发送自定义消息

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、interactive、contacts;
文件大小限制( text:4096字符、audio:16MB、document:100MB、image:5MB、video:16MB、sticker: 100KB);
具体类型传参数请看下面文档说明:
String
 
发送文本消息的请求参数(type=text):
参数 说明 是否必填 类型
text 发送文本消息时必填 Object
body 正文,发送文本消息时必填 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": "91856321321",
  "recipient": "91856321322",
  "channelType": 0,
  "type": "text",
  "text": {
    "body": "this is body content"
  }
}
 
发送引用消息的请求参数(type=context):
参数 说明 是否必填 类型
context 上下文对象 Object
refMessageId 回复上行消息id 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": "17376111187",
    "recipient": "8618099900000",
    "channelType": 0,
    "type": "text",
    "text": {
        "body": "this is body content"
    },
    "context": { //上下文
        "refMessageId": "1"  //消息id
    }
}
 
发送图片消息的请求参数(type=image):
参数 说明 是否必填 类型
image 发送图片消息时必填 Object
link 图片链接,发送图片消息时必填 String
caption 标题 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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "type": "image",
    "image": {
        "link": "https://abc.com/log.png",
        "caption": "title"
    }
}
 
发送文档消息的请求参数(type=document):
参数 说明 是否必填 类型
document 发送文档消息时必填 Object
link 文档链接,发送文档消息时必填 String
filename 文档名称,发送文档消息时必填 String
caption 标题 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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "type": "document",
    "document": {
        "link": "https://abc.com/log.png",
        "filename": "123",
        "caption": "title"
    }
}
 
发送音频消息的请求参数(type=audio):
参数 说明 是否必填 类型
audio 发送音频消息时必填 Object
link 语音链接,发送音频消息时必填 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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "type": "audio",
    "audio": {
        "link": "https://abc.com/log.png"
    }
}
 
发送视频消息的请求参数(type=video):
参数 说明 是否必填 类型
video 发送视频消息时必填 Object
link 视频链接,发送视频消息时必填 String
caption 标题 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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "type": "video",
    "video": {
        "link": "https://abc.com/log.png",
        "caption": "title"
    }
}
 
发送贴图消息的请求参数(type=sticker):
参数 说明 是否必填 类型
sticker 发送贴图消息时必填 Object
link 贴图链接,发送贴图消息时必填 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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "type": "sticker",
    "sticker":{
        "link":"https://abc.com/log.webp"
    }
}
 
发送位置消息的请求参数(type=location):
参数 说明 是否必填 类型
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": "91856321321",
    "recipient": "91856321322",
    "channelType": 0,
    "location": {
        "address": "深圳市龙岗区",
        "latitude": "62.636152267456",
        "link": "https://123",
        "name": "深圳",
        "longitude": "104.056640625"
    }
}
 
发送交互式消息的请求参数(type=interactive):
参数 说明 是否必填 类型
interactive 交互式消息   Object
type 交互式消息类型,list String
header 列表消息的页眉  
type 页眉的类型,interactive String
text 内容 String
body 列表消息的正文  
text 正文内容 String
footer 列表消息的页脚  
text 页脚的内容 String
action      
button 用户在阅读消息后执行的操作 String
sections 节数组。最少1个,最多10个。 Array
title 节数组的标题,24个字符。 String
rows 行数组。您总共可以有10行。 Array
id 行的编号,200个字符 String
title 行的标题,24个字符 String
description 行的描述,72个字符 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": "7WY0BQ7W",
    "businessPhone": 6282299953162,
    "channelType": 0,
    "recipient": "8614718004557",
    "type": "interactive",
    "interactive": {
        "type": "list",
        "header": {
            "type": "text",
            "text": "HEADER_TEXT"
        },
        "body": {
            "text": "BODY_TEXT"
        },
        "footer": {
            "text": "FOOTER_TEXT"
        },
        "action": {
            "button": "BUTTON_TEXT",
            "sections": [
                {
                    "title": "SECTION_1_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_1_ROW_1_ID",
                            "title": "SECTION_1_ROW_1_TITLE",
                            "description": "SECTION_1_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_1_ROW_2_ID",
                            "title": "SECTION_1_ROW_2_TITLE",
                            "description": "SECTION_1_ROW_2_DESCRIPTION"
                        }
                    ]
                },
                {
                    "title": "SECTION_2_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_2_ROW_1_ID",
                            "title": "SECTION_2_ROW_1_TITLE",
                            "description": "SECTION_2_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_2_ROW_2_ID",
                            "title": "SECTION_2_ROW_2_TITLE",
                            "description": "SECTION_2_ROW_2_DESCRIPTION"
                        }
                    ]
                }
            ]
        }
    }
}
 
