一、下载源码
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包的版本为准,如需要其他版本请自主下载。
二、使用帮助
2.1 DEMO结构

- 说明:
- 1、ApiDemo4HttpClient.java:江苏美圣短信接口
-
2、开发环境引用第三方jar方式
maven方式:复制以下配置片段放在pom.xml中dependencies节点内
org.apache.httpcomponents httpclient 4.3.5
2.2 初始参数
//账号 static String account = "JSM*****"; //密码 static String password = "********"; //通讯Key/校验码 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; }
如果账号开了免审,或者是做模板短信,将会按照规则正常发送,而不会进人工审核平台,返回值是:
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 获得状态报告
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; }
只能查询当天的,已获取的状态报告后续不会再获取,返回值是:
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; }
只能查询当天的,已获取的上行短信后续不会再获取,返回值:
159******** 106905994540001 谢谢 159******** 106905994540001 江苏美圣信息技术有限公司
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