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(); }
public function run() { $wechatConf = Vera_Conf::getConf('global')['testWechat']; $appId = $wechatConf['AppID']; $appSecret = $wechatConf['AppSecret']; Vera_Autoload::changeApp('wechat'); $accessToken = Data_Base::getAccessToken($appId, $appSecret); Vera_Autoload::reverseApp(); $ret = array('access_token' => $accessToken); echo json_encode($ret); return false; }
public static function info($openId) { if (!empty(self::$info[$openId])) { return self::$info[$openId]; } $wechatConf = Vera_Conf::getConf('global')['testWechat']; $accessToken = parent::getAccessToken($wechatConf['AppID'], $wechatConf['AppSecret']); $url = sprintf(self::API, $accessToken, $openId); $handle = curl_init(); $options = array(CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1); curl_setopt_array($handle, $options); $content = curl_exec($handle); if (curl_errno($handle)) { //检查是否有误 return array(); } curl_close($handle); $content = json_decode($content, true); if ($content['subscribe'] != 1) { return array(); } self::$info[$openId] = $content; return $content; }