/** * 检查下载程序 */ public function update() { if (DR_VERSION_ID != $this->input->get('id') - 1) { $this->admin_msg('对不起,您的系统版本不满足升级条件'); } $data = dr_catcher_data(urldecode($this->input->get('fid'))); if (!$data) { $this->admin_msg('对不起,您的服务器不支持远程下载'); } $save = FCPATH . 'cache/down/update.zip'; $check = FCPATH . 'cache/down/update/'; if (!@file_put_contents($save, $data)) { $this->admin_msg('目录/cache/down/没有写入权限'); } // 解压缩文件 $this->load->helper('file'); $this->load->library('Pclzip'); $this->pclzip->PclFile($save); if ($this->pclzip->extract(PCLZIP_OPT_PATH, $check, PCLZIP_OPT_REPLACE_NEWER) == 0) { @unlink($save); delete_files(FCPATH . 'cache/down/', TRUE); $this->admin_msg("Error : " . $this->pclzip->errorInfo(true)); } // 检查版本文件 if (!is_file($check . 'config/version.php') || !filesize($check . 'config/version.php')) { delete_files(FCPATH . 'cache/down/', TRUE); $this->admin_msg('升级文件不完整,没有找到版本文件'); } $config = (require $check . 'config/version.php'); // 覆盖至网站根目录 $this->pclzip->extract(PCLZIP_OPT_PATH, FCPATH, PCLZIP_OPT_REPLACE_NEWER); $this->dcache->set('install', TRUE); delete_files(FCPATH . 'cache/down/', TRUE); // 运行SQL语句 if (is_file(FCPATH . 'update.sql')) { $sql = file_get_contents(FCPATH . 'update.sql'); $sql = str_replace('{dbprefix}', $this->db->dbprefix, $sql); $sql_data = explode(';SQL_OmWeb_EOL', trim(str_replace(array(PHP_EOL, chr(13), chr(10)), 'SQL_OmWeb_EOL', $sql))); foreach ($sql_data as $query) { if (!$query) { continue; } $queries = explode('SQL_OmWeb_EOL', trim($query)); $ret = ''; foreach ($queries as $query) { $ret .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query; } if (!$ret) { continue; } $this->db->query($ret); } @unlink(FCPATH . 'update.sql'); } //检查update控制器 if (is_file(FCPATH . 'omooo/controllers/admin/Update.php')) { $this->admin_msg('正在升级数据,请稍候...', dr_url('update/index'), 2); } $this->admin_msg('升级完成,请按F5刷新整个页面<script src="http://www.omooo.com/index.php?c=sys&m=updated&site=' . SITE_URL . '&vid=' . $config['DR_VERSION_ID'] . '"></script>', dr_url('home/main'), 1); }
public function get_user_info(OAuth2_Token_Access $token) { $url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&' . http_build_query(array('access_token' => $token->access_token)); $user = json_decode(dr_catcher_data($url), true); // ����ͳһ����ݸ�ʽ return array('oid' => $user['id'], 'oauth' => 'google', 'avatar' => isset($user['picture']) ? $user['picture'] : null, 'nickname' => url_title($user['name'], '_', true), 'expire_at' => $token->expires, 'access_token' => $token->access_token, 'refresh_token' => $token->refresh_token); }
/** * 版本检测 */ private function _version() { $id = (int) dr_catcher_data('http://www.omooo.com/index.php?c=sys&m=now'); if ($id && DR_VERSION_ID < $id) { return $this->halt("您的当前版本过低,为了您网站的安全性,请立即升级到官方最新版本,<a style='color:red' href='" . dr_url('upgrade/index') . "'><b>这里升级</b></a>", 0); } }
/** * 内容 */ public function index() { $id = (int) $this->input->get('id'); $page = max(1, (int) $this->input->get('page')); $body = dr_catcher_data(SITE_URL . DR_ROUTER_PATH . '/index.php?c=extend&id=' . $id . '&page=' . $page); echo $body; exit; }
/** * 获取用户信息 */ public function get_user_info(OAuth2_Token_Access $token) { $url = 'https://api.t.163.com/users/show.json?' . http_build_query(array('access_token' => $token->access_token, 'user_id' => $token->uid)); $return = dr_catcher_data($url); $user = json_decode($return); if (array_key_exists('error', $user)) { throw new OAuth2_Exception($return); } // 返回统一的数据格式 return array('oid' => $user->id, 'oauth' => $this->name, 'avatar' => $user->profile_image_url, 'nickname' => $user->screen_name, 'expire_at' => $token->expires, 'access_token' => $token->access_token, 'refresh_token' => $token->refresh_token); }
/** * 获取用户信息 */ public function get_user_info(OAuth2_Token_Access $token) { $url = 'https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser?' . http_build_query(array('access_token' => $token->access_token, 'uid' => $token->uid)); $return = dr_catcher_data($url); $user = json_decode($return); if (array_key_exists('error', $user)) { throw new OAuth2_Exception($return); } // 返回统一的数据格式 return array('oid' => $user->uid, 'oauth' => $this->name, 'avatar' => 'http://tb.himg.baidu.com/sys/portraitn/item/' . $user->portrait, 'nickname' => $user->uname, 'expire_at' => $token->expires, 'access_token' => $token->access_token, 'refresh_token' => $token->refresh_token); }
/** * ��ȡ�û���Ϣ */ public function get_user_info(OAuth2_Token_Access $token) { // ʹ��Access Token����ȡ�û���OpenID $url = 'https://graph.qq.com/oauth2.0/me?' . http_build_query(array('access_token' => $token->access_token)); $response = dr_catcher_data($url); if (strpos($response, 'callback') !== false) { $lpos = strpos($response, '('); $rpos = strrpos($response, ')'); $response = substr($response, $lpos + 1, $rpos - $lpos - 1); } $me = json_decode($response); if (isset($me->error)) { throw new OAuth2_Exception($response); } // ʹ��Access Token��OpenID��ȡ�û���Ϣ $url = 'https://graph.qq.com/user/get_user_info?' . http_build_query(array('access_token' => $token->access_token, 'openid' => $me->openid, 'oauth_consumer_key' => $this->client_id)); $response = dr_catcher_data($url); $user = json_decode($response); if (isset($user->ret) && $user->ret != 0) { throw new OAuth2_Exception($response); } // ����ͳһ����ݸ�ʽ return array('oid' => $me->openid, 'oauth' => $this->name, 'avatar' => $user->figureurl_1, 'nickname' => $user->nickname, 'expire_at' => $token->expires, 'access_token' => $token->access_token, 'refresh_token' => $token->refresh_token); }
public function kd_status($id, $sn) { $config = $this->link->where('name', 'expresses')->limit(1)->get(SITE_ID . '_' . APP_DIR . '_config')->row_array(); $config = dr_string2array($config['value']); return str_replace(array('ickd_return', '<tr><th>时间</th><th>记录</th></tr>', '</table>'), array('table_form', '', '<tr><td colspan="2" style="border:none;text-align:center;color:red;">以上部分信息来自于第三方</td></tr></table>'), dr_catcher_data('http://api.ickd.cn/?id=' . $config['id'] . '&secret=' . $config['secret'] . '&com=' . $id . '&nu=' . $sn . '&type=html&encode=utf8&ord=asc')); }
public function baidutest() { $ak = $this->input->get('ak'); $sk = $this->input->get('sk'); $host = $this->input->get('host'); $rurl = $this->input->get('rurl'); $bucket = $this->input->get('bucket'); if (!$ak || !$host || !$sk || !$bucket) { exit(lang('035')); } if (!$rurl) { exit(lang('199')); } require_once FCPATH . 'omooo/libraries/BaiduBCS/bcs.class.php'; $bcs = new BaiduBCS($ak, $sk, $host); $opt = array(); $opt['acl'] = BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_WRITE; $opt['curlopts'] = array(CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 1800); $response = $bcs->create_object($bucket, '/test.txt', FCPATH . 'index.php', $opt); if ($response->status == 200) { if (strpos(dr_catcher_data($rurl . '/test.txt'), 'omooo.com') === FALSE) { exit(lang('200')); } $bcs->delete_object($bucket, '/test.txt'); exit('ok'); } else { exit('error'); } }
/** * 远程图片下载 * * @param array $data * @return Bool|String */ public function _execute_down_file($data) { $data = dr_string2array($data); if (!$data) { return '执行值不存在'; } $path = SYS_UPLOAD_PATH . '/' . date('Ym', SYS_TIME) . '/'; if (!is_dir($path)) { dr_mkdirs($path); } $file = dr_catcher_data($data['url']); if (!$file) { return '获取远程数据失败'; } $fileext = strtolower(trim(substr(strrchr($data['url'], '.'), 1, 10))); //扩展名 $filename = substr(md5(time()), 0, 7) . rand(100, 999); if (@file_put_contents($path . $filename . '.' . $fileext, $file)) { $info = array('file_ext' => '.' . $fileext, 'full_path' => $path . $filename . '.' . $fileext, 'file_size' => filesize($path . $filename . '.' . $fileext) / 1024, 'client_name' => $data['url']); $this->load->model('attachment_model'); $result = $this->attachment_model->upload($data['uid'], $info, $data['id']); if (is_array($result)) { list($table, $tid, $eid) = explode('-', $result['related']); $this->ci->load->model('system_model'); $tableinfo = $this->ci->system_model->cache(); // 表结构缓存 $this->ci->clear_cache('attachment-' . $data['id']); // 数据源判断 if (strpos($table, $this->db->dbprefix($result['siteid'])) === 0) { $db = isset($this->site[$result['siteid']]) ? $this->site[$result['siteid']] : $this->db; } else { $db = $this->db; } $url = dr_get_file($data['id']); // 完整地址忽略水印 $field = $data['field']['fieldname']; // 字段名称 if ($data['field']['relatedname'] == 'module') { // 模块表部分 if (strpos($table, '_draft') || strpos($table, '_verify')) { // 草稿和审核表 $row = $db->where('id', $tid)->get($table)->row_array(); $content = dr_string2array($row['content']); if (isset($content[$field]) && $content[$field]) { $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]); $db->where('id', $tid)->update($table, array('content' => dr_array2string($content))); } return TRUE; } else { // 模块表 if (!$data['field']['ismain']) { // 附表 $index = $db->where('id', $tid)->get($table . '_index')->row_array(); $table = $table . '_data_' . intval($index['tableid']); } } } elseif ($data['field']['relatedname'] == 'extend') { // 模块扩展表部分 if (strpos($table, '_draft') || strpos($table, '_verify')) { // 草稿和审核表 $row = $db->where('id', $tid)->get($table)->row_array(); $content = dr_string2array($row['content']); if (isset($content[$field]) && $content[$field]) { $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]); $db->where('id', $tid)->update($table, array('content' => dr_array2string($content))); } return TRUE; } else { // 内容表 if (!$data['field']['ismain']) { // 附表 $index = $db->where('id', $tid)->get($table . '_extend_index')->row_array(); $table = $table . '_extend_data_' . intval($index['tableid']); } } } else { list($dir, $catid) = explode('-', $data['field']['relatedname']); if (is_dir(FCPATH . $dir)) { // 栏目附加字段 if (!$data['field']['ismain']) { // 附表 $index = $db->where('id', $tid)->get($table . '_index')->row_array(); $table = $table . '_category_data_' . intval($index['tableid']); } else { // 主表 $table = $table . '_category_data'; } } } // 表结构不存在 if (!isset($tableinfo[$table]['field'])) { @unlink($info['full_path']); return '表结构不存在:' . $table; } // 替换操作 if (isset($tableinfo[$table]['field'][$field])) { $db->query('UPDATE `' . $table . '` SET `' . $field . '` = replace (`' . $field . '`, "' . $data['url'] . '?s=finecms", "' . $url . '")'); } else { @unlink($info['full_path']); return '表' . $table . '没有字段:' . $field; } return TRUE; } else { return $result; } } else { return '文件移动失败,目录无权限(' . $path . ')'; } }
/** * 下载远程文件 * * @param intval $uid uid 用户id * @param string $url 文件url * @return array */ public function catcher($uid, $url) { if (!$uid || !$url) { return NULL; } // 站点信息 $siteinfo = $this->ci->get_cache('siteinfo', SITE_ID); // 域名验证 $domain = (require FCPATH . 'config/domain.php'); foreach ($siteinfo['remote'] as $t) { $domain[$t['SITE_ATTACH_URL']] = TRUE; } $domain['baidu.com'] = TRUE; $domain['google.com'] = TRUE; foreach ($domain as $uri => $t) { if (stripos($url, $uri) !== FALSE) { return NULL; } } $path = FCPATH . 'member/uploadfile/' . date('Ym', SYS_TIME) . '/'; if (!is_dir($path)) { dr_mkdirs($path); } $filename = substr(md5(time()), 0, 7) . rand(100, 999); $data = dr_catcher_data($url); if (!$data) { return NULL; } $fileext = strtolower(trim(substr(strrchr($url, '.'), 1, 10))); //扩展名 if (file_put_contents($path . $filename . '.' . $fileext, $data)) { $info = array('file_ext' => '.' . $fileext, 'full_path' => $path . $filename . '.' . $fileext, 'file_size' => filesize($path . $filename . '.' . $fileext) / 1024, 'client_name' => $url); return $this->upload($uid, $info, NULL); } return NULL; }
/** * 升级程序 */ public function upgrade() { $key = (int) $this->input->get('key'); $dir = $this->input->get('dir'); if (is_file(FCPATH . 'app/' . $dir . '/config/app.php')) { $config = (require FCPATH . 'app/' . $dir . '/config/app.php'); if ((int) $config['key'] != $key) { $this->admin_msg('此应用无法在线升级,key不匹配'); } } else { $this->admin_msg('此应用无法在线升级,目录(/app/' . $dir . '/)不存在'); } $data = dr_catcher_data(urldecode($this->input->get('id'))); if (!$data) { $this->admin_msg('对不起,您的服务器不支持远程下载'); } $save = FCPATH . 'cache/down/app.zip'; $check = FCPATH . 'cache/down/app/'; if (!@file_put_contents($save, $data)) { $this->admin_msg('目录/cache/down/没有写入权限'); } // 解压缩文件 $this->load->helper('file'); $this->load->library('Pclzip'); // 文件安全性检测 $this->pclzip->PclFile($save); $content = $this->pclzip->listContent(); if (!$content) { $this->admin_msg('文件下载不完整或者已经损坏!<br>请检查网站目录权限或者联系应用开发者。'); } foreach ($content as $t) { if (strpos($t['stored_filename'], '..') !== FALSE || strpos($t['stored_filename'], '/') === 0) { $this->admin_msg('含有非法名称的文件:' . basename($t['stored_filename'])); } } unset($content); // 开始解压文件 if ($this->pclzip->extract(PCLZIP_OPT_PATH, $check, PCLZIP_OPT_REPLACE_NEWER) == 0) { @unlink($save); delete_files(FCPATH . 'cache/down/', TRUE); $this->admin_msg("Error : " . $this->pclzip->errorInfo(true)); } // 检查版本文件 if (!is_file($check . 'config/app.php') || !filesize($check . 'config/app.php')) { delete_files(FCPATH . 'cache/down/', TRUE); $this->admin_msg('升级文件不完整,请重试'); } // 覆盖至网站目录 $this->pclzip->extract(PCLZIP_OPT_PATH, FCPATH . 'app/' . $dir, PCLZIP_OPT_REPLACE_NEWER); delete_files(FCPATH . 'cache/down/', TRUE); // 运行SQL语句 if (is_file(FCPATH . 'app/' . $dir . '/update.sql')) { $sql = file_get_contents(FCPATH . 'app/' . $dir . '/update.sql'); $sql = str_replace('{dbprefix}', $this->db->dbprefix, $sql); $this->sql_query($sql); @unlink(FCPATH . 'app/' . $dir . '/update.sql'); } //检查update控制器 if (is_file(FCPATH . 'app/' . $dir . '/controllers/admin/Update.php')) { $this->admin_msg('正在升级数据,请稍候...', dr_url($dir . '/update/index'), 2); } $this->admin_msg('升级完成,请重新检测一次版本', dr_url('application/index'), 1); }
/** * 短信发送 * * @param string $mobile * @param string $content * @return bool */ public function sendsms($mobile, $content, $tid) { if (!$mobile || !$content) { return FALSE; } $file = FCPATH . 'config/sms.php'; if (!is_file($file)) { return FALSE; } if (!$tid) { $tid = "1"; } $config = (require_once $file); if ($config['third']) { $this->load->helper('sms'); if (function_exists('my_sms_send')) { $result = my_sms_send($mobile, $content . '【' . $config['note'] . '】'); } else { return FALSE; } } else { $result = dr_catcher_data('http://www.omooo.com/sms.php?c=send&tid=' . $tid . '&uid=' . $config['uid'] . '&key=' . $config['key'] . '&mobile=' . $mobile . '&content=' . $content . '&domain=' . trim(str_replace('http://', '', SITE_URL), '/') . '&sitename=' . SITE_NAME); if (!$result) { return FALSE; } $result = dr_object2array(json_decode($result)); //对象转换数组 } @file_put_contents(FCPATH . 'cache/sms_error.log', date('Y-m-d H:i:s') . ' [' . $mobile . '] [' . $result['msg'] . '] (' . str_replace(array(chr(13), chr(10)), '', $content) . ')' . PHP_EOL, FILE_APPEND); return $result; }
function fn_sendsms($mobile, $content) { if (!$mobile || !$content) { return FALSE; } $file = FCPATH . 'config/sms.php'; $config = is_file($file) ? string2array(file_get_contents($file)) : array(); $result = dr_catcher_data('http://sms.dayrui.com/index.php?uid=' . $config['uid'] . '&key=' . $config['key'] . '&mobile=' . $mobile . '&content=' . $content . '【' . $config['note'] . '】&domain=' . trim(str_replace('http://', '', SITE_URL), '/') . '&sitename=' . CMS_NAME); if (!$result) { return FALSE; } $result = dr_object2array(json_decode($result)); @file_put_contents(FCPATH . 'cache/sms.log', date('Y-m-d H:i:s') . ' [' . $mobile . '] [' . $result['msg'] . '] (' . str_replace(array(chr(13), chr(10)), '', $content) . ')' . PHP_EOL, FILE_APPEND); return $result; }
/** * 图片处理 */ public function thumb() { $id = (int) $this->input->get('id'); $info = get_attachment($id); // 图片信息 $file = $info && in_array($info['fileext'], array('jpg', 'gif', 'png')) ? $info['attachment'] : 'omooo/statics/images/nopic.gif'; // 图片判断 // 参数设置 $water = (int) $this->input->get('water'); $width = (int) $this->input->get('width'); $height = (int) $this->input->get('height'); $thumb_file = FCPATH . 'member/uploadfile/thumb/' . md5("index.php?c=api&m=thumb&id={$id}&width={$width}&height={$height}&water={$water}") . '.jpg'; if (!is_dir(FCPATH . 'member/uploadfile/thumb/')) { @mkdir(FCPATH . 'member/uploadfile/thumb/'); } // 远程图片下载到本地缓存目录 if (isset($info['remote']) && $info['remote']) { $file = FCPATH . 'cache/attach/' . time() . '_' . basename($info['attachment']); file_put_contents($file, dr_catcher_data($info['attachment'])); } else { $file = FCPATH . $file; } // 处理宽高 list($_width, $_height) = getimagesize($file); $width = $width ? $width : $_width; $height = $height ? $height : $_height; // 站点配置信息 $site = $this->get_cache('siteinfo', SITE_ID); $iswater = (bool) $site['SITE_IMAGE_WATERMARK']; $config['width'] = $width; $config['height'] = $height; $config['create_thumb'] = TRUE; $config['source_image'] = $file; $config['is_watermark'] = $iswater && $water ? TRUE : FALSE; // 开启水印 $config['is_watermark'] = isset($info['remote']) && $info['remote'] && !$site['SITE_IMAGE_REMOTE'] ? FALSE : $config['is_watermark']; // 远程附件图片水印关闭 $config['image_library'] = 'gd2'; $config['dynamic_output'] = TRUE; // 输出到浏览器 $config['maintain_ratio'] = (bool) SITE_IMAGE_RATIO; // 使图像保持原始的纵横比例 // 水印参数 $config['wm_type'] = $site['SITE_IMAGE_TYPE'] ? 'overlay' : 'text'; $config['wm_vrt_offset'] = $site['SITE_IMAGE_VRTOFFSET']; $config['wm_hor_offset'] = $site['SITE_IMAGE_HOROFFSET']; $config['wm_vrt_alignment'] = $site['SITE_IMAGE_VRTALIGN']; $config['wm_hor_alignment'] = $site['SITE_IMAGE_HORALIGN']; // 文字模式 $config['wm_text'] = $site['SITE_IMAGE_TEXT']; $config['wm_font_size'] = $site['SITE_IMAGE_SIZE']; $config['wm_font_path'] = FCPATH . 'omooo/statics/watermark/' . ($site['SITE_IMAGE_FONT'] ? $site['SITE_IMAGE_FONT'] : 'default.ttf'); $config['wm_font_color'] = $site['SITE_IMAGE_COLOR'] ? str_replace('#', '', $site['SITE_IMAGE_COLOR']) : '#000000'; // 图片模式 $config['wm_opacity'] = $site['SITE_IMAGE_OPACITY'] ? $site['SITE_IMAGE_OPACITY'] : 80; $config['wm_overlay_path'] = FCPATH . 'omooo/statics/watermark/' . ($site['SITE_IMAGE_OVERLAY'] ? $site['SITE_IMAGE_OVERLAY'] : 'default.png'); $this->load->library('image_lib2', $config); $this->image_lib2->resize($thumb_file); if (isset($info['remote']) && $info['remote']) { @unlink($file); } }
/** * QQ微博分享 * * @param array $data * @return Bool|String */ public function _execute_qqshare($data) { $data = dr_string2array($data); if (!$data) { return '执行值不存在'; } $config = (require FCPATH . 'config/oauth.php'); if (!isset($config['qq']) || !isset($config['qq']['key'])) { return 'QQ配置文件不正确或者Key不存在'; } // 查询OAuth2授权信息 $auth = $this->db->where('uid', (int) $data['uid'])->where('oauth', 'qq')->limit(1)->get('member_oauth')->row_array(); if (!$auth) { return '会员uid:' . $data['uid'] . ' 授权信息不存在'; } $thumb = $data['thumb']; $content = $data['title'] . ' ' . $data['url']; if (function_exists('curl_init')) { // curl方式 $par = 'access_token=' . $auth['access_token'] . '&oauth_consumer_key=' . $config['qq']['key'] . '&openid=' . $auth['oid']; $par .= '&format=xml&content=' . $content; $headers = array(); $pic = ''; if ($thumb) { // 强图片转为临时目录 $tmp = dr_catcher_data($thumb); if ($tmp) { $ext = trim(strrchr($thumb, '.'), '.'); $ext = in_array($ext, array('jpg', 'png', 'gif')) ? $ext : 'jpg'; $pic = FCPATH . 'cache/attach/' . md5($thumb) . '.' . $ext; file_put_contents($pic, $tmp); $headers[] = 'Expect: '; $tmp = array(); foreach (explode('&', $par) as $v) { $t = explode('=', $v); $tmp[$t[0]] = $t[1]; } $tmp['pic'] = '@' . $pic; $par = $tmp; } } $cur = curl_init('https://graph.qq.com/t/' . ($pic ? 'add_pic_t ' : 'add_t')); curl_setopt($cur, CURLOPT_POST, 1); curl_setopt($cur, CURLOPT_POSTFIELDS, $par); curl_setopt($cur, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($cur, CURLOPT_HEADER, 0); curl_setopt($cur, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($cur, CURLOPT_RETURNTRANSFER, 1); if ($headers) { curl_setopt($cur, CURLOPT_HTTPHEADER, $headers); } $rec = curl_exec($cur); curl_close($cur); if ($pic) { @unlink($pic); } if (strpos($rec, '<msg>ok</msg>') === FALSE) { //fail return $rec; } else { //success return TRUE; } } else { return 'QQ微博分享提示:服务器不支持CURL函数'; } }
/** * 获取access_token * @return mixed */ protected function _get_access_token() { $name = APP_ROOT . 'cache/' . SITE_ID . '_access_token.txt'; $data = @json_decode(@file_get_contents($name), true); if (isset($data['time']) && $data['time'] > time() && isset($data['access_token']) && $data['access_token']) { return $data['access_token']; } $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->wx_config['appid'] . '&secret=' . $this->wx_config['appsecret']; $data = json_decode(@dr_catcher_data($url), true); if (!$data) { @unlink($name); $this->adminMsg('获取access_token失败,请检查服务器是否支持远程链接'); } if (isset($data['errmsg']) && $data['errmsg']) { @unlink($name); $this->adminMsg('错误代码(' . $data['errcode'] . '):' . $data['errmsg']); } $data['time'] = time() + $data['expires_in']; @file_put_contents($name, json_encode($data)); return $data['access_token']; }