Messenger API Documentation
发送消息接口
发送消息
通过API发起Messenger消息发送服务
- URL:
https://api.nxcloud.com/v1/messenger/mt
- Method:
POST
- Content-Type:
application/json
- 需要鉴权:
是
鉴权机制
鉴权规则请参考地址:API接口调用约定
请求参数
参数名 |
类型 |
必填 |
描述 |
pageId |
String |
是 |
公共主页id |
recipientId |
String |
是 |
接收方id |
functionType |
String |
是 |
消息类型 |
messageData |
Object |
是 |
消息体参数 |
appkey |
String |
是 |
应用唯一标识 |
functionType 消息类型说明
类型 |
描述 |
必填参数 |
text |
文本 |
messageData{rateType=Message,text不能为空} |
image |
图片 |
messageData{rateType=Message,image不能为空} |
audio |
音频 |
messageData{rateType=Message,url不能为空} |
video |
视频 |
messageData{rateType=Message,url不能为空} |
template |
普通模板 |
messageData{rateType=Message,title不能为空} |
button_template |
按钮模板 |
messageData{rateType=Message,text/elements不能为空} |
messageData 消息体参数说明
参数名 |
类型 |
必填 |
描述 |
rateType |
String |
是 |
计费类型(Message) |
text |
String |
否 |
文本内容 |
url |
String |
否 |
地址(根据functionType确定是图片/音频/视频地址) |
type |
String |
否 |
类型(当functionType为template特有,generic/button) |
elements |
Array |
否 |
元素数组 |
rateType 计费类型说明
elements 元素参数说明
参数名 |
类型 |
必填 |
描述 |
title |
String |
否 |
标题(type=generic时必填) |
subtile |
String |
否 |
子标题 |
imageUrl |
String |
否 |
图片地址 |
buttons |
Array |
是 |
按钮数组(type=button时必填) |
buttons 按钮参数说明
参数名 |
类型 |
必填 |
描述 |
type |
String |
是 |
类型(web_url/postback) |
url |
String |
是 |
跳转地址 |
title |
String |
是 |
button名称 |
请求示例
发送文本消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "text",
"messageData": {
"text": "Hello World!",
"rateType": "Promotional"
}
}
发送图片消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "image",
"messageData": {
"url": "your_url",
"rateType": "Message"
}
}
发送音频消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "audio",
"messageData": {
"url": "your_audio_url",
"rateType": "Message"
}
}
发送视频消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "video",
"messageData": {
"url": "your_video_url",
"rateType": "Message"
}
}
发送普通模板消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "template",
"messageData": {
"elements": [
{
"title": "Welcome!",
"image_url": "https://example.com/image.jpg",
"subtitle": "We have the right hat for everyone.",
"action": {
"type": "web_url",
"url": "https://www.example.com"
},
"buttons": [
{
"type": "web_url",
"url": "https://www.example.com",
"title": "View Website"
}
]
}
],
"type": "generic",
"rateType": "Message"
}
}
发送按钮模板消息
{
"appkey": "your_app_key",
"pageId": "your_page_id",
"recipientId": "recipient_id",
"functionType": "button_template",
"messageData": {
"text": "button template",
"elements": [
{
"buttons": [
{
"type": "web_url",
"url": "https://www.example.com",
"title": "访问网站"
},
{
"type": "postback",
"payload": "POSTBACK_PAYLOAD",
"title": "回调按钮"
}
]
}
],
"type": "button",
"rateType": "Message"
}
}
响应参数
参数名 |
类型 |
描述 |
code |
Integer |
响应码 |
message |
String |
响应描述 |
data |
Object |
响应数据 |
traceId |
Object |
链路追踪id |
响应示例
{
"code": 0,
"message": "Success",
"data": {
"requestId": "metamid.xxxx"
},
"traceId": "xxxx"
}
错误码说明