思路
1.点击应用的菜单-在线客服-触发事件
$result1 = $this->receiveEvent($postObj);
2.分配客服 - 使用缓存memcache进行存储分配客服的信息(项目部署在sae,所以在sae上面开启memcache即可)
$mmc = memcache_init(); //初始化缓存
memcache_set($mmc, "service", '{"from":"'.$from.'","to":"'.$to.'"}'); //分配的信息
3.发送信息接入客服和用户
$this->send_custom_msg($from, "text", "正在为您接入客服,请稍候..");
4.断开连接,结束在线客服模式
memcache_delete($mmc, "service");
单客服
该多客服功能参考修改了单客服功能,全面代码请参考
微信企业号客服功能开发PHP.
下文中的代码则是更改了的部分代码
多客服
客服用户对话连接
private function receiveEvent($object)
{
$content = "";
switch($object->Event){
case "click":
switch($object->EventKey)
{
case "qt_kf":
$mmc = memcache_init();
//客服单击,结束对话
if( in_array($object->FromUserName, Constant::$Staff4)){
//只有客服点击,才可结束会话
$staff = Constant::$Staff4; //客服名单
$countt = sizeof($staff); //客服总数量
$i = 1;
$ii = 0;
while($countt >= $i){
$service = memcache_get($mmc,"service".$i);
$relation = json_decode($service, true);
$ii = $i;
if($service && in_array(strval($object->FromUserName), array( $relation['to']))