發送TTS語音消息

POST

https://api.laaffic.com/v3/voice/sendCode

通過指定語言和指定語言文本發送TTS語音消息。
 
請求參數
callee
String
必填
被叫號碼,國碼+手機號組成的7-15位數位。
displayNum
String
顯示號碼,7-15位數字,允許為空
language
String
必填
語言代碼:[越南語:VN,英語:EN,日語:JP,阿拉伯文:ARB,德國:DE,印地語:IN,義大利:IT,韓國:KR,俄羅斯:RU,西班牙:ES,葡萄牙:PT,印尼語:IDN,孟加拉:BD,泰語:TH]
text
String
必填
文本內容,需要和語言代碼對應,驗證碼之間以英文逗號隔開
appId
String
必填
語音應用id
loopCount
Int
必填
迴圈播報次數,1-3數字,預設為1,允許為空。
calledInfo
String
被叫資訊,0-1000位字符
 
請求示例
Request URL:
    https://api.laaffic.com/v3/voice/sendCode
Request Method:
    POST
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9
Request Body:
{
    "callee":"932111111111",
    "displayNum":"1008122211",
    "language":"EN",
    "text":"hello world",
    "appId":"4luaKsL2",
    "loopCount":2,
    "calledInfo":"calledInfo"
}
 
響應參數
參數 説明 類型
status 狀態碼,0表示成功,其他均爲失敗,詳見狀態碼説明. String
reason 失敗原因説明 String
data 記錄唯一id String
 
響應狀態碼
狀態碼 説明
0 成功
-1 帳號認證異常
-2 IP訪問受限
-10 客戶餘額不足,不滿足本次發送
-16 超出時間限制
-18 系統異常
-22 參數異常
-26 獲取費用失敗
 

語言

Java

PHP

請求

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;

public void sendCode() {
    final String baseUrl = "https://api.laaffic.com/v3/voice";
    final String apiKey = "your api key";
    final String apiPwd = "your api secret";
    final String appId = "{{appId}}";
    final String callee = "{{callee}}";
    final String displayNum = "{{displayNum}}";
    final String language = "{{language}}";
    final String text = "{{text}}";
    final Integer loopCount = "{{loopCount}}";
    final String calledInfo = "{{calledInfo}}";

    final String url = baseUrl.concat("/sendCode");
    HttpRequest request = HttpRequest.post(url);

    // generate md5 key
    final String datetime = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond());
    final String sign = SecureUtil.md5(apiKey.concat(apiPwd).concat(datetime));

    request.header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")
            .header("Sign", sign)
            .header("Timestamp", datetime)
            .header("Api-Key", apiKey);

    final String body = JSONUtil.createObj()
            .set("callee", callee)
            .set("displayNum", displayNum)
            .set("language", language)
            .set("text", text)
            .set("appId", appId)
            .set("loopCount", loopCount)
            .set("calledInfo", calledInfo)
            .toString();

    HttpResponse response = request.body(body).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/voice/sendCode";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);

$dataArr['callee'] = "{{callee}}";
$dataArr['displayNum'] = "{{displayNum}}";
$dataArr['language'] = "{{language}}";
$dataArr['appId'] = $appId;
$dataArr['text'] = "{{text}}";
$dataArr['loopCount'] = "{{loopCount}}";
$dataArr['calledInfo'] = "{{calledInfo}}";

$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);
$error = curl_error($ch);
curl_close($ch);

var_dump($output);        
                
 

響應示例

{
    "status": "0",
    "reason": "success",
    "data": "2203031113381000002"
}                    
                

點擊此處開啟人工服務