/** * @return bool|mixed * @throws Exception */ private static function _getAccessToken() { $url = sprintf(self::$access_token_url, APPID, APPSECRET); $accessToken = Util::get($url); $accessToken = json_decode($accessToken, true); if (!isset($accessToken['access_token'])) { throw new Exception("获取ACCESS_TOKEN失败"); } //缓存时间,用来判断access_token是否过期 $accessToken['atime'] = time(); $accessTokenJson = json_encode($accessToken); //缓存基础access_token S(self::$cache_id, $accessTokenJson); return $accessToken; }
/** * 通过ticket换取二维码 * * @param string $ticket 票据 * @param string $filepath 文件路径,如果存在,则会保存二维码到本地 * @return bool|mixed * @see http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html */ public static function getQrcodeByTicket($ticket, $filepath = '') { $query_url = sprintf(self::$show_qrcode_url, urlencode($ticket)); $qrcode = Util::get($query_url); if (!empty($filepath)) { file_put_contents($filepath, $qrcode); } return $qrcode; }