public function index() { $weObj = new TPWechat($this->getOption()); //验证合法性 $weObj->valid(); //获取微信参数 $this->wechatMsg = $weObj->getRev()->getRevData(); //回复内容 $response = ''; // //检查是否具有调用权限 $code = $this->checkCompany($weObj->getRevTo(), $weObj->getRevContent()); if ($code != Error::SUCCESS_OK) { echo Error::getErrMsg($code); return; } //添加用户 $this->saveUserInfo($this->companyInfo['ecid'], $this->wechatMsg['FromUserName']); //处理收到的信息 switch ($this->wechatMsg['MsgType']) { case TPWechat::MSGTYPE_TEXT: //收到文本信息 $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg); $response = $keywordResponse->getResponse(); break; case TPWechat::MSGTYPE_EVENT: //收到事件信息 $eventResponse = new \Weixin\Event\EventResponse($this->companyInfo, $this->wechatMsg); $response = $eventResponse->getResponse(); break; case TPWechat::MSGTYPE_LOCATION: //收到地理信息 $locationResponse = new \Weixin\Location\LocationResponse($this->companyInfo, $this->wechatMsg); $response = $locationResponse->getResponse(); break; case TPWechat::MSGTYPE_IMAGE: //回复图片信息 break; case TPWechat::MSGTYPE_VOICE: //处理语音信息 if (assert($this->wechatMsg['Recognition'])) { $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg); $response = $keywordResponse->getResponse(); } break; default: break; } // 响应回复 switch ($response['type']) { case TPWechat::MSGTYPE_TEXT: $weObj->text($response["content"])->reply(); break; case TPWechat::MSGTYPE_NEWS: $weObj->news($response['content'])->reply(); default: $weObj->transfer_customer_service()->reply(); break; } if ($response['ext'] != null) { $this->sendCustomMessage($response['ext'], $this->wechatMsg['FromUserName']); } // 记录日志 $wechatMsg['Content'] = htmlspecialchars_decode($wechatMsg['Content']); //过滤html和实体 $wechatMsg['Content'] = strip_tags($wechatMsg['Content']); \Weixin\Log\ResponseLog::wxReceiveLog($this->companyInfo['ecid'], $this->wechatMsg); }