发送自定义消息

POST
https://api.itniotech.com/wa/custom/sendMsg
自定义消息发送限制为收到用户消息的24小时内可以发送此类消息,只有被接收者主动回复后才可发送自定义消息。
请求参数
参数 说明 是否必填 类型
appId 应用Id String
businessPhone 商家号码 String
channelType 通道类型:0-WhatsApp,默认送0; Integer
recipient 接收号码 String
type 消息类型:text、image、audio、video、location、document、sticker;文件大小限制(text:4096字符、audio:16MB、document:100MB、image:5MB、video:16MB、sticker:100KB);具体类型传参数请看下面文档说明。 String
text 发送文本消息时必填 Object
body 正文,发送文本消息时必填 String
image 发送图片消息时必填 Object
link 图片链接,发送图片消息时必填 String
audio 发送音频消息时必填 Object
link 语音链接,发送音频消息时必填 String
video 发送视频消息时必填 Object
link 视频链接,发送视频消息时必填 String
sticker 发送贴图消息时必填 Object
link 贴图链接,发送贴图消息时必填 String
document 发送文档消息时必填 Object
link 文档链接,发送文档消息时必填 String
filename 文档名称,发送文档消息时必填 String
location 发送位置消息时必填 Object
longitude 经度,发送位置消息时必填 String
latitude 纬度,发送位置消息时必填 String
name 位置名称,发送位置消息时必填 String
address 地址描述,发送位置消息时必填 String
请求示例
Request URL:
    https://api.itniotech.com/wa/custom/sendMsg
Request Method:
    POST
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9

//发送文本消息示例
Request Body:
{
    "appId": "DGziZf5u",
    "businessPhone": "91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "text",
    "text": {
        "body": "this is body content"
    }
}
//发送图片消息示例
{
    "appId": "DGziZf5u",
    "businessPhone": "91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "image",
    "image": {
        "link": "https://abc.com/log.png"
    }
}
//发送文档消息示例
{
    "appId": "DGziZf5u",
    "businessPhone": "91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "document",
    "document": {
        "link": "https://abc.com/log.png",
        "filename": "123"
    }
}
//发送音频消息示例
{
    "appId": "DGziZf5u",
    "businessPhone": "91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "audio",
    "audio": {
        "link": "https://abc.com/log.png"
    }
}
//发送视频消息示例
{
    "appId": "DGziZf5u",
    "businessPhone": "91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "video",
    "audio": {
        "link": "https://abc.com/log.png"
    }
}
//发送贴图消息示例
{
    "appId": "DGziZf5u",
    "businessPhone":"91856321412",
    "recipient": "91856321321",
    "channelType": 0,
    "type": "sticker",
    "sticker":{
        "link":"https://abc.com/log.webp"
    }
}
//发送位置消息示例
{
    "channelType": 0,
    "type": "location",
    "appId": "xJdRmKR3",
    "recipient": "91856321321",
    "location": {
        "address": "深圳市龙岗区xx园区",
        "latitude": "62.636152267456",
        "link": "https://123",
        "name": "深圳",
        "longitude": "104.056640625"
    },
    "businessPhone": "91856321412"
}
响应参数
参数 说明 类型
status 状态码,0成功,其他失败参见响应状态码说明 String
reason 成功或失败描述 String
data 结果 Object
messageId 消息id String
imestamp 时间戳(秒级) Long
channelType 通道类型:0-WhatsApp,默认0; String
响应状态码
status 状态说明
-68 余额不足
-69 费率不存在
-70 接收人号码长度不能大于14位
-71 接收人号码长度不能小于7位
-72 接收人号码格式错误,它必须为数字
-93 商家号码长度不能大于14位
-94 商家号码长度不能小于7位
-95 商家号码必须为纯数字
-96 商家号码不存在
-97 商家号码状态错误
-112 channelType在参数中只能为0
-114 文本消息text不能为空
-115 文本消息的body不能为空
-116 图片消息image不能为空
-117 图片消息的link不能为空
-118 音频消息audio不能为空
-119 音频消息的link不能为空
-120 视频消息video不能为空
-121 视频消息的link不能为空
-122 贴图消息sticker不能为空
-123 贴图消息的link不能为空
-124 文档消息document不能为空
-125 文档消息的link不能为空
-127 位置消息location不能为空
-128 位置消息的longitude不能为空
-129 位置消息的latitude不能为空
-132 未知消息类型
-133 link链接地址格式错误
-134 parameter参数类型错误
-135 parameter的变量值不能为空

意见反馈

文档内容是否对您有帮助?

LANGUAGE

Java

PHP

REQUEST

package com.itniotech.api.demo.im;

import cn.hutool.core.map.MapUtil;
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.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

private static void sendCustomMsg() {
    final String baseUrl = "https://api.itniotech.com/wa/";
    final String apiKey = "your api key";
    final String apiPwd = "your api secret";
    final String appId = "your appid";

    final String url = baseUrl.concat("custom/sendMsg");

    HttpRequest request = HttpRequest.post(url);

    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.CONNECTION, "Keep-Alive")
            .header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")
            .header("Sign", sign)
            .header("Timestamp", datetime)
            .header("Api-Key", apiKey);


    final int channelType = 0;
    final String businessPhone = "business phone"; //the business phone
    final String recipient = "accept phone"; //accept phone
    final String type = "text";

    Map buildMap = MapUtil.builder("body", "this is body content").build();

    String body = JSONUtil.createObj()
            .set("appId", appId)
            .set("businessPhone", businessPhone)
            .set("channelType", channelType)
            .set("recipient", recipient)
            .set("type", type)
            .set("text", buildMap)
            .toString();

    HttpResponse response = request.body(body).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";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);
$headers = array('Content-Type:application/json;charset=UTF-8',"Sign:$sign","Timestamp:$timeStamp","Api-Key:$apiKey");

$url = "https://api.itniotech.com/im/template/sendMsg";

$dataArr["appId"] = $appId;
$dataArr["businessPhone"] = "business phone";
$dataArr["recipient"] = "accept phone";
$dataArr["channelType"] = 0;
$dataArr["type"] = "text";
$dataArr["text"] = array(
    "body" => "this is body content"
);

$data = json_encode($dataArr);

$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",
	"data": {
        "channelType": 0,
		"messageId": "10415ecbd0c848ebb7d5a3fe53269df6",
		"timestamp": 1693813991
	}
}