基于創藍253短信服務平臺的java調用短信接口api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package com.bcloud.msg.http; import java.io.bytearrayoutputstream; import java.io.inputstream; import java.net.urldecoder; import org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.httpstatus; import org.apache.commons.httpclient.namevaluepair; import org.apache.commons.httpclient.uri; import org.apache.commons.httpclient.methods.getmethod; /** * * @param url 應用地址,類似于http://ip:port/msg/ * @param account 賬號 * @param pswd 密碼 * @param mobile 手機號碼,多個號碼使用","分割 * @param msg 短信內容 * @param needstatus 是否需要狀態報告,需要true,不需要false * @return 返回值定義參見http協議文檔 * @throws exception */ public static string batchsend(string url, string account, string pswd, string mobile, string msg, boolean needstatus, string extno) throws exception { httpclient client = new httpclient(); getmethod method = new getmethod(); try { uri base = new uri(url, false ); method.seturi( new uri(base, "httpbatchsendsm" , false )); method.setquerystring( new namevaluepair[] { new namevaluepair( "account" , account), new namevaluepair( "pswd" , pswd), new namevaluepair( "mobile" , mobile), new namevaluepair( "needstatus" , string.valueof(needstatus)), new namevaluepair( "msg" , msg), new namevaluepair( "extno" , extno), }); int result = client.executemethod(method); if (result == httpstatus.sc_ok) { inputstream in = method.getresponsebodyasstream(); bytearrayoutputstream baos = new bytearrayoutputstream(); byte [] buffer = new byte [ 1024 ]; int len = 0 ; while ((len = in.read(buffer)) != - 1 ) { baos.write(buffer, 0 , len); } return urldecoder.decode(baos.tostring(), "utf-8" ); } else { throw new exception( "http error status: " + method.getstatuscode() + ":" + method.getstatustext()); } } finally { method.releaseconnection(); } } } |
總結
以上所述是小編給大家介紹的java調取創藍253短信驗證碼的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:https://www.cnblogs.com/chuanglan253/archive/2018/04/03/8706305.html