Exemplo n.º 1
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();
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public function checkin($act, $token)
 {
     $openId = self::$resource['FromUserName'];
     $nickname = Data_Wechat_User::getNick($openId);
     $avatar = Data_Wechat_User::getAvatar($openId);
     Vera_Autoload::changeApp('rollcall');
     $service = new Service_Func();
     $checkin = $service->checkin($act, $token, $openId, $nickname);
     Vera_Autoload::reverseApp();
     if ($checkin['errno']) {
         $ret['type'] = 'text';
         $ret['data']['Content'] = $checkin['errmsg'];
         return $ret;
     }
     $data = array('a' => $avatar, 'n' => $nickname);
     $ret['type'] = 'news';
     $temp['Articles'][0]['Title'] = "您是第{$checkin['rank']}位在【{$checkin['actInfo']['name']}】签到";
     $temp['Articles'][0]['Description'] = "点击大图参与大屏幕弹幕互动。";
     $temp['Articles'][0]['PicUrl'] = 'http://www.novaxmu.cn/templates/rollcall/img/success.png';
     $temp['Articles'][0]['Url'] = 'http://hackathontsubaki.github.io/Frontend/client.html?' . http_build_query($data);
     // Vera_Log::addNotice('url', $temp['Articles'][0]['Url']);
     $temp['Articles'][1]['Title'] = "SegmentFault";
     $temp['Articles'][1]['PicUrl'] = 'http://tp1.sinaimg.cn/2036070420/180/40003289296/0';
     $temp['Articles'][1]['Url'] = 'segmentfault.com';
     $temp['Articles'][2]['Title'] = "FreesFund | 峰瑞资本";
     $temp['Articles'][2]['PicUrl'] = 'http://freesvc.com/favicon.0bf61f76.ico';
     $temp['Articles'][2]['Url'] = 'http://freesvc.com/';
     $temp['Articles'][3]['Title'] = "有赞";
     $temp['Articles'][3]['PicUrl'] = 'http://static.segmentfault.com/app/hackathon-2015/logos/youzan.8bf6b2b.png';
     $temp['Articles'][3]['Url'] = 'https://www.youzan.com/';
     $temp['Articles'][4]['Title'] = "TalkingData";
     $temp['Articles'][4]['PicUrl'] = 'http://segmentfault.com/img/bVp4TP';
     $temp['Articles'][4]['Url'] = 'https://www.talkingdata.com/';
     $temp['Articles'][5]['Title'] = "阿里百川";
     $temp['Articles'][5]['PicUrl'] = 'http://static.segmentfault.com/app/hackathon-2015/logos/baichuan.cabac3c0.png';
     $temp['Articles'][5]['Url'] = 'https://baichuan.taobao.com/';
     $ret['data'] = $temp;
     return $ret;
 }