微信公众号开发教程[019]-新版客服

       新版客服是针对之前文章<<微信公众号开发教程[007]-消息管理-客服消息>>里面提到的客服功能而言的.在其基础上做了很多提升.

        首先如果公众号曾经使用过旧版多客服功能,则要在"功能->多客服"中,点击"升级"进行升级.

 

        客服人员可以通过手机微信扫码登录网页版客服系统: https://mpkf.weixin.qq.com.客服人员登录后,就可以使用网页版客服系统,接收用户发送给公众号的消息,并对其进行回复了:

 

        待接入列表中的信息,可以手动接入,也可以在设置中开启自动接入:

 

以下文字转自微信官方文档:

        如果公众号处于开发模式,普通微信用户向公众号发消息时,微信服务器会先将消息POST到开发者填写的url上,如果希望将消息转发到客服系统,则需要开发者在响应包中返回MsgType为transfer_customer_service的消息,微信服务器收到响应后会把当次发送的消息转发至客服系统。您也可以在返回transfer_customer_service消息时,在XML中附上TransInfo信息指定分配给某个客服帐号。
        用户被客服接入以后,客服关闭会话以前,处于会话过程中时,用户发送的消息均会被直接转发至客服系统。当会话超过30分钟客服没有关闭时,微信服务器会自动停止转发至客服,而将消息恢复发送至开发者填写的url上。
        用户在等待队列中时,用户发送的消息仍然会被推送至开发者填写的url上。

 

要回复的xml如下:

 

<xml>
     <ToUserName><![CDATA[oIaodvwZe03Amjb8_jQ0ZHGmr-4w]]></ToUserName>
     <FromUserName><![CDATA[gh_733c42e0aee9]]></FromUserName>
     <CreateTime>1399197672</CreateTime>
     <MsgType><![CDATA[transfer_customer_service]]></MsgType>
     <TransInfo>
         <KfAccount><![CDATA[test1@test]]></KfAccount>
     </TransInfo>
 </xml>

 

 

下面,代码实现新版客服功能,如果与旧版相同的api则略过.

 

function getonlinekflist() { //获取在线客服基本信息
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=$ACCESS_TOKEN";
	$result = curl_http_get($url);
	echo $result;
}

function inviteworker() { //邀请绑定客服帐号
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfaccount/inviteworker?access_token=$ACCESS_TOKEN";
	$data = '{"kf_account": "test1@test", "invite_wx": "test_kfwx"}';
	$result = curl_http_post($url, $data);
	echo $result;
}

function session_create() { //创建会话
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfsession/create?access_token=$ACCESS_TOKEN";
	$data = '{"kf_account" : "test1@test","openid" : "oe5SXv71irmrQ0TH-JxA-z_hmYLE"}';
	$result = curl_http_post($url, $data);
	echo $result;
}

function session_close() { //关闭会话
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfsession/close?access_token=$ACCESS_TOKEN";
	$data = '{"kf_account" : "test1@test", "openid" : "oe5SXv71irmrQ0TH-JxA-z_hmYLE"}';
	$result = curl_http_post($url, $data);
	echo $result;
}

function getsession() { //获取客户会话状态
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=$ACCESS_TOKEN&openid=oe5SXv71irmrQ0TH-JxA-z_hmYLE";
	$result = curl_http_get($url);
	echo $result;
}

function getsessionlist() { //获取客服会话列表
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=$ACCESS_TOKEN&kf_account=test1@test";
	$result = curl_http_get($url);
	echo $result;
}

function getwaitcase() { //获取未接入会话列表
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=$ACCESS_TOKEN";
	$result = curl_http_get($url);
	echo $result;
}

function getmsglist() { //获取聊天记录
	$ACCESS_TOKEN = "OcjHFml-rn4TxxuuKhTtzHRFWYGlE3_VJK-b58ZZ8jnjYBvS1IxEgSmg4C7hrirkl5n7yf-798q2mPbRybKw5-59OhgfvJYM5wSGsItLJ-DWlN68JaOd_pidaChZ-6ReVGGgADANYY";
	$url = "https://api.weixin.qq.com/customservice/msgrecord/getmsglist?access_token=$ACCESS_TOKEN";
	$data = '{"starttime" : 987654321, "endtime" : 987654321, "msgid" : 1, "number" : 10000}';
	$result = curl_http_post($url, $data);
	echo $result;
}

 

 

 

 

借鉴了网上的资料: 搜狐公众平台->微信公众平台推出新版客服功能:http://mt.sohu.com/20160321/n441422036.shtml

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值