# 国际短信发送接口
# 接口地址
http://intlapi.1cloudsp.com/intl/api/v2/send
用户通过HTTP(或HTTPS)的POST或GET方式提交短信发送请求。编码采用 UTF-8
编码。
# 请求参数
参数名 | 是否必填 | 类型 | 示例 | 描述 |
---|---|---|---|---|
accesskey | 是 | String | xxxxxxxxxx | 秘钥key |
secret | 是 | String | yyyyyyyyyy | 秘钥secret |
mobile | 否 | String | 13900000000,13900000001 | 接收短信的手机号码,多个号码以半角逗号 , 隔开注:最大支持5万 |
content | 否 | String | 先生##9:40##快递公司##1234567 (示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4}) | 发送的短信内容是模板变量内容,多个变量中间用 ## 或者 $$ 隔开,采用utf8编码 |
data | 否 | JSON | {"13700000001":"女士##10:10##物流公司##000000","13700000000":"先生##9:40##快递公司##1234567"} | 该字段用于发送个性短信,mobile和content字段不需要填写,该字段json字符串,json的key是手机号,value是短信内容变量,等同于上面的content 包含多个变量中间用 ## 或者 $$ 隔开,采用utf8编码最大支持1万 |
scheduleSendTime | 否 | String | 2018-01-01 18:00:00 | 短信定时发送时间,格式为:2018-01-01 18:00:00;参数如果为空表示立即发送 |
senderId | 否 | String | xxxxxx | 该字段用于短信下发标识发件人信息 |
# 返回参数
参数名 | 类型 | 说明 | 描述 |
---|---|---|---|
code | String | 请求状态数 | 0表示请求成功,非0表示请求失败;详细参考 错误码列表 |
msg | String | 状态说明 | |
batchId | String | 批次id |
# 请求示例
/* ---示例代码 POST方式----*/
package apiserver;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import com.alibaba.fastjson.JSONObject;
public class ApiTest {
//普通短信
private void sendsms() throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("http://intlapi.1cloudsp.com/intl/api/v2/send");
postMethod.getParams().setContentCharset("UTF-8");
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());
String accesskey = "xxxxxxxxxx"; //用户开发key
String accessSecret = "yyyyyyyyyy"; //用户开发秘钥
NameValuePair[] data = {
new NameValuePair("accesskey", accesskey),
new NameValuePair("secret", accessSecret),
new NameValuePair("mobile", "8613900000001,8613900000002"),
new NameValuePair("content", URLEncoder.encode("先生##9:40##快递公司##1234567", "utf-8"))//(示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4})
};
postMethod.setRequestBody(data);
postMethod.setRequestHeader("Connection", "close");
int statusCode = httpClient.executeMethod(postMethod);
System.out.println("statusCode: " + statusCode + ", body: "
+ postMethod.getResponseBodyAsString());
}
//个性短信
private void sendsms2() throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("http://intlapi.1cloudsp.com/intl/api/v2/send");
postMethod.getParams().setContentCharset("UTF-8");
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());
String accesskey = "xxxxxxxxxx"; //用户开发key
String accessSecret = "yyyyyyyyyy"; //用户开发秘钥
//组装个性短信内容
JSONObject jsonObj = new JSONObject();
jsonObj.put("8613700000000","先生##9:40##快递公司##1234567");
jsonObj.put("8613700000001","女士##10:10##物流公司##000000");//(示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4})
NameValuePair[] data = {
new NameValuePair("accesskey", accesskey),
new NameValuePair("secret", accessSecret),
new NameValuePair("sign", "123"),
new NameValuePair("templateId", "100"),
new NameValuePair("data", URLEncoder.encode(jsonObj.toString(), "utf-8"))
};
postMethod.setRequestBody(data);
postMethod.setRequestHeader("Connection", "close");
int statusCode = httpClient.executeMethod(postMethod);
System.out.println("statusCode: " + statusCode + ", body: "
+ postMethod.getResponseBodyAsString());
}
public static void main(String[] args) throws Exception {
ApiTest t = new ApiTest();
//普通短信
//t.sendsms();
//个性短信
t.sendsms2();
}
}
/* ---示例代码 POST方式----*/
# 返回示例
{
"code": "0",
"msg": "SUCCESS",
"batchId": ""
}