一、下載源碼
JAVA DEMO下載備注: httpclient 方式引用1、httpclient.jar,2、httpcore.jar,3、commons-logging.jar,4、commons-codec.jar; jodd方式引用1、jodd-core.jar,2、jodd-http.jar,3、jodd-upload.jar。 具體版本號以下載示例源碼包中jar包的版本為準(zhǔn),如需要其他版本請自主下載。
二、使用幫助
2.1 DEMO結(jié)構(gòu)
- 說明:
- 1、ApiDemo4HttpClient.java:江蘇美圣短信接口
-
2、開發(fā)環(huán)境引用第三方j(luò)ar方式
maven方式:復(fù)制以下配置片段放在pom.xml中dependencies節(jié)點(diǎn)內(nèi)
org.apache.httpcomponents httpclient 4.3.5
2.2 初始參數(shù)
//賬號 static String account = "JSM*****"; //密碼 static String password = "********"; //通訊Key/校驗(yàn)碼 static String veryCode = "************";
2.3 接口使用
2.3.1 普通短信
public static String sendSms(String mobile,String content){ String sendSmsUrl = http_url + "/service/httpService/httpInterface.do?method=sendUtf8Msg"; Map<String,String> params = new HashMap<String,String>(); params.put("username", account); params.put("password", password); params.put("veryCode", veryCode); params.put("mobile", mobile); params.put("content", content); params.put("msgtype", "1"); params.put("code", "utf-8"); String result = sendHttpPost(sendSmsUrl, params); return result; }
如果賬號開了免審,或者是做模板短信,將會按照規(guī)則正常發(fā)送,而不會進(jìn)人工審核平臺,返回值是:
0 48783a095b7e4c11a9f1a86b5f9b0357,bb3a1075aca34f588defde55d0b3d57c
2.3.2 模板短信
public static String sendTplSms(String mobile,String tplId,String content){ String sendTplSmsUrl = http_url + "/service/httpService/httpInterface.do?method=sendUtf8Msg"; Map<String,String> params = new HashMap<String,String>(); params.put("username", account); params.put("password", password); params.put("veryCode", veryCode); params.put("mobile", mobile); params.put("content", content); //變量值,以英文逗號隔開 params.put("msgtype", "2"); //2-模板短信 params.put("tempid", tplId); //模板編號 params.put("code", "utf-8"); String result = sendHttpPost(sendTplSmsUrl, params); return result; }
0 743ed1cf5c1a48059e46b5bddced4f4a
2.3.3 獲得狀態(tài)報(bào)告
public static String queryReport(){ String reportUrl = http_url + "/service/httpService/httpInterface.do?method=queryReport"; Map<String,String> params = new HashMap<String,String>(); params.put("username", account); params.put("password", password); params.put("veryCode", veryCode); String result = sendHttpPost(reportUrl, params); return result; }
只能查詢當(dāng)天的,已獲取的狀態(tài)報(bào)告后續(xù)不會再獲取,返回值是:
159******** c9d6cdca60734906b35f846a1feb0622 DELIVRD 159******** 74b8a704de1f498a8762dc66e02fd660 DELIVRD
2.3.4 獲得上行短信
public static String queryMo(){ String moUrl = http_url + "/service/httpService/httpInterface.do?method=queryMo"; Map<String,String> params = new HashMap<String,String>(); params.put("username", account); params.put("password", password); params.put("veryCode", veryCode); String result = sendHttpPost(moUrl, params); return result; }
只能查詢當(dāng)天的,已獲取的上行短信后續(xù)不會再獲取,返回值:
159******** 106905994540001 謝謝 159******** 106905994540001 江蘇美圣信息技術(shù)有限公司
2.3.5 獲得余額
public static String getBalance(){ String balanceUrl = http_url + "/service/httpService/httpInterface.do?method=getAmount"; Map<String,String> params = new HashMap<String,String>(); params.put("username",account); params.put("password",password); params.put("veryCode",veryCode); String result = sendHttpPost(balanceUrl, params); return result; }返回值是:
0 0