通过验证码短信http调用接口,您可以很快速的在网站或者app中集成手机号验证功能,该源码只是核心代码,具体可以根据您的实际需求进行扩展。
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.IOException;
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;
public class sendsms {
private static String Url = "http://106.ihuyi.com/webservice/sms.php?method=Submit";
public static void main(String [] args) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(Url);
//client.getParams().setContentCharset("GBK");
client.getParams().setContentCharset("UTF-8");
method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");
String content = new String("您的验证码是:7528。请不要把验证码泄露给其他人。");
NameValuePair[] data = {//提交短信
new NameValuePair("account", "用户名"),
new NameValuePair("password", "密码"),
new NameValuePair("mobile", "手机号码"),
new NameValuePair("content", content),
};
method.setRequestBody(data);
try {
client.executeMethod(method);
System.out.println(method.getResponseBodyAsString());
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println("短信提交成功");
}
}
==================================================================
互亿无线验证码短信接口下载地址:https://www.ihuyi.com/duanxin.html
如有疑问,请联系我们的技术,或者访问我们的网站了解更多信息:https://www.ihuyi.com/
新用户促销套餐,首购优惠,直接下单购买
验证码已发送到您的手机,请查收!
输入验证码后,点击“开通体验账户”按钮可立即开通体验账户。