作者:501917112_0de975_837 | 来源:互联网 | 2023-07-22 17:48
本文章是用106试用通道用java发送短信的例子,复制代码就可使用,但前提有106试用账号和密码----------------------------------
本文章是用106试用通道用java发送短信 的例子,就可使用,但前提有106试用账号和密码
----------------------------------
package util;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
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 Fixin {
public static void sendMsg(String _phone,String _pwd,String _to,String _msg) throws HttpException, IOException{
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost("106.ihuyi.cn",80,"http");
//post 带参提交数据
PostMethod post = new PostMethod("/webservice/sms.php?method=Submit");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
NameValuePair[] op ={
new NameValuePair("account", _phone),
new NameValuePair("password", _pwd),
new NameValuePair("mobile",_to),
new NameValuePair("content",_msg),
};
post.setRequestBody(op);
client.executeMethod(post);
System.out.println("---------");
// 打印服务器返回的状态
System.out.println(post.getStatusLine());
// 打印返回的信息
System.out.println(post.getResponseBodyAsString());
System.out.println(post.getURI());
System.out.println("---------");
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("utf-8"));
//System.out.println(result);
System.out.println("ok!");
post.releaseConnection();
}
}
-------------------------------------------
package test;
import java.io.IOException;
import org.apache.commons.httpclient.HttpException;
import util.Fixin;
public class Test {
private static String PHOnE= "cf_a6233976**"; // 106账号 http://sms.webchinese.cn/
private static String PWD = "jie52019**";
private static String TO = "183110093**";
private static String MSG = "您的验证码是:888。请不要把验证码泄露给其他人。";
public static void main(String[] args) throws HttpException, IOException {
Fixin.sendMsg(PHONE, PWD, TO, MSG);
}
}