java calls SMS interface to send SMS

Keywords: Java Apache Eclipse Mobile

java calls SMS interface to send SMS

1. Download interface file

Port: https://pan.baidu.com/s/1h1ZGQeA2BUX_WwIkvC4vgA
Extraction Code: 2ev3

2. Open the java folder

Download Complete Open Folder Select java

2.1 Getting jar package dependencies

Then open lib (copy out the required jar package dependencies)



2.2 Getting Code Templates

Open the src file directory and set theSendsms.javaAnd inside the util folder StringUtil.java One copy



3. Create a project

3.1 Open eclipse software to create a dynamic web project



Check Profile



3.2 Import jar package dependencies

3.3 Tool classes required to create package imports

Import two tool classes first. I don't have any subcontracted storage here. I'm doing a test, writing in subcontracted layers (for reference only)

4. Create an account

I'm using the interface of a billion wireless platforms here
Platform address: https://www.ihuyi.com/
Log in once you've created your account

4.1 Account Status

5. Get the required account password and enter the tool class assignment

Class name: sendsms

6. Testing

6.1 Test Results

eclipse console output

Mobile Receive Results



7. Code display

7.1 Class name: sendsms

package com.tanle;

import java.io.IOException;

import javax.swing.JOptionPane;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class sendsms {

	private static String Url = "http://106.ihuyi.com/webservice/sms.php?method=Submit";

	public static int code(String st) {

		HttpClient client = new HttpClient();
		PostMethod method = new PostMethod(Url);

		client.getParams().setContentCharset("GBK");
		method.setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=GBK");

		int mobile_code = (int) ((Math.random() * 9 + 1) * 100000);

		String content = new String("Your verification code is:" + mobile_code + ". Please do not leak the verification code to others.");

		NameValuePair[] data = { // Submit SMS
				new NameValuePair("account", "Fill in the previous picture here APIID"), // View User Name Login User Center->Authentication Code Notification SMS>Product Overview->API Interface Information->APIID
				new NameValuePair("password", "Fill in the previous picture here APIKEY"), // View Password
																					// Log in to User Center->Authentication Code Notification SMS>Product Overview->API Interface Information->APIKEY
				// New NameValuePair ("password"),Utl.StringUtil.MD5Encode(Password)),
				new NameValuePair("mobile", st), new NameValuePair("content", content), };
		method.setRequestBody(data);

		try {
			client.executeMethod(method);

			String SubmitResult = method.getResponseBodyAsString();
			// System.out.println(SubmitResult);
			Document doc = DocumentHelper.parseText(SubmitResult);
			Element root = doc.getRootElement();

			String code = root.elementText("code");
			String msg = root.elementText("msg");
			String smsid = root.elementText("smsid");

			System.out.println(code);
			System.out.println(msg);
			System.out.println(smsid);
			System.out.println(content);
//
//			if ("2".equals(code)) {
//				JOptionPane.showMessageDialog(null,'SMS Submitted Successfully');
//			}

		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mobile_code;
	}

}

Class name 7.2: StringUtil

//Interface type: Mutual billions of wireless triggered SMS interface, supporting sending verification code SMS, order notification SMS, etc.
// Account registration: please open an account at this addressHttp://sms.ihuyi.com/register.html
// Matters needing attention:
//(1) During debugging, test with the default template, which is detailed in the interface documentation;
//(2) Call the interface using APIID (see APIID please log in to User Center->Authentication Code SMS->Product Overview->APIID) and APIkey;
//(3) The code is only for the reference of access to the mutual billion wireless SMS interfaces, and customers can write their own according to their actual needs;

package com.tanle;

import java.security.MessageDigest;

public class StringUtil {
	public static String str;
	public static final String EMPTY_STRING = "";

	private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };

	private static String byteToHexString(byte b) {
		int n = b;
		if (n < 0)
			n = 256 + n;
		int d1 = n / 16;
		int d2 = n % 16;
		return hexDigits[d1] + hexDigits[d2];
	}

	/**
	 * Convert byte array to 16-bit string
	 * @param b Byte Array
	 * @return 16 Binary string
	 */
	public static String byteArrayToHexString(byte[] b) {
		StringBuffer resultSb = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			resultSb.append(byteToHexString(b[i]));
		}
		return resultSb.toString();
	}

	public static String MD5Encode(String origin) {
		String resultString = null;
		try {
			resultString = new String(origin);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byteArrayToHexString(md.digest(resultString
					.getBytes()));
		} catch (Exception ex) {
		}
		return resultString;
	}

}

7.3 Test Class

package com.tanle;

public class test {
	public static void main(String[] args) {
		int code = sendsms.code("Fill in the recipient's computer number here");
		System.out.println("Send Successfully:"+code);
	}
}

8. Summary

  1. Here I just call the interface test, written in the main method, which can be added to the project by instance.
  2. Thank you for watching and welcome to point out the shortcomings!

Posted by brickstermike on Wed, 24 Jun 2020 18:59:47 -0700