java發送短信開發,第三方接口方法


必備的三個jar包Maven有自己去下:

commons-logging commons-logging 1.1

commons-httpclient commons-httpclient 3.1

commons-codec commons-codec 1.4

第三方參數及其接口

 

java示例代碼:

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","驗證碼:8888")};
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();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM