中国网建SMS短信接口调用(java发送短信)
生活随笔
收集整理的這篇文章主要介紹了
中国网建SMS短信接口调用(java发送短信)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
java發送短信
package sms;import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; public class SendMsg_webchinese { public static void main(String[] args)throws Exception{ HttpClient client = new HttpClient(); PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn"); post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在頭文件中設置轉碼 NameValuePair[] data ={ new NameValuePair("Uid", "qxxxx"), new NameValuePair("Key", "dcd082xxxxxd27057"), new NameValuePair("smsMob","186xxxxx20"), new NameValuePair("smsText","這個是內容 ")}; post.setRequestBody(data); client.executeMethod(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(); } } commons-logging-1.1.1.jar
commons-httpclient-3.1.jar
commons-codec-1.4.jar
需要引入上面三個jar包
注冊中國網建賬號 官網地址?http://sms.webchinese.cn/
UID 是注冊的賬號 Key 是短信密鑰(注:不是密碼)在中國網建 上面可以查看到 smsmob 是接收方電話號碼 Smstext 是短信內容?
記得先增加短信簽名? 不然報錯-51
總結
以上是生活随笔為你收集整理的中国网建SMS短信接口调用(java发送短信)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使役动词
- 下一篇: 如何理解海森堡的「不确定性原理」(总结)