# 客服消息事件
本文档描述服务器端接收的消息或事件,详细说明参见消息推送。
事件英文名:commkf_send_msg_to_kf
当微信客户、接待人员发消息或有行为动作时,商家客服后台会将事件的回调数据包发送到指定URL。
相关 API 接口:
相关开发指南:
# 1. 消息参数
# 请求体 Request Payload
| 参数名 | 类型 | 说明 |
|---|---|---|
| ToUserName | string | 小店UserName |
| FromUserName | string | 小店用户的OpenID |
| CreateTime | number | 事件时间,Unix时间戳,即格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数 |
| MsgType | string | 消息类型,固定为 event |
| Event | string | 事件类型,本接口固定为 commkf_send_msg_to_kf |
| msg_id | string | 用户发送该条消息的所捆绑的单调自增msg_id |
| msg_type | object | 消息类型, 参考发送消息中的消息类型 |
| msg_event | object | 事件类型 |
| text | object | 当msg_type为text时,则会返回text对应消息结构体 |
| video | object | 当msg_type为video时,则会返回video对应消息结构体 |
| image | object | 当msg_type为image时,则会返回image对应消息结构体 |
| file | object | 当msg_type为file时,则会返回file对应消息结构体 |
| product_share | object | 当msg_type为product_share时,则会返回product_share对应消息结构体 |
| order_share | object | 当msg_type为order_share时,则会返回order_share对应消息结构体 |
| voice | object | 当msg_type为voice时,则会返回voice对应消息结构体 |
# Body.msg_type Object Payload
消息类型, 参考发送消息中的消息类型
| 参数名 | 类型 | 说明 |
|---|---|---|
| text | object | msg_type为text |
| video | object | msg_type为video |
| image | object | msg_type为image |
| file | object | msg_type为file |
| product_share | object | msg_type为product_share |
| order_share | object | msg_type为order_share |
| voice | object | msg_type为voice |
# Body.msg_event Object Payload
事件类型
| 参数名 | 类型 | 说明 |
|---|---|---|
| EVENT_TYPE_SEND_MSG | object | 用户发送消息时的回调行为 |
# Body.text Object Payload
当msg_type为text时,则会返回text对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| content | string | 测试消息123 | msg_type为text时,必返回的回报消息 |
# Body.video Object Payload
当msg_type为video时,则会返回video对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| play_length | uint32 | 24 | msg_type为video时,表示返回视频秒数 |
| cos_url | string | https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxxxxx&msg_type=7 | msg_type为video时,表示返回视频的可下载cos_url |
| ld_img_url | string | https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxxxxx&msg_type=2 | msg_type为video时,表示返回视频的封面图 |
# Body.image Object Payload
当msg_type为image时,则会返回image对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| cos_url | string | https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxxxxx&msg_type=2 | msg_type为image时,表示返回图片的可下载cos_url |
# Body.file Object Payload
当msg_type为file时,则会返回file对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| cos_url | string | https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxxxxx&msg_type=8 | msg_type为file时,表示返回文件的可下载cos_url |
# Body.product_share Object Payload
当msg_type为product_share时,则会返回product_share对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| product_id | string | 1000018045xxxxx | msg_type为product_share时,表示当前用户发送的卡片商品Id |
# Body.order_share Object Payload
当msg_type为order_share时,则会返回order_share对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| order_id | string | 37265222601xxxxxxxxx | msg_type为order_share时,表示当前用户发送的卡片订单Id |
# Body.voice Object Payload
当msg_type为voice时,则会返回voice对应消息结构体
| 参数名 | 类型 | 示例 | 说明 |
|---|---|---|---|
| translated_msg | string | 您好,问一下这个商品如何下单 | msg_type为voice时,表示当前用户发送语音翻译成功后的文本 |
| play_length | number | 2287 | msg_type为voice时,表示当前用户发送语音的语音长度,单位为毫秒(ms) |
| translation_succ | bool | true | msg_type为voice时,表示当前用户发送语音文本是否翻译成功 |
# 2. 消息返回
# 返回体 Response Payload
回复 success 或空字符串(无需加密)
# 3. 注意事项
- 回调url设置和消息推送规则需参考消息推送文档 ,如果设置的回调url无法访问,商户将无法收微信小店发送的通知;
- 如果已切换API模式,但是没有设置指定URL,事件消息则会丢弃。设置指定URL后,需确保接收消息的服务器是可接收数据的。
- 如果服务器回包数据不符合预期,商家客服后台则会进行消息的重试推送,总重试约3.5小时,共会进行10次消息重试推送。
# 4. 代码示例
本事件无代码示例
2025 年 10 月 31 日
优化格式