public function test() { $this->checkCompany('To', 'test'); $wechatMsg = array('FromUserName' => 'ooKmYt8VGB2V3l3ZXolpFbTukE58', 'ToUserName' => 'To', 'MsgType' => 'event', 'Event' => 'SCAN', 'EventKey' => 'SCENE_17'); // $wechatMsg = array( // 'FromUserName' => 'ogETojuLhjNU5ds2EOB3vGCqhwh0', // 'ToUserName' => 'To', // 'MsgType' => 'event', // 'Content' => '13199046020170742476', // 'Event' => 'scancode_waitmsg', // 'ScanResult' => 'SZ12365_MENUCLICK_1398826195'); // $keywordResponse = new \Weixin\Event\EventResponse( $this->companyInfo, $wechatMsg); $eventResponse = new \Weixin\Event\EventResponse($this->companyInfo, $wechatMsg); $response = $eventResponse->getResponse(); dump($response); }
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); }