通过验证码短信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/
互亿无线营销短信平台支持签名认证
为短信加上您的公司品牌名称和LOGO
150,000家
企业客户
20年
行业经验
2V1
2对1客户支持