参数 | 说明 | 是否必填 | 类型 |
---|---|---|---|
appId | 应用id(短信-短信应用) | 是 | String |
array | 消息内容json集合 | 是 | JSONArray |
numbers | 短信接收号码,多个号码之间以英文逗号分隔 | 是 | String |
content | 发送内容,长度不能超过1024字符 | 是 | String |
senderId | 发送号码,最大长度是32个字符 | 否 | String |
orderId | 自定义消息id,orderId 数量和手机号码数量需保持一致 | 否 | String |
Request URL:
https://api.itniotech.com/sms/sendSms/batch
Request Method:
POST
Request Headers:
Content-Type: application/json;charset=UTF-8
Sign: 05d7a50893e22a5c4bb3216ae3396c7c
Timestamp: 1630468800
Api-Key: bDqJFiq9
Request Body:
{
"appId": "4luaKsL2",
"array": [
{
"numbers": "91856321412,91856321413",
"content": "test message",
"senderId": "",
"orderId": "56584,56585"
},
{
"numbers": "91856321414",
"content": "test message1",
"senderId": "",
"orderId": "56586"
}
]
}
参数 | 说明 | 类型 |
---|---|---|
status | 状态码,0成功,其他失败参见响应状态码说明 | String |
reason | 失败原因说明 | String |
success | 提交成功的号码个数 | String |
fail | 提交失败的号码个数 | String |
array | 提交成功的json集合 | JSONArray |
msgId | 提交号码对应平台msgId | String |
number | 提交号码 | String |
orderId | 自定义消息id | String |
注:提交发送短信成功后,系统会给每个提交成功的号码对应生成一个平台msgId,后续客户可以根据这个msgId来查询该号码的发送结果。
status | 状态说明 |
---|---|
0 | 成功 |
-1 | 认证错误 |
-2 | Ip访问受限 |
-3 | 短信内容含有敏感字符 |
-4 | 短信内容为空 |
-5 | 短信内容过长 |
-6 | 不是模板的短信 |
-7 | 号码个数过多 |
-8 | 号码为空 |
-9 | 号码异常 |
-10 | 客户余额不足,不能满足本次发送 |
-16 | 超出时间范围限制 |
-18 | 端口程序异常 |
-19 | 请联系业务经理绑定通道 |
Java
PHP
REQUEST
package com.itniotech.api.demo.sms;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
private void batchSendSms() {
final String baseUrl = "https://api.itniotech.com/sms";
final String apiKey = "your api key";
final String apiPwd = "your api secret";
final String appId = "your appid";
Map map=new HashMap<>();
map.put("numbers","91856321412,91856321413");
map.put("content","hello world");
map.put("orderId","56584,56585");
final String url = baseUrl.concat("/sendSms/batch");
HttpRequest request = HttpRequest.post(url);
// currentTime
final String datetime = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond());
// generate md5 key
final String sign = SecureUtil.md5(apiKey.concat(apiPwd).concat(datetime));
request.header(Header.CONNECTION, "Keep-Alive")
.header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")
.header("Sign", sign)
.header("Timestamp", datetime)
.header("Api-Key", apiKey);
final String params = JSONUtil.createObj()
.set("appId", appId)
.set("array", Arrays.asList(map))
.toString();
HttpResponse response = request.body(params).execute();
if (response.isOk()) {
String result = response.body();
System.out.println(result);
}
}
REQUEST
header('content-type:text/html;charset=utf8');
$apiKey = "your api key";
$apiSecret = "your api secret";
$appId = "your appid";
$url = "https://api.itniotech.com/sms/sendSms/batch";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);
$dataArr['appId'] = $appId;
$dataArr['array'] = array(
array(
'numbers' => '91856321412,91856321413',
'content' => 'hello world',
'orderId' => '56584,56585',
)
);
$data = json_encode($dataArr);
$headers = array('Content-Type:application/json;charset=UTF-8',"Sign:$sign","Timestamp:$timeStamp","Api-Key:$apiKey");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POSTFIELDS , $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);
RESPONSEEXAMPLE
{
"status": "0",
"reason": "success",
"success": "2",
"fail": "0",
"array": [
{
"msgId": "2207201629421000001",
"number": "91856321412",
"orderId": "56584"
},
{
"msgId": "2207201629421000002",
"number": "91856321413",
"orderId": "56585"
}
]
}