发送短信

GET
POST
https://api.itniotech.com/sms/sendSms
提交短信接口,支持单个号码或多个号码发送。支持GET或POST,GET方式一次最多提交100个号码,POST方式一次最多提交1000个号码。
 
请求参数
appId
String
必填
应用id
numbers
String
必填
短信接收号码,多个号码之间以英文逗号分隔(get最多100个,post最多1000个)
content
String
必填
发送内容,长度不能超过1024字符,get请求内容需要urlEncode
senderId
String
发送号码
 
请求示例
GET请求示例发送 “hello world”内容:
Request URL:
    https://api.itniotech.com/sms/sendSms?appId=4luaKsL2&numbers=91856321412,91856321413&content=hello%20world&senderId=123
Request Method:
    GET
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9

POST请求示例发送 “hello world” 内容:
Request URL:
    https://api.itniotech.com/sms/sendSms
Request Method:
    POST
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9
Request Body:
{
    "appId":"4luaKsL2",
    "numbers":"91856321412,91856321413",
    "content":"hello world",
    "senderId":"123"
}
 
响应参数
参数 说明 类型
status 状态码,0成功,其他失败参见接口响应状态码 String
reason 失败原因说明 String
success 提交成功的号码个数 String
fail 提交失败的号码个数 String
array 提交成功的json集合 JSONArray
msgId 提交号码对应平台msgId String
number 提交号码 String
orderId 自定义消息id String
 
响应状态码
status 状态说明
0 成功
-1 认证错误
-2 Ip访问受限
-3 短信内容含有敏感字符
-4 短信内容为空
-5 短信内容过长
-6 不是模板的短信
-7 号码个数过多
-8 号码为空
-9 号码异常
-10 客户余额不足,不能满足本次发送
-13 用户被锁定
-16 超出时间范围限制
-18 端口程序异常
-19 请联系业务经理绑定通道
 

LANGUAGE

Java

PHP

Curl

Python

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 sendSms() {
    final String baseUrl = "https://api.itniotech.com/sms";
    final String apiKey = "your api key";
    final String apiPwd = "your api secret";
    final String appId = "{{appId}}";
    final String numbers = "{{numbers}}";
    final String content = "{{content}}";
    final String senderId = "{{senderId}}";
    final String url = baseUrl.concat("/sendSms");
    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("numbers", numbers)
            .set("content", content)
            .set("senderId", senderId)
            .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 = "{{appId}}";
$url = "https://api.itniotech.com/sms/sendSms";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);

$dataArr['appId'] = $appId;
$dataArr['numbers'] = '{{numbers}}';
$dataArr['content'] = '{{content}}';
$dataArr['senderId'] = '{{senderId';

$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);

REQUEST

curl -X POST 'https://api.itniotech.com/sendSms'
-H 'Timestamp: {datetime}'
-H 'Api-Key: {apiKey}'
-H 'Sign: {sign}'
-H 'Content-Type: application/json;charset=UTF-8'
-d '{"appId":"{{appId}}","numbers":"{{numbers}}","content":"{{content}}","senderId":"{{senderId}}"}'

REQUEST

import hashlib
import time
import requests
import json

base_url = "https://api.itniotech.com/sms/"
api_key = "your api key"
api_pwd = "your api secret"
appid = "{{appId}}"
numbers = "{{numbers}}"
content = "{{content}}"
senderId = "{{senderId}}"

def create_headers():
  timestamp = int(time.time())
  s = "%s%s%s" % (api_key, api_pwd, str(timestamp))
  sign = hashlib.md5(s.encode(encoding='UTF-8')).hexdigest()
  headers = {
    'Content-Type': 'application/json;charset=utf-8',
    'Sign': sign,
    'Timestamp': str(timestamp),
    'Api-Key': api_key
  }
  return headers

headers = create_headers()

url = "%s/sendSms" % base_url
print(url)

#post method
body = {"appId": appid, "numbers": numbers, "content": content, "senderId": senderId}
print(body)

rsp = requests.post(url, json=body, headers=headers)
if rsp.status_code == 200:
    res = json.loads(rsp.text)
  print(res)
 

RESPONSEEXAMPLE

{
    "status": "0",
    "reason": "success",
    "success": "2",
    "fail": "0",
    "array":[
        {
            "msgId": "2108021054011000095",
            "number": "91856321412"
        },
        {
            "msgId": "2108021059531000096",
            "number": "91856321413"
        }
    ]
}