<?php require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/Workerman/Autoloader.php'; require_once dirname(dirname(__DIR__)) . '/GatewayClient/Gateway.php'; \Workerman\Autoloader::setRootPath(__DIR__ . '/../../'); use GatewayWorker\Lib\Db; use Workerman\Protocols\Http; if (!isset($_POST['macid']) && !isset($_POST['buttonid'])) { echo "对不起,您访问的页面不存在!"; HTTP::end(); } $macid = $_POST['macid']; $buttonid = $_POST['buttonid']; $connectHC = Db::instance('ConnectHC'); $clientdata = $connectHC->row("SELECT clientid, sign FROM `WEBHC` WHERE macid='{$macid}'"); if (!Gateway::isOnline($clientdata['clientid'])) { echo "102"; HTTP::end(); } if (!$clientdata['sign']) { echo "103"; HTTP::end(); } Gateway::sendToClient($clientdata['clientid'], "{" . $buttonid . "}"); echo "101"; HTTP::end(); ?>
/** * 接收事件消息 * @var object * @return string */ private function receiveEvent($object) { $result = ""; $client_openid = $object->FromUserName; switch ($object->Event) { //关注事件 case "subscribe": $content = "感谢关注广州汇承信息科技微信服务号! [太阳]\n\n"; $content .= "点击菜单:'HC汇承'\n"; $content .= "得到最新产品咨询、HC产品列表汇总、HC汇承官网信息\n"; $content .= "--------------------------\n"; $content .= "点击菜单:'人工咨询'\n"; $content .= "在线技术支持、在线销售咨询\n"; $content .= "--------------------------\n"; $content .= "点击菜单:'HC智能❤'\n"; $content .= "暂时没有开放..\n\n"; $content .= "电话:020-4008881803"; $result = $this->transmitText($object, $content); break; //取消关注事件 //取消关注事件 case "unsubscribe": $content = "取消关注"; break; /*case "SCAN": $content = "扫描场景 ".$object->EventKey; break;*/ //点击事件 /*case "SCAN": $content = "扫描场景 ".$object->EventKey; break;*/ //点击事件 case "CLICK": switch ($object->EventKey) { //最新产品 case "NewProduct": $content = array(); $content[] = array("Title" => "HC-08蓝牙4.0BLE串口模块", "Description" => "HC-08支持和iPhone4s以上的苹果手机或安卓4.3蓝牙4.0的安卓手。。,两模块之前也可通讯", "PicUrl" => "https://mmbiz.qlogo.cn/mmbiz/JnIZvkFV6c0gu2PEYJkcP3ngibwfIufAIPcjwpx1W2brgWTfibVe2dhFqKcQEntc6wXVZm8P6LaQ6qic9UOFibyFaA/0?wx_fmt=jpeg", "Url" => "http://www.hchchchc.com/Tpl/product_arc.php?model=HC-08"); $result = $this->transmitNews($object, $content); break; // 在线销售 // 在线销售 case "OnlineSaler": $getcustom_mark = redisData::hGet($client_openid, 'custom'); // 重复click if ($getcustom_mark == "1") { echo ""; HTTP::end(); } else { // 得到空闲客服帐号 $kf_account = transToWxServer::findRelaxCustom("HCS"); if (!empty($kf_account)) { $result = $this->transmitService($object, $kf_account); redisData::hSet($client_openid, 'custom', "1"); } else { // 客服不在线 $content = "客服已离线,请稍候重试!"; $result = $this->transmitText($object, $content); } } break; // 在线技术客服 // 在线技术客服 case "THelp": $getcustom_mark = redisData::hGet($client_openid, 'custom'); // 重复click if ($getcustom_mark == "1") { echo ""; HTTP::end(); } else { // 得到空闲客服帐号 $kf_account = transToWxServer::findRelaxCustom("HCT"); if (!empty($kf_account)) { $result = $this->transmitService($object, $kf_account); redisData::hSet($client_openid, 'custom', "1"); } else { // 客服不在线 $content = "客服已离线,请稍候重试!"; $result = $this->transmitText($object, $content); } } break; //汇承官网 //汇承官网 case "IndexHC": break; //智能控制 //智能控制 case "IntelligentControl": // $getintell_mark = redisData::hGet($client_openid,'intell'); // if($getintell_mark == "0") // { // redisData::hSet($client_openid,'intell',"1"); // $content = "成功进入智能控制!\n\n"; // $content.="发送数字'0'可退出智能模式"; // $result = $this->transmitText($object, $content); // }else{ // $content = "智能控制中...!"; // $result = $this->transmitText($object, $content); // } break; //用户主动退出多客服会话 //用户主动退出多客服会话 case "Exit": $getcustom_mark = redisData::hGet($client_openid, 'custom'); if ($getcustom_mark == "1") { $content = "提示: 用户主动结束会话!"; $kf_account = transToWxServer::findUserSession($object); transToWxServer::closeSalerSession($object, $kf_account, $content); // Gateway::sendToAll($error); redisData::hSet($client_openid, 'custom', "0"); } else { echo ""; HTTP::end(); } break; } break; case "VIEW": $openid = $object->FromUserName; $_SESSION['username'] = $openid; break; //多客服主动关闭会话事件 //多客服主动关闭会话事件 case "kf_close_session": $content = "感谢您的咨询,我们下次再见!"; transToWxServer::transToWxClientMsg($object, $content); redisData::hSet($object->FromUserName, 'custom', "0"); // return $result; // $content = "关闭了会话"; // $result = $this->transmitText($object, $content); break; //多客服转接会话事件 //多客服转接会话事件 case "kf_switch_session": $service_id = $object->ToKfAccount; //得到客服的昵称 $service_name = redisData::Get($service_id); $content = "已转接到 客服: {$service_name}"; transToWxServer::transToWxClientMsg($object, $content); break; } return $result; }