예제 #1
0
 public function run()
 {
     $resource = $this->getResource();
     Vera_Log::addNotice('event', $resource['Event']);
     switch ($resource['Event']) {
         case 'CLICK':
             $ret = $this->_click();
             break;
         case 'scancode_waitmsg':
             // 扫码推事件且弹出“消息接收中”提示框的事件推送
             $ret = $this->_scancode();
             break;
         case 'subscribe':
             $ret = $this->_subscribe();
             break;
         case 'unsubscribe':
             break;
         default:
             $conf = Vera_Conf::getAppConf('common');
             $ret = $conf['defaultReply'];
             break;
     }
     if (empty($ret)) {
         throw new Exception("很抱歉公众号出现异常", 1);
     }
     //寻找模板
     $view = new View_Wechat($resource);
     $view->assign($ret);
     $view->display();
     return true;
 }
예제 #2
0
 public function run()
 {
     $resource = $this->getResource();
     $fileApi = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s';
     $mediaId = $resource['MediaId'];
     // header('http://hackathon.lishengcn.cn/wap/api/image?media_id=' . $resource['MediaId'] . '&openid=' . $resource['FromUserName']);
     $wechatConf = Vera_Conf::getConf('global')['testWechat'];
     $accessToken = Data_Base::getAccessToken($wechatConf['AppID'], $wechatConf['AppSecret']);
     $picUrl = urlencode(sprintf($fileApi, $accessToken, $mediaId));
     $avatar = Data_Wechat_User::getAvatar($resource['FromUserName']);
     //此处添加发弹幕逻辑
     $data = 'p=' . $picUrl . '&a=' . $avatar;
     $url = 'http://127.0.0.1:3000/image';
     $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);
     $ret['type'] = 'text';
     $ret['data']['Content'] = '图片已发送';
     //寻找模板
     $view = new View_Wechat($resource);
     $view->assign($ret);
     $view->display();
 }
예제 #3
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;
 }