版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41413619/article/details/86072403
网址:http://sms.webchinese.cn/default.shtml
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.api.smschinese.cn");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
NameValuePair[] data ={ new NameValuePair("Uid", "用户名"),
new NameValuePair("Key", "短信密钥"),
new NameValuePair("smsMob","发送的手机号"),
new NameValuePair("smsText","短信内容")};
post.setRequestBody(data);//把要执行的数据添加到post中
client.executeMethod(post);//执行post
Header[] headers = post.getResponseHeaders();//获取消息头
int statusCode = post.getStatusCode();
System.out.println("statusCode:"+statusCode);//获取执行状态码
for(Header h : headers)
{
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("gbk"));
System.out.println(result); //打印返回消息状态
post.releaseConnection();//释放连接
}
多个手机号请用半角,隔开
如:13888888886,13888888887,1388888888
温馨提示:
发送测试短信请勿输入:短信测试等词语,请直接提交您要发送的短信内容;
接口发送短信时请在内容后加签名:【XX公司或XX网名称】,否者会被屏蔽。
短信签名可在用户平台平台上设置,也可以在短信内容后,直接加入。
记得添加短信签名。亲测有效,代码考走修改成自己的信息就能发送短信和验证码,就是这么简单,哈哈 撤了~