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(); }
function __construct($content) { parent::__construct(); $content['data'] = array_change_key_case($content['data'], CASE_LOWER); //数组键名全小写,以满足推送 api 的要求 $temp = array('touser' => '', 'msgtype' => $content['type'], $content['type'] => $content['data']); $this->_content = $temp; $this->_api = sprintf($this->_api, $this->accessToken); }
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; }
protected static function getUserInfo() { if (empty(self::$resource)) { throw new Exception("Resource can not be empty", 1); } if (!($db = Vera_Database::getInstance())) { throw new Exception("Cannot get instance of database", 1); } $result = $db->select('vera_User', '*', array('wechat_id' => self::$resource['openid'])); if (!$result) { self::$userInfo = -1; return NULL; } self::$userInfo = $result[0]; return $result[0]; }
public function run() { if (empty($_SERVER['HTTP_REFERER'])) { echo json_encode(array('errmsg' => 'referer is empty')); return false; } $wechatConf = Vera_Conf::getConf('global')['testWechat']; $url = $_SERVER['HTTP_REFERER']; $appId = $wechatConf['AppID']; $appSecret = $wechatConf['AppSecret']; Vera_Autoload::changeApp('wechat'); $ticket = Data_Base::getJsTicket($appId, $appSecret); $signArr = Data_Base::getJsSign($url, $ticket); Vera_Autoload::reverseApp(); $signArr['appId'] = $appId; echo json_encode($signArr); 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; }
function __construct($resource) { parent::__construct($resource); }