Beispiel #1
0
 public function run()
 {
     $resource = $this->getResource();
     $openId = $resource['FromUserName'];
     Vera_Log::addNotice('content', $resource['Content']);
     $avatar = Data_Wechat_User::getAvatar($openId);
     if ($resource['Content'] != '') {
         //此处添加发弹幕逻辑
         $data = 'w=' . $resource['Content'] . '&a=' . $avatar;
         $url = 'http://127.0.0.1:3000/message';
         $handle = curl_init();
         $options = array(CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_TIMEOUT => 1);
         curl_setopt_array($handle, $options);
         $content = curl_exec($handle);
         $text = '快抬头看大屏幕~!';
         if (curl_errno($handle)) {
             //检查是否有误
             $text = '啊哦..服务器好像生病了...';
         }
         curl_close($handle);
     } else {
         $text = '呃..你是不是发了表情?暂时不支持哟~';
     }
     $ret['type'] = 'text';
     $ret['data']['Content'] = $text;
     //寻找模板
     $view = new View_Wechat($resource);
     $view->assign($ret);
     $view->display();
     return true;
     // --------------end--------------
     $conf = Vera_Conf::getAppConf('common');
     $reply = Data_Wechat_Db::keywordReply($resource['Content']);
     if (!$reply) {
         //默认回复
         $ret = $conf['defaultReply'];
     } elseif (in_array($reply['replyType'], $conf['replyType'])) {
         //固定回复
         $ret['type'] = $reply['replyType'];
         $ret['data'] = json_decode($reply['reply'], true);
     } else {
         //功能性回复
         $class = 'Service_' . $reply['replyType'];
         $instance = new $class($resource);
         $ret = $instance->{$reply['reply']}();
     }
     if (empty($ret)) {
         throw new Exception("很抱歉公众号出现异常", 1);
     }
     //寻找模板
     $view = new View_Wechat($resource);
     $view->assign($ret);
     $view->display();
     return true;
 }
Beispiel #2
0
 private function _click()
 {
     $resource = $this->getResource();
     Vera_Log::addNotice('eventKey', $resource['EventKey']);
     $conf = Vera_Conf::getAppConf('common');
     $result = Data_Wechat_Db::eventReply($resource['EventKey']);
     if (!$result) {
         //出错回复
         $ret = $conf['errMsg'];
     } elseif (in_array($result['replyType'], $conf['replyType'])) {
         //固定回复
         $ret['type'] = $result['replyType'];
         $ret['data'] = json_decode($result['reply'], true);
     } else {
         //功能性回复
         $class = 'Service_' . $result['replyType'];
         $instance = new $class($resource);
         $ret = $instance->{$result['reply']}();
     }
     return $ret;
 }