Example #1
0
 public function index()
 {
     $weObj = new Wechat($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->log($this->companyInfo['ecid']);
     $this->log($this->wechatMsg['FromUserName']);
     //添加用户
     $this->saveUserInfo($this->companyInfo['ecid'], $this->wechatMsg['FromUserName']);
     //处理收到的信息
     switch ($this->wechatMsg['MsgType']) {
         case Wechat::MSGTYPE_TEXT:
             //收到文本信息
             $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg);
             $response = $keywordResponse->getResponse();
             break;
         case Wechat::MSGTYPE_EVENT:
             //收到事件信息
             $eventResponse = new \Weixin\Event\EventResponse($this->companyInfo, $this->wechatMsg);
             $response = $eventResponse->getResponse();
             break;
         case Wechat::MSGTYPE_LOCATION:
             //收到地理信息
             $locationResponse = new \Weixin\Location\LocationResponse($this->companyInfo, $this->wechatMsg);
             $response = $locationResponse->getResponse();
             break;
         case Wechat::MSGTYPE_IMAGE:
             //回复图片信息
             break;
         case Wechat::MSGTYPE_VOICE:
             //处理语音信息
             if (assert($this->wechatMsg['Recognition'])) {
                 $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg);
                 $response = $keywordResponse->getResponse();
             }
             break;
         default:
             break;
     }
     //$this->log(json_encode($response));
     // 响应回复
     switch ($response['type']) {
         case Wechat::MSGTYPE_TEXT:
             $weObj->text($response["content"])->reply();
             break;
         case Wechat::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);
 }
Example #2
0
 public function test()
 {
     $this->checkCompany('To', 'test');
     $wechatMsg = array('FromUserName' => 'ogETojuLhjNU5ds2EOB3vGCqhwh0', 'ToUserName' => 'To', 'MsgType' => 'text', 'Content' => 'shopTest');
     $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $wechatMsg);
     $response = $keywordResponse->getResponse();
     dump($response);
 }