record() public static method

记录调试信息
public static record ( mixed $msg, string $type = 'log' ) : void
$msg mixed 调试信息
$type string 信息类型
return void
Esempio n. 1
0
 public function testRecord()
 {
     $record_msg = 'record';
     Log::record($record_msg, 'notice');
     $logs = Log::getLog();
     $this->assertNotFalse(array_search(['type' => 'notice', 'msg' => $record_msg], $logs));
 }
Esempio n. 2
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  * @author jry <*****@*****.**>
  */
 public function getAllAddon($addon_dir = THINK_ADDON_PATH)
 {
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $map['name'] = array('in', $dirs);
     $list = $this->where($map)->field(true)->order('sort asc,id desc')->select();
     foreach ($list as $addon) {
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['status'] = -1;
                 //未安装
             }
         }
     }
     foreach ($addons as &$val) {
         switch ($val['status']) {
             case '-1':
                 //未安装
                 $val['status'] = '<i class="glyphicon glyphicon-trash" style="color:red"></i>';
                 $val['right_button'] = '<a class="ajax-get" href="' . U('install?addon_name=' . $val['name']) . '">安装</a>';
                 break;
             case '0':
                 //禁用
                 $val['status'] = '<i class="glyphicon glyphicon-ban-circle" style="color:red"></i>';
                 $val['right_button'] = '<a href="' . U('config', array('id' => $val['id'])) . '">设置</a> ';
                 $val['right_button'] .= '<a class="ajax-get" href="' . U('setStatus', array('status' => 'resume', 'ids' => $val['id'])) . '">启用</a> ';
                 $val['right_button'] .= '<a class="ajax-get" href="' . U('uninstall?id=' . $val['id']) . '">卸载</a> ';
                 if ($val['adminlist']) {
                     $val['right_button'] .= '<a href="' . U('adminlist', array('name' => $val['name'])) . '">管理</a>';
                 }
                 break;
             case '1':
                 //正常
                 $val['status'] = '<i class="glyphicon glyphicon-ok" style="color:green"></i>';
                 $val['right_button'] = '<a href="' . U('config', array('id' => $val['id'])) . '">设置</a> ';
                 $val['right_button'] .= '<a class="ajax-get" href="' . U('setStatus', array('status' => 'forbid', 'ids' => $val['id'])) . '">禁用</a> ';
                 $val['right_button'] .= '<a class="ajax-get" href="' . U('uninstall?id=' . $val['id']) . '">卸载</a> ';
                 if ($val['adminlist']) {
                     $val['right_button'] .= '<a href="' . U('adminlist', array('name' => $val['name'])) . '">管理</a>';
                 }
                 break;
         }
     }
     return $addons;
 }
Esempio n. 3
0
 /**
  * 发送模板短信
  * @param String $to 短信接收彿手机号码集合,用英文逗号分开
  * @param array $datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
  * @param int $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
  * @return 内容数据|mixed
  */
 function sendTemplateSMS($to, $datas, $tempId)
 {
     $this->Batch = date("YmdHis");
     // 拼接请求包体
     $data = "";
     for ($i = 0; $i < count($datas); $i++) {
         $data = $data . "'" . $datas[$i] . "',";
     }
     $body = "{'to':'{$to}','templateId':'{$tempId}','appId':'{$this->AppId}','datas':[" . $data . "]}";
     $level = Log::INFO;
     Log::record("response body = " . $body, $level);
     // 大写的sig参数
     $sig = strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));
     // 生成请求URL
     $url = "https://{$this->ServerIP}:{$this->ServerPort}/{$this->SoftVersion}/Accounts/{$this->AccountSid}/SMS/TemplateSMS?sig={$sig}";
     Log::record("request url = " . $url, $level);
     // 生成授权:主帐户Id + 英文冒号 + 时间戳。
     $authen = base64_encode($this->AccountSid . ":" . $this->Batch);
     // 生成包头
     $header = array("Accept:application/{$this->BodyType}", "Content-Type:application/{$this->BodyType};charset=utf-8", "Authorization:{$authen}");
     // 发送请求
     $result = $this->curl_post($url, $body, $header);
     Log::record("response body = " . $result, $level);
     $datas = json_decode($result);
     //重新装填数据
     if ($datas->statusCode == 0) {
         if ($this->BodyType == "json") {
             $datas->TemplateSMS = $datas->templateSMS;
             unset($datas->templateSMS);
         }
     }
     return $datas;
 }
Esempio n. 4
0
 public function testRecord()
 {
     $record_msg = 'record';
     Log::record($record_msg, 'notice');
     $logs = Log::getLog();
     $this->assertNotFalse(array_search($record_msg, $logs['notice']));
 }
Esempio n. 5
0
 /**
  * 加载语言定义(不区分大小写)
  * @param string $file 语言文件
  * @param string $range 语言作用域
  * @return mixed
  */
 public static function load($file, $range = '')
 {
     $range = $range ?: self::$range;
     if (!isset(self::$lang[$range])) {
         self::$lang[$range] = [];
     }
     // 批量定义
     if (is_string($file)) {
         $file = [$file];
     }
     $lang = [];
     foreach ($file as $_file) {
         if (is_file($_file)) {
             // 记录加载信息
             APP_DEBUG && Log::record('[ LANG ] ' . $_file, 'info');
             $_lang = (include $_file);
         } else {
             $_lang = [];
         }
         $lang = array_change_key_case($_lang) + $lang;
     }
     if (!empty($lang)) {
         self::$lang[$range] = $lang + self::$lang[$range];
     }
     return self::$lang[$range];
 }
Esempio n. 6
0
 public function testSave()
 {
     Log::init(['type' => 'test']);
     Log::clear();
     Log::record('test');
     Log::record([1, 2, 3]);
     $this->assertTrue(Log::save());
 }
Esempio n. 7
0
 /**
  * session初始化
  * @param array $config
  * @return void
  * @throws \think\Exception
  */
 public static function init(array $config = [])
 {
     if (empty($config)) {
         $config = Config::get('session');
     }
     // 记录初始化信息
     App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info');
     $isDoStart = false;
     if (isset($config['use_trans_sid'])) {
         ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0);
     }
     // 启动session
     if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) {
         ini_set('session.auto_start', 0);
         $isDoStart = true;
     }
     if (isset($config['prefix'])) {
         self::$prefix = $config['prefix'];
     }
     if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) {
         session_id($_REQUEST[$config['var_session_id']]);
     } elseif (isset($config['id']) && !empty($config['id'])) {
         session_id($config['id']);
     }
     if (isset($config['name'])) {
         session_name($config['name']);
     }
     if (isset($config['path'])) {
         session_save_path($config['path']);
     }
     if (isset($config['domain'])) {
         ini_set('session.cookie_domain', $config['domain']);
     }
     if (isset($config['expire'])) {
         ini_set('session.gc_maxlifetime', $config['expire']);
         ini_set('session.cookie_lifetime', $config['expire']);
     }
     if (isset($config['use_cookies'])) {
         ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
     }
     if (isset($config['cache_limiter'])) {
         session_cache_limiter($config['cache_limiter']);
     }
     if (isset($config['cache_expire'])) {
         session_cache_expire($config['cache_expire']);
     }
     if (!empty($config['type'])) {
         // 读取session驱动
         $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
         // 检查驱动类
         if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
             throw new ClassNotFoundException('error session handler:' . $class, $class);
         }
     }
     if ($isDoStart) {
         session_start();
     }
 }
 public function auth()
 {
     $account = I("post.account");
     $pwd = I("post.password");
     Log::record($account . "" . $pwd);
     $all = '{"data":{"account":"*****@*****.**","apiKey":"ed8b72515a1577c26edebf2f2654238d74108b6d","articleVisible":1,"authString":"0,947742853@qq.com,1439045570","brokerDomain":null,"bwTenant":null,"device":null,"email":"*****@*****.**","expiredAt":1443862842,"guest":false,"ip":"222.41.113.210","locale":"zh","login":null,"mt4Group":null,"nickname":"test123","phone":null,"randomKey":null,"serviceId":null,"symbols":null,"tenantId":"0","tenantName":null,"token":"1439112842,266,24e8bc0ef5","twTimeout":30,"userAvatar":"https://p-picture.b0.upaiyun.com/default_avatar.jpg","userId":266,"verification":null},"message":"登录成功","result":1}';
     $data = json_decode($all);
     echo $all;
 }
 function movieStart($movietime)
 {
     \Think\Log::record('开场提示:' . $movietime['pid'] . '-' . $movietime['title']);
     //推送开场提醒
     D('JPush', 'Logic')->pushNotificationByTags(C('PUSH_PARTY_PREFIX') . $movietime['pid'], '你参加的' . $movietime['title'] . '活动即将开始,摇一摇加入社交圈,开启捉影之旅。', null, array("redirect" => "circleentry"));
     //向融云服务器发送创建群组的请求
     $im = D('Im', 'Logic');
     $im->createCircle($movietime['id']);
     M('Socialcircle')->where('id = %d', $movietime['id'])->setField('openstatus', 1);
 }
Esempio n. 10
0
 /**
  *index
  *api令牌生成
  * 支持操作post
  *@return json,xml
  *@author NewFuture
  */
 public function index()
 {
     $pwd = I('post.pwd');
     $type = I('post.type', null, 'int');
     $Model = null;
     switch ($type) {
         case C('STUDENT'):
         case C('STUDENT_API'):
             $account = I('post.account', 0, C('REGEX_NUMBER'));
             $Model = M('user');
             $where['student_number'] = $account;
             break;
         case C('PRINTER'):
         case C('PRINTER_WEB'):
             $account = I('post.account', null, C('REGEX_ACCOUNT'));
             $Model = M('printer');
             $where['account'] = $account;
             break;
         default:
             $data['err'] = 'unknown user type';
     }
     if (!isset($data)) {
         if ($account) {
             $key = 'api_' . $account;
             $times = S($key);
             if ($times > C('MAX_TRIES')) {
                 \Think\Log::record('api爆破警告:ip:' . get_client_ip() . ',account:' . $account, 'NOTIC', true);
                 $data['err'] = '此账号尝试次数过多,已经暂时封禁,请于一小时后重试!(ps:你的行为已被系统记录)';
             } else {
                 S($key, $times + 1, 3600);
                 $info = $Model->where($where)->field('id,password,name')->find();
                 $id = $info['id'];
                 $password = $info['password'];
                 if ($password == encode($pwd, $account)) {
                     $token = update_token($id, $type);
                     if ($token) {
                         S($key, null);
                         $data['token'] = $token;
                         $data['name'] = $info['name'];
                         $data['id'] = $info['id'];
                     } else {
                         $data['err'] = '创建令牌失败';
                     }
                 } else {
                     $data['err'] = 'authored failed';
                 }
             }
         } else {
             $data['err'] == 'illegal account';
         }
     }
     $data['version'] = C('API_VERSION');
     $this->response($data, $this->_type == 'xml' ? 'xml' : 'json');
 }
Esempio n. 11
0
 public function index()
 {
     Log::record('收到消息' . date('Ymd H:m:s') . 'Form:' . get_client_ip());
     $weixin = new ThinkWechat(get_opinion('weixin_token'));
     /* 获取请求信息 */
     $data = $weixin->request();
     /* 获取回复信息 */
     list($content, $type) = $this->reply($data);
     /* 响应当前请求 */
     $weixin->response($content, $type);
     Log::record('发送消息' . date('Ymd H:m:s'));
 }
Esempio n. 12
0
File: Error.php Progetto: klsf/kldns
 /**
  * Error Handler
  * @param  integer $errno   错误编号
  * @param  integer $errstr  详细错误信息
  * @param  string  $errfile 出错的文件
  * @param  integer $errline 出错行号
  * @return bool  true-禁止往下传播已处理过的异常
  */
 public static function appError($errno, $errstr, $errfile = null, $errline = 0, array $errcontext = [])
 {
     if ($errno & Config::get('exception_ignore_type')) {
         // 忽略的异常记录到日志
         Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notice');
     } else {
         // 将错误信息托管至 think\exception\ErrorException
         throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
         // 禁止往下传播已处理过的异常
         return true;
     }
 }
Esempio n. 13
0
 /**
  * 渲染模板文件
  * @access public
  * @param string $template 模板文件
  * @param array $data 模板变量
  * @param array $config 模板参数
  * @return void
  */
 public function fetch($template, $data = [], $config = [])
 {
     if (!is_file($template)) {
         // 获取模板文件名
         $template = $this->parseTemplate($template);
     }
     // 模板不存在 抛出异常
     if (!is_file($template)) {
         throw new Exception('template file not exists:' . $template, 10700);
     }
     // 记录视图信息
     APP_DEBUG && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
     $this->template->fetch($template, $data, $config);
 }
Esempio n. 14
0
 /**
  * 渲染模板文件
  * @access public
  * @param string    $template 模板文件
  * @param array     $data 模板变量
  * @param array     $config 模板参数
  * @return void
  */
 public function fetch($template, $data = [], $config = [])
 {
     if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
         // 获取模板文件名
         $template = $this->parseTemplate($template);
     }
     // 模板不存在 抛出异常
     if (!is_file($template)) {
         throw new TemplateNotFoundException('template not exists:' . $template, $template);
     }
     // 记录视图信息
     App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
     $this->template->fetch($template, $data, $config);
 }
Esempio n. 15
0
 /**
  * * 响应微信发送的信息(自动回复)
  * @param  array $content 回复信息,文本信息为string类型
  * @param  string $type    消息类型
  * @param int|string $flag 是否新标刚接受到的信息
  * @internal param string $to 接收用户名
  * @internal param string $from 发送者用户名
  * @return string          XML字符串
  */
 public function response($content, $type = 'text', $flag = 0)
 {
     /* 基础数据 */
     $this->data = array('ToUserName' => $this->data['FromUserName'], 'FromUserName' => $this->data['ToUserName'], 'CreateTime' => NOW_TIME, 'MsgType' => $type);
     /* 添加类型数据 */
     $this->{$type}($content);
     /* 添加状态 */
     $this->data['FuncFlag'] = $flag;
     /* 转换数据为XML */
     $xml = new \SimpleXMLElement('<xml></xml>');
     $this->data2xml($xml, $this->data);
     \Think\Log::record('echo:' . $xml->asXML());
     exit($xml->asXML());
 }
Esempio n. 16
0
 /**
  * Report or log an exception.
  *
  * @param  \Exception $exception
  * @return void
  */
 public function report(Exception $exception)
 {
     if (!$this->isIgnoreReport($exception)) {
         // 收集异常数据
         if (APP_DEBUG) {
             $data = ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $exception->getMessage(), 'code' => $this->getCode($exception)];
             $log = "[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]";
         } else {
             $data = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
             $log = "[{$data['code']}]{$data['message']}";
         }
         Log::record($log, 'error');
     }
 }
Esempio n. 17
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ONETHINK_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     //TODO 新增模块插件的支持
     /* $modules=D('Module')->getAll();
        foreach($modules as $m){
            if($m['is_setup']){
                $module_dir=APP_PATH.$m['name'].'/Addons/';
                if(!file_exists($module_dir)){
                    continue;
                }
                $tmp_dirs = array_map('basename',glob($module_dir.'*', GLOB_ONLYDIR));
                $dirs=array_merge($dirs,$tmp_dirs);
            }
        }*/
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
         }
     }
     //dump($list);exit;
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Esempio n. 18
0
File: Log.php Progetto: GDdark/cici
 /**
  * 日志初始化
  * @param array $config
  */
 public static function init($config = [])
 {
     $type = isset($config['type']) ? $config['type'] : 'File';
     $class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
     self::$config = $config;
     unset($config['type']);
     if (class_exists($class)) {
         self::$driver = new $class($config);
     } else {
         throw new ClassNotFoundException('class not exists:' . $class, $class);
     }
     // 记录初始化信息
     App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
 }
Esempio n. 19
0
 /**
  * 新增/修改操作
  */
 public function edit()
 {
     $this->isAjaxLogin();
     $m = D('Admin/Navs');
     $rs = array();
     if (I('id', 0) > 0) {
         \Think\Log::record(__LINE__);
         $this->checkAjaxPrivelege('dhgl_02');
         $rs = $m->edit();
     } else {
         $this->checkAjaxPrivelege('dhgl_01');
         $rs = $m->insert();
     }
     $this->ajaxReturn($rs);
 }
Esempio n. 20
0
 /**
  * 获取插件列表
  *
  * @param string $addon_dir        	
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ONETHINK_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === FALSE || !file_exists($addon_dir) || count($dirs) == 0) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->order('id desc')->select();
     foreach ($list as $addon) {
         $addon['is_weixin'] = file_exists($addon_dir . $addon['name'] . '/Model/WeixinAddonModel.class.php');
         $addon['uninstall'] = 0;
         $addon['is_show_text'] = $addon['is_show'] == 1 ? '是' : '否';
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
             $addons[$value]['is_weixin'] = file_exists($addon_dir . $value . '/Model/WeixinAddonModel.class.php');
         }
     }
     foreach ($addons as $key => $val) {
         if (!$val['is_weixin']) {
             unset($addons[$key]);
         }
     }
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Esempio n. 21
0
 /**
  * 构造方法,用于实例化微信SDK
  * @param string $token 微信开放平台设置的TOKEN
  */
 public function __construct($token)
 {
     /**
      * warning 不检测签名加快速度
      */
     //$this->checkSignature($token) || exit;
     if (IS_GET) {
         exit($_GET['echostr']);
     } else {
         $xml = file_get_contents("php://input");
         \Think\Log::record('消息内容GET' . $xml);
         $xml = new \SimpleXMLElement($xml);
         $xml || exit;
         foreach ($xml as $key => $value) {
             $this->data[$key] = strval($value);
         }
     }
 }
Esempio n. 22
0
 /**
  * 存储缓存
  * @param $cacheId 缓存Key
  * @param $value 值
  * @param int $expire 过期时间
  * @param bool $needCompress 是否压缩
  * @return bool|\boolen
  */
 public function set($cacheId, $value, $expire = 0, $needCompress = false)
 {
     //三次尝试
     $ret = parent::set($cacheId, $value, $needCompress, $expire);
     if (!$ret) {
         $ret = parent::set($cacheId, $value, $needCompress, $expire);
     }
     if (!$ret) {
         $ret = parent::set($cacheId, $value, $needCompress, $expire);
     }
     if ($ret) {
         return $ret;
     } else {
         //log error.
         Log::record('set to mc failed! server is:' . var_export($this->_serverAry, true));
     }
     return $ret;
 }
Esempio n. 23
0
 /**
  * 获取公众账号基本信息
  * @param unknown_type $key
  * @param unknown_type $val
  * @return boolean|Ambigous 
  */
 public function val($key, $val = "")
 {
     try {
         $where['key'] = $key;
         if ($val) {
             //更新value值
             $result = $this->where($where)->setField("value", $val);
             return $result;
         } else {
             //获取value值
             $val = $this->where($where)->getField("value");
             return $val;
         }
     } catch (\Exception $e) {
         Log::record($e->getMessage());
         return false;
     }
 }
Esempio n. 24
0
 /**
  * 连接缓存
  * @access public
  * @param array         $options  配置数组
  * @param bool|string   $name 缓存连接标识 true 强制重新连接
  * @return object
  */
 public static function connect(array $options = [], $name = false)
 {
     $type = !empty($options['type']) ? $options['type'] : 'File';
     if (false === $name) {
         $name = $type;
     }
     if (true === $name || !isset(self::$instance[$name])) {
         $class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
         // 记录初始化信息
         App::$debug && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info');
         if (true === $name) {
             return new $class($options);
         } else {
             self::$instance[$name] = new $class($options);
         }
     }
     self::$handler = self::$instance[$name];
     return self::$handler;
 }
Esempio n. 25
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ZS_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             $admin_list = $obj->admin_list;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
             if ($admin_list) {
                 $addons[$value]['has_adminlist'] = 1;
             } else {
                 $addons[$value]['has_adminlist'] = 0;
             }
         }
     }
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Esempio n. 26
0
 /**
  * 发送验证码
  */
 public function send($mobile, $code)
 {
     $url = 'http://api.189.cn/v2/emp/templateSms/sendSms';
     $post = [];
     $post['app_id'] = $this->config['appId'];
     $post['access_token'] = $this->_getAccessToken();
     $post['acceptor_tel'] = $mobile;
     $post['template_id'] = 91002003;
     $post['template_param'] = json_encode(array('param1' => $code));
     $post['timestamp'] = urlencode(date('Y-m-d H:i:s'));
     $res = $this->_httpRequest($url, $post);
     if ($res['res_code'] == 0) {
         \Think\Log::record('发送短信成功:' . $mobile . ' => ' . $code, \Think\Log::INFO);
         return true;
     } else {
         \Think\Log::record('发送短信失败:' . $mobile . ' => ' . $res['res_message']);
         return false;
     }
 }
Esempio n. 27
0
 /**
  * 构造方法,用于实例化微信SDK
  * 自动回复消息时实例化该SDK
  * @param string $token 微信后台填写的TOKEN
  */
 public function __construct($token)
 {
     Think\Log::record('开始接受微信请求:');
     if ($token) {
         self::auth($token) || exit;
         if (IS_GET) {
             exit($_GET['echostr']);
         } else {
             $xml = file_get_contents("php://input");
             Think\Log::record($xml);
             $xml = new \SimpleXMLElement($xml);
             $xml || exit;
             foreach ($xml as $key => $value) {
                 $this->data[$key] = strval($value);
             }
         }
     } else {
         throw new \Exception('参数错误!');
     }
 }
Esempio n. 28
0
 /**
  * 加载模板输出
  * @access protected
  * @param string $template 模板文件名
  * @param array  $vars     模板输出变量
  * @param array $replace     模板替换
  * @param array $config     模板参数
  * @return mixed
  */
 public function make($template = '', $vars = [], $replace = [], $config = [])
 {
     $view = $this->view;
     if ($this->theme) {
         $m = $this->request->module();
         $c = $this->request->controller();
         $a = $template ?: $this->request->action();
         $file = Config::get('template.view_path') . $m . DS . $c . DS . $a . '.' . Config::get('template.view_suffix');
         if (!is_file($file)) {
             Log::record("主题文件不存在" . $file, 'notice');
             $this->set_theme('');
             if (is_null(self::$view_instance)) {
                 self::$view_instance = new View(Config::get('template'), Config::get('view_replace_str'));
             }
             $view = self::$view_instance;
         } else {
             $template = $m . DS . $c . DS . $a;
         }
     }
     return $view->fetch($template, $vars, $replace, $config);
 }
Esempio n. 29
0
 /**
  * 渲染模板文件
  * @access public
  * @param string    $template 模板文件
  * @param array     $data 模板变量
  * @return void
  */
 public function fetch($template, $data = [])
 {
     if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
         // 获取模板文件名
         $template = $this->parseTemplate($template);
     }
     // 模板不存在 抛出异常
     if (!is_file($template)) {
         throw new TemplateNotFoundException('template not exists:' . $template, $template);
     }
     // 记录视图信息
     App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
     if (isset($data['template'])) {
         $__template__ = $template;
         extract($data, EXTR_OVERWRITE);
         include $__template__;
     } else {
         extract($data, EXTR_OVERWRITE);
         include $template;
     }
 }
Esempio n. 30
0
 public function getList()
 {
     $dirs = array_map('basename', glob(ADDON_PATH . '*', GLOB_ONLYDIR));
     if ($dirs === false || !file_exists(ADDON_PATH)) {
         $this->error = '插件目录不可读或者不存在';
         return array();
     }
     $addons = array();
     $list = $this->select();
     foreach ($list as &$info) {
         $info['uninstall'] = 0;
         $addons[$info['name']] = $info;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 $addons[$value]['status'] = null;
             }
         }
     }
     $result = array();
     $map = array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装'));
     foreach ($addons as $key => &$row) {
         if (!in_array($key, $dirs)) {
             $row['status'] = -1;
         }
         $row['status_text'] = $map['status'][$row['status']] ?: '-';
         array_push($result, $row);
     }
     return $result;
 }