1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 微信公众号开发(七)发送客服消息

微信公众号开发(七)发送客服消息

时间:2020-06-14 16:33:27

相关推荐

微信公众号开发(七)发送客服消息

微信公众号开发(七)发送客服消息

当用户和公众号产生特定动作的交互时(具体动作列表请见下方说明),微信将会把消息数据推送给开发者,开发者可以在一段时间内(目前修改为48小时)调用客服接口,通过POST一个JSON数据包来发送消息给普通用户。此接口主要用于客服等有人工消息处理环节的功能,方便开发者为用户提供更加优质的服务。

允许的动作如下:

用户发送信息点击自定义菜单(仅有点击推事件、扫码推事件、扫码推事件且弹出“消息接收中”提示框这3种菜单类型是会触发客服接口的)关注公众号扫描二维码支付成功用户维权

现在客服接口可以使用永久media_id了。

1、发送客服消息

发送接口:https://api./cgi-bin/message/custom/send?access_token=ACCESS_TOKEN

发送文本

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"text","text":{"content":"客服消息"}}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

返回结果如下:

{"errcode":0,"errmsg":"ok"}

发送图片

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"image","image":{"media_id":"FrsRJ3g3BHR-pIkuFLARnHjI9Cq9lDFas4Kp8otlAUQ"}}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

返回结果:

{"errcode":0,"errmsg":"ok"}

发送语音和这类似,不过结构为:

{"touser":"OPENID","msgtype":"voice","voice":{"media_id":"MEDIA_ID"}}

发送音乐

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"music","music":{"title":"泡沫","description":"邓紫棋","musicurl":"/music/missyou.mp3","hqmusicurl":"/music/missyou.mp3","thumb_media_id":"FrsRJ3g3BHR-pIkuFLARnLApulXtdIVuSDOZVUMF4I8" }}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

注:发送视频和发送音乐都没有显示thumb_media_id设置的缩略图,有知道的小伙伴麻烦留下言。

发送视频

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"video","video":{"media_id":"FrsRJ3g3BHR-pIkuFLARnBcTeZTOOEh5acdetFMw1Xw","thumb_media_id":"bnahO7BqolsaJgQI_TsailL3OkztloUhG-xYealG2phqBpgid8kWcncVm_3ks8oT","title":"客服视频","description":"一个自拍小饰品"}}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

发送图文消息(点击跳转到外链) 图文消息条数限制在8条以内

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"news","news":{"articles": [{"title":"第一项","description":"第一项描述","url":"","picurl":"/images/img1.jpg"},{"title":"第二项","description":"第二项描述","url":"","picurl":"/images/img2.jpg"}]}}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

发送图文消息(点击跳转到图文消息页面) 图文消息条数限制在8条以内

这里的图文就是指我们上传的永久图文消息,点击之后图文消息页面。

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c","msgtype":"mpnews","mpnews":{"media_id":"FrsRJ3g3BHR-pIkuFLARnAwGsFjf8Rckbd63rFBsE4o"}}';$url = "https://api./cgi-bin/message/custom/send?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

2、客服输入状态

有以下限制:

如果不满足发送客服消息的触发条件,则无法下发输入状态。下发输入状态,需要客服之前30秒内跟用户有过消息交互。在输入状态中(持续15s),不可重复下发输入态。在输入状态中,如果向用户下发消息,会同时取消输入状态。

<?php@header('Content-type: text/plain;charset=UTF-8');require_once("Utils.php");$data = '{ "touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c", "command":"Typing"}';$url = "https://api./cgi-bin/message/custom/typing?"."access_token=".Utils::get_access_token();$result = Utils::https_request($url, $data);echo $result;

相关博客

微信公众号开发(一)服务器及接口的配置

微信公众号开发(二)基础接口

微信公众号开发(三)获取access_token

微信公众号开发(四)自定义菜单

微信公众号开发(五)个性化菜单

微信公众号开发(六)素材管理

微信公众号开发(七)发送客服消息

微信公众号开发(八)用户管理

微信公众号开发(九)群发消息接口

微信公众号开发(十)模板消息

微信公众号开发(十一)生成带参数二维码

微信公众号开发(十二)OAuth2.0网页授权

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。