發送短訊

POST

https://api.laaffic.com/v3/sendSms

提交短訊接口,支持單個號碼或多個號碼發送。支持GET或POST,GET方式一次最多提交100個號碼,POST方式一次最多提交1000個號碼。
 
請求參數
appId
String
必填
應用ID
numbers
String
必填
短訊接收號碼,多個號碼之間以英文逗號分隔(get最多100個,post最多1000個)
content
String
必填
發送内容,長度不能超過1024字符,get請求内容需要urlEncode
senderId
String
發送號碼
orderId
String
自定义消息id,orderId數量和手機號碼數量需保持一致
 
請求示例
//使用GET請求發送內容:"hello world":
Request URL:
    https://api.laaffic.com/v3/sendSms?appId=4luaKsL2&numbers=91856321412,91856321413&content=hello%20world&senderId=123&orderId=21412,21413
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.laaffic.com/v3/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",
    "orderId":"21412,21413"
}
 
響應參數
參數 説明 類型
status 狀態碼,0表示成功,其他參見狀態碼説明 String
reason 失敗原因説明 String
成功 提交成功的號碼個數 String
fail 提交失敗的號碼個數 String
array 提交成功的json集合 JSONArray
msgId 提交號碼對應平臺msgld String
number 響應狀態碼 String
orderid 自定义消息id String
 
響應狀態碼
狀態碼 説明
0 成功
-1 認證錯誤
-2 IP訪問受限
-3 短訊内容含有敏感字符
-4 短訊内容爲空
-5 短訊内容過長
-6 不是模板的短訊
-7 號碼個數過多
-8 號碼爲空
-9 號碼異常
-10 客戶餘額不足,不滿足本次發送
-13 用戶被鎖
-16 超出時間限制
-18 接口異常
-19 請聯係業務經理綁定通道
 

語言

Java

PHP

Python

請求


                    package com.laaffic.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.laaffic.com/v3";
    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 orderId = "{{orderId}}";
    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)
            .set("orderId", orderId)
            .toString();
    HttpResponse response = request.body(params).execute();
    if (response.isOk()) {
        String result = response.body();
        System.out.println(result);
    }
}        
                

請求

header('content-type:text/html;charset=utf8');

$apiKey = "your api key";
$apiSecret = "your api secret";
$appId = "{{appId}}";
$url = "https://api.laaffic.com/v3/sendSms";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);

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

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

請求

import hashlib
import time
import requests
import json

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

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, "orderId": orderId}
print(body)

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

響應示例


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

點擊此處開啟人工服務