交互式-快捷回复消息(type=interactive):
参数 说明 是否必填 类型
interactive 交互式消息   Object
type 交互式消息类型,button String
header 列表消息的页眉  
type 页眉的类型,interactive String
text 内容 String
body 列表消息的正文  
text 正文内容 String
footer 列表消息的页脚  
text 页脚的内容 String
action      
buttons    
type 回复按钮支持的类型:reply。最多支持三个按钮 String
reply   Object
id 按钮的唯一标识符。当用户单击按钮时,将在 Webhook 中返回此ID。最大长度:256个字符 String
title 按钮标题。它不能是空字符串,并且在消息中必须是唯一的(需测试)。20个字符 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": "7WY0BQ7W",
    "businessPhone": 6282299953162,
    "channelType": 0,
    "recipient": "8614718004557",
    "type": "interactive",
    "interactive": {
        "type": "button",
        "body": {
            "text": "BUTTON_TEXT"
        },
        "action": {
            "buttons": [
            {
                "type": "reply",
                "reply": {
                    "id": "22",
                    "title": "one"
                }
            },
            {
                "type": "reply",
                "reply": {
                    "id": "33",
                    "title": "two"
                }
            }]
        }
    }
}
 
交互式-请求地理位置消息(type=interactive):
参数 说明 是否必填 类型
interactive 交互式消息   Object
type location_request_message String
body 正文  
text 正文内容 String
action      
name send_location(固定值)  
请求示例
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": "zRTc00Vs",
    "businessPhone": 6282292229952762,
    "channelType": 0,
    "recipient": "86173333376738687",
    "type": "interactive",
    "interactive": { // the text object
        "type": "location_request_message",
        "body":{
            "text":"广东省深圳市龙岗区"
        },
        "action":{
            "name":"send_location"
        }
    }
}
 
发送联系人消息的请求参数(type=contacts):
参数 说明 是否必填 类型
contacts 联系人消息   Object
birthday 生日,YYYY-MM-DD格式 String
addresses 地址对象 Array
street 街道名称 String
city 城市名称 String
state String
zip 邮政编码 String
country 完整的国家名称 String
country_code 国家缩写 String
type 地址类型:HOME(家庭)、WORK(工作) String
emails 地址对象 Array
email 电子邮件地址 String
type 类型:HOME(家庭)、WORK(工作) String
name   Object
formatted_name 全名 String
first_name 名字 String
last_name 姓氏 String
middle_name 中间名 String
suffix 名称后缀 String
prefix 名称前缀 String
org   Object
company 公司名称 String
department 部门名称 String
title 职务 String
phones   Array
phone 手机号 String
type 类型:CELL、MAIN、IPHONE、HOME、WORK String
urls   Array
url 网址 String
type 类型:HOME、WORK 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": "7WY0BQ7W",
    "businessPhone": 6282299953162,
    "channelType": 0,
    "recipient": "8614718004557",
    "type": "contacts",
    "contacts": [
        {
            "addresses": [
                {
                    "street": "STREET",
                    "city": "CITY",
                    "state": "STATE",
                    "zip": "ZIP",
                    "country": "COUNTRY",
                    "country_code": "COUNTRY_CODE",
                    "type": "HOME"
                },
                {
                    "street": "STREET",
                    "city": "CITY",
                    "state": "STATE",
                    "zip": "ZIP",
                    "country": "COUNTRY",
                    "country_code": "COUNTRY_CODE",
                    "type": "WORK"
                }
            ],
            "birthday": "1995-01-11",
            "emails": [
                {
                    "email": "EMAIL",
                    "type": "WORK"
                },
                {
                    "email": "EMAIL",
                    "type": "HOME"
                }
            ],
            "name": {
                "formatted_name": "NAME",
                "first_name": "FIRST_NAME",
                "last_name": "LAST_NAME",
                "middle_name": "MIDDLE_NAME",
                "suffix": "SUFFIX",
                "prefix": "PREFIX"
            },
            "org": {
                "company": "COMPANY",
                "department": "DEPARTMENT",
                "title": "TITLE"
            },
            "phones": [
                {
                    "phone": "PHONE_NUMBER",
                    "type": "HOME"
                },
                {
                    "phone": "PHONE_NUMBER",
                    "type": "WORK",
                    "wa_id": "PHONE_OR_WA_ID"
                }
            ],
            "urls": [
                {
                    "url": "URL",
                    "type": "WORK"
                },
                {
                    "url": "URL",
                    "type": "HOME"
                }
            ]
        }
    ]
}
 
响应参数
参数 说明 类型
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/wa/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
	}
}