连续复制
一键复制
一键打包
Http.php
<?php
namespace utils;
class Http{
/**
* 以get模拟网络请求
* @param string $url HTTP请求URL地址
* @param array $query GET请求参数
* @param array $options CURL参数
* @return bool|string
*/
public static function get($url, $query = [], $options = [])
{
$options['query'] = $query;
return self::request('get', $url, $options);
}
/**
* 以get模拟网络请求
* @param string $url HTTP请求URL地址
* @param array $data POST请求数据
* @param array $options CURL参数
* @return bool|string
*/
public static function post($url, $data = [], $options = [])
{
$options['data'] = $data;
return self::request('post', $url, $options);
}
/**
* CURL模拟网络请求
* @param string $method 请求方法
* @param string $url 请求方法
* @param array $options 请求参数[header,data,ssl_cer,ssl_key]
* @return bool|string
*/
public static function request($method, $url, $options = [])
{
$curl = curl_init();
// GET参数设置
if (!empty($options['query'])) {
$url .= stripos($url, '?') !== false ? '&' : '?' . http_build_query($options['query']);
}
// POST数据设置
if (strtolower($method) === 'post') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::build($options['data']));
}
// 请求超时设置
$options['timeout'] = isset($options['timeout']) ? $options['timeout'] : 60;
curl_setopt($curl, CURLOPT_TIMEOUT, $options['timeout']);
// CURL头信息设置
if (!empty($options['header'])) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $options['header']);
}
// 证书文件设置
if (!empty($options['ssl_cer']) && file_exists($options['ssl_cer'])) {
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLCERT, $options['ssl_cer']);
}
if (!empty($options['ssl_key']) && file_exists($options['ssl_key'])) {
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
return (intval($status["http_code"]) === 200) ? $content : false;
}
/**
* POST数据过滤处理
* @param array $data
* @param bool $needBuild
* @return array
*/
private static function build($data, $needBuild = true)
{
if (!is_array($data)) {
return $data;
}
foreach ($data as $key => $value) {
if (is_string($value) && class_exists('CURLFile', false) && stripos($value, '@') === 0) {
if (($filename = realpath(trim($value, '@'))) && file_exists($filename)) {
list($needBuild, $data[$key]) = [false, new \CURLFile($filename)];
}
}
}
return $needBuild ? http_build_query($data) : $data;
}
}
?>
Strs.php
<?php
namespace utils;
class Strs
{
/**
* 生成UUID 单机使用
* @access public
* @return string
*/
static public function uuid()
{
$charId = md5(uniqid(mt_rand(), true));
$hyphen = chr(45);
$uuid = chr(123)
. substr($charId, 0, 8) . $hyphen
. substr($charId, 8, 4) . $hyphen
. substr($charId, 12, 4) . $hyphen
. substr($charId, 16, 4) . $hyphen
. substr($charId, 20, 12)
. chr(125);
return $uuid;
}
/**
* 生成Guid主键
* @return Boolean
*/
static public function keyGen()
{
return str_replace('-', '', substr(self::uuid(), 1, -1));
}
/**
* 检查字符串是否是UTF8编码
* @param string $string 字符串
* @return Boolean
*/
static public function isUtf8($string)
{
$len = strlen($string);
for ($i = 0; $i < $len; $i++) {
$c = ord($string[$i]);
if ($c > 128) {
if (($c >= 254)) return false;
elseif ($c >= 252) $bits = 6;
elseif ($c >= 248) $bits = 5;
elseif ($c >= 240) $bits = 4;
elseif ($c >= 224) $bits = 3;
elseif ($c >= 192) $bits = 2;
else return false;
if (($i + $bits) > $len) return false;
while ($bits > 1) {
$i++;
$b = ord($string[$i]);
if ($b < 128 || $b > 191) return false;
$bits--;
}
}
}
return true;
}
/**
* 字符串截取,支持中文和其他编码
* @access public
* @param string $str 需要转换的字符串
* @param integer $start 开始位置
* @param string $length 截取长度
* @param string $charset 编码格式
* @param bool $suffix 截断显示字符
* @return string
*/
static public function mSubStr($str, $start = 0, $length, $charset = "utf-8", $suffix = true)
{
if (function_exists("mb_substr"))
$slice = mb_substr($str, $start, $length, $charset);
elseif (function_exists('iconv_substr')) {
$slice = iconv_substr($str, $start, $length, $charset);
} else {
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("", array_slice($match[0], $start, $length));
}
return $suffix ? $slice . '...' : $slice;
}
/**
* 产生随机字串,可用来自动生成密码
* 默认长度6位 字母和数字混合 支持中文
* @param integer $len 长度
* @param string $type 字串类型
* 0 字母 1 数字 2 大写字母 3 小写字母 4 中文 其它 混合
* @param string $addChars 额外字符
* @return string
*/
static public function randString($len = 6, $type = '', $addChars = '')
{
$str = '';
switch ($type) {
case 0:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 1:
$chars = str_repeat('0123456789', 3);
break;
case 2:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
break;
case 3:
$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 4:
$chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借" . $addChars;
break;
default :
// 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
break;
}
if ($len > 10) {//位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
}
if ($type != 4) {
$chars = str_shuffle($chars);
$str = substr($chars, 0, $len);
} else {
// 中文随机字
for ($i = 0; $i < $len; $i++) {
$str .= self::msubstr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1, 'utf-8', false);
}
}
return $str;
}
/**
* 生成一定数量的随机数,并且不重复
* @param integer $number 数量
* @param integer $length 长度
* @param integer $mode 字串类型
* 0 字母 1 数字 其它 混合
* @return string
*/
static public function buildCountRand($number, $length = 4, $mode = 1)
{
if ($mode == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字
return false;
}
$rand = [];
for ($i = 0; $i < $number; $i++) {
$rand[] = self::randString($length, $mode);
}
$unique = array_unique($rand);
if (count($unique) == count($rand)) {
return $rand;
}
$count = count($rand) - count($unique);
for ($i = 0; $i < $count * 3; $i++) {
$rand[] = self::randString($length, $mode);
}
$rand = array_slice(array_unique($rand), 0, $number);
return $rand;
}
/**
* 带格式生成随机字符 支持批量生成
* 但可能存在重复
* @param string $format 字符格式
* # 表示数字 * 表示字母和数字 $ 表示字母
* @param integer $number 生成数量
* @return string | array
*/
static public function buildFormatRand($format, $number = 1)
{
$str = [];
$length = strlen($format);
$strTemp = '';
for ($j = 0; $j < $number; $j++) {
$strTemp = '';
for ($i = 0; $i < $length; $i++) {
$char = substr($format, $i, 1);
switch ($char) {
case "*"://字母和数字混合
$strTemp .= self::randString(1);
break;
case "#"://数字
$strTemp .= self::randString(1, 1);
break;
case "$"://大写字母
$strTemp .= self::randString(1, 2);
break;
default://其他格式均不转换
$strTemp .= $char;
break;
}
}
$str[] = $strTemp;
}
return $number == 1 ? $strTemp : $str;
}
/**
* 获取一定范围内的随机数字 位数不足补零
* @param integer $min 最小值
* @param integer $max 最大值
* @return string
*/
static public function randNumber($min, $max)
{
return sprintf("%0" . strlen($max) . "d", mt_rand($min, $max));
}
// 自动转换字符集 支持数组转换
static public function autoCharset($string, $from = 'gbk', $to = 'utf-8')
{
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
//如果编码相同或者非字符串标量则不转换
return $string;
}
if (is_string($string)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($string, $to, $from);
} elseif (function_exists('iconv')) {
return iconv($from, $to, $string);
} else {
return $string;
}
} elseif (is_array($string)) {
foreach ($string as $key => $val) {
$_key = self::autoCharset($key, $from, $to);
$string[$_key] = self::autoCharset($val, $from, $to);
if ($key != $_key)
unset($string[$key]);
}
return $string;
} else {
return $string;
}
}
/**
* 加密字符串
* @param string $str 需要加密的字符串
* @return string
*/
static public function encrypt($str)
{
if (config('app_env') == 'local') {
//$seed = rand(0,9) + 2;
$seed = 2;
$len = strlen($str);
$result = '';
for ($i = 0; $i < $len; $i++) {
$o = ord(substr($str, $i, 1));
$b = $o ^ $seed << 2;
$result .= chr($b);
}
$result .= chr(($seed + 64) ^ 35);
return base64_encode($result);
} else {
if (empty($str))
return '';
return addslashes(my_encrypt($str));
}
}
/**
* 解密字符串
* @param string $str 需要解密的字符串
* @return string
*/
static public function decrypt($str)
{
if (config('app_env') == 'local') {
$str_d = base64_decode($str);
$seed = (ord(substr($str_d, -1)) - 64) ^ 35;
$len = strlen($str_d) - 1;
$result = '';
for ($i = 0; $i < $len; $i++) {
$o = ord(substr($str_d, $i, 1));
$b = $o ^ $seed << 2;
$result .= chr($b);
}
return $result;
} else {
if (empty($str))
return '';
return my_decrypt(stripslashes($str));
}
}
/**
* 模糊查询时加密字符串
* @param string $str 需要加密的字符串
* @return mixed
*/
static public function encryptByParam($str)
{
if (config('app_env') == 'local') {
$seed = 2;
$len = strlen($str);
$result = '';
for ($i = 0; $i < $len; $i++) {
$o = ord(substr($str, $i, 1));
$b = $o ^ $seed << 2;
$result .= chr($b);
}
$result .= chr(($seed + 64) ^ 35);
return base64_encode($result);
} else {
if (empty($str))
return '';
return addslashes(my_encrypt_param($str));
}
}
/**
* myencrypt
* 加解密函数
*
* @author jackie <jackie.zhao@mcake.com>
* @param string $str 需要加密/解密的字符串
* @param string $operation E 加密 D 解密
* @param string $skey 秘钥
* @return string
*/
static public function myEncrypt($string, $operation = 'E', $skey = 'mcake')
{
if ($operation == 'E') {
$strArr = str_split(base64_encode($string));
$strCount = count($strArr);
foreach (str_split($skey) as $key => $value)
$key < $strCount && $strArr[$key] .= $value;
return str_replace(['=', '+', '/'], ['O0O0O', 'o000o', 'oo00o'], join('', $strArr));
} else {
$strArr = str_split(str_replace(['O0O0O', 'o000o', 'oo00o'], ['=', '+', '/'], $string), 2);
$strCount = count($strArr);
foreach (str_split($skey) as $key => $value)
$key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
return base64_decode(join('', $strArr));
}
}
/**
* 将字符串拆分为数组
* @param string $str 字符串
* @param int $len 拆分长度
* @return array
*/
static public function mbStrSplit($str, $len = 1)
{
$array = [];
$start = 0;
$strlen = mb_strlen($str);
while ($strlen) {
$array[] = mb_substr($str, $start, $len, "utf8");
$str = mb_substr($str, $len, $strlen, "utf8");
$strlen = mb_strlen($str);
}
return $array;
}
/**
* 格式化金额
* @return string
*/
static function formatMoney($str)
{
$money = floatval(sprintf('%.2f', $str));
$count = 0;
$temp = explode('.', $money);
if (sizeof($temp) > 1) {
$decimal = end($temp);
$count = strlen($decimal);
}
$count = $count > 2 ? 2 : $count;
return sprintf('%.' . $count . 'f', $str);
}
}
?>
Jump.php
<?php
namespace utils;
trait Jump{
/**
* 操作成功跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : Container::get('url')->build($url);
}
$result = [
'code' => 1,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
$type = $this->getResponseType();
// 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_success_tmpl')]);
throw new HttpResponseException($response);
}
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$type = $this->getResponseType();
if (is_null($url)) {
$url = $this->app['request']->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app['url']->build($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
/**
* 返回封装后的API数据到客户端
* @access protected
* @param mixed $data 要返回的数据
* @param integer $code 返回的code
* @param mixed $msg 提示信息
* @param string $type 返回数据格式
* @param array $header 发送的Header信息
* @return void
*/
protected function result($data, $code = 0, $msg = '', $type = '', array $header = [])
{
$result = [
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data,
];
$type = $type ?: $this->getResponseType();
$response = Response::create($result, $type)->header($header);
throw new HttpResponseException($response);
}
}
?>
Tools.php
<?php
namespace utils;
class Tools
{
public static function getDate($timestamp)
{
$now = time();
$diff = $now - $timestamp;
if ($diff <= 60) {
return $diff . '秒前';
} elseif ($diff <= 3600) {
return floor($diff / 60) . '分钟前';
} elseif ($diff <= 86400) {
return floor($diff / 3600) . '小时前';
} elseif ($diff <= 2592000) {
return floor($diff / 86400) . '天前';
} else {
return '一个月前';
}
}
/**
* 二次封装的密码加密
* @param $str
* @param string $auth_key
* @return string
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public static function userMd5($str, $auth_key = '')
{
if (!$auth_key) {
$auth_key = config('apiAdmin.AUTH_KEY');
}
return '' === $str ? '' : md5(sha1($str) . $auth_key);
}
/**
* 判断当前用户是否是超级管理员
* @param string $uid
* @return bool
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public static function isAdministrator($uid = '')
{
if (!empty($uid)) {
$adminConf = config('apiAdmin.USER_ADMINISTRATOR');
if (is_array($adminConf)) {
if (is_array($uid)) {
$m = array_intersect($adminConf, $uid);
if (count($m)) {
return true;
}
} else {
if (in_array($uid, $adminConf)) {
return true;
}
}
} else {
if (is_array($uid)) {
if (in_array($adminConf, $uid)) {
return true;
}
} else {
if ($uid == $adminConf) {
return true;
}
}
}
}
return false;
}
/**
* 将查询的二维对象转换成二维数组
* @param array $res
* @param string $key 允许指定索引值
* @return array
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public static function buildArrFromObj($res, $key = '')
{
$arr = [];
foreach ($res as $value) {
$value = $value->toArray();
if ($key) {
$arr[$value[$key]] = $value;
} else {
$arr[] = $value;
}
}
return $arr;
}
/**
* 将二维数组变成指定key
* @param $array
* @param $keyName
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
*/
public static function buildArrByNewKey($array, $keyName = 'id')
{
$list = array();
foreach ($array as $item) {
$list[$item[$keyName]] = $item;
}
return $list;
}
public function toCSV(array $data, array $colHeaders = array(), $asString = false)
{
$stream = ($asString)
? fopen("php://temp/maxmemory", "w+")
: fopen("php://output", "w");
if (!empty($colHeaders)) {
fputcsv($stream, $colHeaders);
}
foreach ($data as $record) {
fputcsv($stream, $record);
}
if ($asString) {
rewind($stream);
$returnVal = stream_get_contents($stream);
fclose($stream);
return $returnVal;
} else {
fclose($stream);
}
}
/**
* 合并图片
* @param string $backgroundImage 背景图
* @param string $smallImage 小图
* @param int $smallX 小图相对于背景图x轴位移
* @param int $smallY 小图相对于背景图Y轴位移
* @param string $output_path 输出图片的路径
* @param string $output_filename 输出图片的名字
*/
public function bindImages($backgroundImage = '', $smallImage = '', $smallX = 0, $smallY = 0, $output_path = '', $output_filename = ''){
//创建源图的实例
$src = imagecreatefromstring(file_get_contents($backgroundImage));
//创建点的实例
$des = imagecreatefrompng($smallImage);
//获取点图片的宽高
list($point_w, $point_h) = getimagesize($smallImage);
//重点:png透明用这个函数
imagecopy($src, $des, $smallX, $smallY, 0, 0, $point_w, $point_h);
header('Content-Type: image/jpeg');
imagejpeg($src,$output_path.$output_filename);
}
}
Email.php
<?php
namespace utils;
use think\Config;
class Email
{
/**
* 单例对象
*/
protected static $instance;
/**
* phpmailer对象
*/
protected $mail = [];
/**
* 错误内容
*/
protected $_error = '';
/**
* 默认配置
*/
public $options = [
'charset' => 'utf-8', //编码格式
'debug' => 0, //调式模式
'mail_type' => '1',
'mail_smtp_host' => 'smtp.qq.com',
'mail_smtp_port' => '465',
'mail_smtp_user' => '10000',
'mail_smtp_pass' => 'password',
'mail_verify_type' => '2',
'mail_from' => '10000@qq.com',
];
/**
* 初始化
* @access public
* @param array $options 参数
* @return Email
*/
public static function instance($options = [])
{
if (is_null(self::$instance))
{
self::$instance = new static($options);
}
return self::$instance;
}
/**
* 构造函数
* @param array $options
*/
public function __construct($options = [])
{
if ($config = Config::get('shop.email'))
{
$this->options = array_merge($this->options, $config);
}
$this->options = array_merge($this->options, $options);
vendor('phpmailer.phpmailer.PHPMailerAutoload');
$securArr = [1 => 'tls', 2 => 'ssl'];
$this->mail = new \PHPMailer(true);
$this->mail->CharSet = $this->options['charset'];
$this->mail->SMTPDebug = $this->options['debug'];
$this->mail->isSMTP();
$this->mail->SMTPAuth = true;
$this->mail->Host = $this->options['mail_smtp_host'];
$this->mail->Username = $this->options['mail_smtp_user'];
$this->mail->Password = $this->options['mail_smtp_pass'];
$this->mail->SMTPSecure = isset($securArr[$this->options['mail_verify_type']]) ? $securArr[$this->options['mail_verify_type']] : '';
$this->mail->Port = $this->options['mail_smtp_port'];
//设置发件人
$this->from($this->options['mail_from']);
}
/**
* 设置邮件主题
* @param string $subject
* @return $this
*/
public function subject($subject)
{
$this->options['subject'] = $subject;
return $this;
}
/**
* 设置发件人
* @param string $email
* @param string $name
* @return $this
*/
public function from($email, $name = '')
{
$this->options['from'] = $email;
$this->options['from_name'] = $name;
return $this;
}
/**
* 设置收件人
* @param string $email
* @param string $name
* @return $this
*/
public function to($email, $name = '')
{
$this->options['to'] = $email;
$this->options['to_name'] = $name;
return $this;
}
/**
* 设置邮件正文
* @param string $body
* @param boolean $ishtml
* @return $this
*/
public function message($body, $ishtml = true)
{
$this->options['body'] = $body;
$this->options['ishtml'] = $ishtml;
return $this;
}
/**
* 获取最后产生的错误
* @return string
*/
public function getError()
{
return $this->_error;
}
/**
* 设置错误
* @param string $error 信息信息
*/
protected function setError($error)
{
$this->_error = $error;
}
/**
* 发送邮件
* @return boolean
*/
public function send()
{
$result = false;
switch ($this->options['mail_type'])
{
case 1:
//使用phpmailer发送
$this->mail->setFrom($this->options['from'], $this->options['from_name']);
$this->mail->addAddress($this->options['to'], $this->options['to_name']);
$this->mail->Subject = $this->options['subject'];
if ($this->options['ishtml'])
{
$this->mail->msgHTML($this->options['body']);
}
else
{
$this->mail->Body = $this->options['body'];
}
try
{
$result = $this->mail->send();
}
catch (\phpmailerException $e)
{
$this->setError($e->getMessage());
}
$this->setError($result ? '' : $this->mail->ErrorInfo);
break;
case 2:
//使用mail方法发送邮件
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=" . $this->options['charset'] . "\r\n";
$headers .= "To: {$this->options['to_name']} <{$this->options['to']}>\r\n"; //收件人
$headers .= "From: {$this->options['from_name']} <{$this->options['from']}>\r\n"; //发件人
$result = mail($this->options['to'], $this->options['subject'], $this->options['body'], $headers);
$this->setError($result ? '' : error_get_last()['message']);
break;
default:
//邮件功能已关闭
$this->setError(__('Mail already closed'));
break;
}
return $result;
}
}
Pinyin.php
<?php
namespace utils;
/**
* 中文转拼音类
*/
class Pinyin
{
protected static $keys = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
protected static $values = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274|-10270|-10262|-10260|-10256|-10254";
/**
* 获取文字的拼音
* @param string $chinese 中文汉字
* @param boolean $onlyfirst 是否只返回拼音首字母
* @param string $delimiter 分隔符
* @param string $charset 文字编码
* @return string
*/
public static function get($chinese, $onlyfirst = false, $delimiter = '', $ucfirst = false, $charset = 'utf-8')
{
$keys_a = explode('|', self::$keys);
$values_a = explode('|', self::$values);
$data = array_combine($keys_a, $values_a);
arsort($data);
reset($data);
if ($charset != 'gb2312')
$chinese = self::_u2_utf8_gb($chinese);
$result = '';
for ($i = 0; $i < strlen($chinese); $i++)
{
$_P = ord(substr($chinese, $i, 1));
if ($_P > 160)
{
$_Q = ord(substr($chinese, ++$i, 1));
$_P = $_P * 256 + $_Q - 65536;
}
$result .= ($onlyfirst ? substr(self::_pinyin($_P, $data), 0, 1) : self::_pinyin($_P, $data));
$result .= $delimiter;
}
if ($delimiter)
{
$result = rtrim($result, $delimiter);
}
return preg_replace("/[^a-z0-9_\-]*/i", '', $result);
}
private static function _pinyin($num, $data)
{
if ($num > 0 && $num < 160)
return chr($num);
elseif ($num < -20319 || $num > -10247)
return '';
else
{
foreach ($data as $k => $v)
{
if ($v <= $num)
break;
}
return $k;
}
}
private static function _u2_utf8_gb($c)
{
$string = '';
if ($c < 0x80)
$string .= $c;
elseif ($c < 0x800)
{
$string .= chr(0xC0 | $c >> 6);
$string .= chr(0x80 | $c & 0x3F);
}
elseif ($c < 0x10000)
{
$string .= chr(0xE0 | $c >> 12);
$string .= chr(0x80 | $c >> 6 & 0x3F);
$string .= chr(0x80 | $c & 0x3F);
}
elseif ($c < 0x200000)
{
$string .= chr(0xF0 | $c >> 18);
$string .= chr(0x80 | $c >> 12 & 0x3F);
$string .= chr(0x80 | $c >> 6 & 0x3F);
$string .= chr(0x80 | $c & 0x3F);
}
return iconv('UTF-8', 'GB2312//IGNORE', $string);
}
}
Tree.php
<?php
namespace utils;
use think\Config;
/**
* 通用的树型类
* @author XiaoYao <476552238li@gmail.com>
*/
class Tree
{
protected static $instance;
//默认配置
protected $config = [];
public $options = [];
/**
* 生成树型结构所需要的2维数组
* @var array
*/
public $arr = [];
/**
* 生成树型结构所需修饰符号,可以换成图片
* @var array
*/
public $icon = array('│', '├', '└');
public $nbsp = " ";
public $pidname = 'pid';
public function __construct($options = [])
{
if ($config = Config::get('tree'))
{
$this->options = array_merge($this->config, $config);
}
$this->options = array_merge($this->config, $options);
}
/**
* 初始化
* @access public
* @param array $options 参数
* @return Tree
*/
public static function instance($options = [])
{
if (is_null(self::$instance))
{
self::$instance = new static($options);
}
return self::$instance;
}
/**
* 初始化方法
* @param array 2维数组,例如:
* array(
* 1 => array('id'=>'1','pid'=>0,'name'=>'一级栏目一'),
* 2 => array('id'=>'2','pid'=>0,'name'=>'一级栏目二'),
* 3 => array('id'=>'3','pid'=>1,'name'=>'二级栏目一'),
* 4 => array('id'=>'4','pid'=>1,'name'=>'二级栏目二'),
* 5 => array('id'=>'5','pid'=>2,'name'=>'二级栏目三'),
* 6 => array('id'=>'6','pid'=>3,'name'=>'三级栏目一'),
* 7 => array('id'=>'7','pid'=>3,'name'=>'三级栏目二')
* )
*/
public function init($arr = [], $pidname = NULL, $nbsp = NULL)
{
$this->arr = $arr;
if (!is_null($pidname))
$this->pidname = $pidname;
if (!is_null($nbsp))
$this->nbsp = $nbsp;
return $this;
}
/**
* 得到子级数组
* @param int
* @return array
*/
public function getChild($myid)
{
$newarr = [];
foreach ($this->arr as $value)
{
if (!isset($value['id']))
continue;
if ($value[$this->pidname] == $myid)
$newarr[$value['id']] = $value;
}
return $newarr;
}
/**
* 读取指定节点的所有孩子节点
* @param int $myid 节点ID
* @param boolean $withself 是否包含自身
* @return array
*/
public function getChildren($myid, $withself = FALSE)
{
$newarr = [];
foreach ($this->arr as $value)
{
if (!isset($value['id']))
continue;
if ($value[$this->pidname] == $myid)
{
$newarr[] = $value;
$newarr = array_merge($newarr, $this->getChildren($value['id']));
}
else if ($withself && $value['id'] == $myid)
{
$newarr[] = $value;
}
}
return $newarr;
}
/**
* 读取指定节点的所有孩子节点ID
* @param int $myid 节点ID
* @param boolean $withself 是否包含自身
* @return array
*/
public function getChildrenIds($myid, $withself = FALSE)
{
$childrenlist = $this->getChildren($myid, $withself);
$childrenids = [];
foreach ($childrenlist as $k => $v)
{
$childrenids[] = $v['id'];
}
return $childrenids;
}
/**
* 得到当前位置父辈数组
* @param int
* @return array
*/
public function getParent($myid)
{
$pid = 0;
$newarr = [];
foreach ($this->arr as $value)
{
if (!isset($value['id']))
continue;
if ($value['id'] == $myid)
{
$pid = $value[$this->pidname];
break;
}
}
if ($pid)
{
foreach ($this->arr as $value)
{
if ($value['id'] == $pid)
{
$newarr[] = $value;
break;
}
}
}
return $newarr;
}
/**
* 得到当前位置所有父辈数组
* @param int
* @return array
*/
public function getParents($myid, $withself = FALSE)
{
$pid = 0;
$newarr = [];
foreach ($this->arr as $value)
{
if (!isset($value['id']))
continue;
if ($value['id'] == $myid)
{
if ($withself)
{
$newarr[] = $value;
}
$pid = $value[$this->pidname];
break;
}
}
if ($pid)
{
$arr = $this->getParents($pid, TRUE);
$newarr = array_merge($arr, $newarr);
}
return $newarr;
}
/**
* 读取指定节点所有父类节点ID
* @param int $myid
* @param boolean $withself
* @return array
*/
public function getParentsIds($myid, $withself = FALSE)
{
$parentlist = $this->getParents($myid, $withself);
$parentsids = [];
foreach ($parentlist as $k => $v)
{
$parentsids[] = $v['id'];
}
return $parentsids;
}
/**
* 树型结构Option
* @param int $myid 表示获得这个ID下的所有子级
* @param string $itemtpl 条目模板 如:"<option value=@id @selected @disabled>@spacer@name</option>"
* @param mixed $selectedids 被选中的ID,比如在做树型下拉框的时候需要用到
* @param mixed $disabledids 被禁用的ID,比如在做树型下拉框的时候需要用到
* @param string $itemprefix 每一项前缀
* @param string $toptpl 顶级栏目的模板
* @return string
*/
public function getTree($myid, $itemtpl = "<option value=@id @selected @disabled>@spacer@name</option>", $selectedids = '', $disabledids = '', $itemprefix = '', $toptpl = '')
{
$ret = '';
$number = 1;
$childs = $this->getChild($myid);
if ($childs)
{
$total = count($childs);
foreach ($childs as $value)
{
$id = $value['id'];
$j = $k = '';
if ($number == $total)
{
$j .= $this->icon[2];
$k = $itemprefix ? $this->nbsp : '';
}
else
{
$j .= $this->icon[1];
$k = $itemprefix ? $this->icon[0] : '';
}
$spacer = $itemprefix ? $itemprefix . $j : '';
$selected = $selectedids && in_array($id, (is_array($selectedids) ? $selectedids : explode(',', $selectedids))) ? 'selected' : '';
$disabled = $disabledids && in_array($id, (is_array($disabledids) ? $disabledids : explode(',', $disabledids))) ? 'disabled' : '';
$value = array_merge($value, array('selected' => $selected, 'disabled' => $disabled, 'spacer' => $spacer));
$value = array_combine(array_map(function($k) {
return '@' . $k;
}, array_keys($value)), $value);
$nstr = strtr((($value["@{$this->pidname}"] == 0 || $this->getChild($id) ) && $toptpl ? $toptpl : $itemtpl), $value);
$ret .= $nstr;
$ret .= $this->getTree($id, $itemtpl, $selectedids, $disabledids, $itemprefix . $k . $this->nbsp, $toptpl);
$number++;
}
}
return $ret;
}
/**
* 树型结构UL
* @param int $myid 表示获得这个ID下的所有子级
* @param string $itemtpl 条目模板 如:"<li value=@id @selected @disabled>@name @childlist</li>"
* @param string $selectedids 选中的ID
* @param string $disabledids 禁用的ID
* @param string $wraptag 子列表包裹标签
* @return string
*/
public function getTreeUl($myid, $itemtpl, $selectedids = '', $disabledids = '', $wraptag = 'ul', $wrapattr = '')
{
$str = '';
$childs = $this->getChild($myid);
if ($childs)
{
foreach ($childs as $value)
{
$id = $value['id'];
unset($value['child']);
$selected = $selectedids && in_array($id, (is_array($selectedids) ? $selectedids : explode(',', $selectedids))) ? 'selected' : '';
$disabled = $disabledids && in_array($id, (is_array($disabledids) ? $disabledids : explode(',', $disabledids))) ? 'disabled' : '';
$value = array_merge($value, array('selected' => $selected, 'disabled' => $disabled));
$value = array_combine(array_map(function($k) {
return '@' . $k;
}, array_keys($value)), $value);
$nstr = strtr($itemtpl, $value);
$childdata = $this->getTreeUl($id, $itemtpl, $selectedids, $disabledids, $wraptag, $wrapattr);
$childlist = $childdata ? "<{$wraptag} {$wrapattr}>" . $childdata . "</{$wraptag}>" : "";
$str .= strtr($nstr, array('@childlist' => $childlist));
}
}
return $str;
}
/**
* 菜单数据
* @param int $myid
* @param string $itemtpl
* @param mixed $selectedids
* @param mixed $disabledids
* @param string $wraptag
* @param string $wrapattr
* @param int $deeplevel
* @return string
*/
public function getTreeMenu($myid, $itemtpl, $selectedids = '', $disabledids = '', $wraptag = 'ul', $wrapattr = '', $deeplevel = 0)
{
$str = '';
$childs = $this->getChild($myid);
if ($childs)
{
foreach ($childs as $value)
{
$id = $value['id'];
unset($value['child']);
$selected = in_array($id, (is_array($selectedids) ? $selectedids : explode(',', $selectedids))) ? 'selected' : '';
$disabled = in_array($id, (is_array($disabledids) ? $disabledids : explode(',', $disabledids))) ? 'disabled' : '';
$value = array_merge($value, array('selected' => $selected, 'disabled' => $disabled));
$value = array_combine(array_map(function($k) {
return '@' . $k;
}, array_keys($value)), $value);
$bakvalue = array_intersect_key($value, array_flip(['@url', '@caret', '@class']));
$value = array_diff_key($value, $bakvalue);
$nstr = strtr($itemtpl, $value);
$value = array_merge($value, $bakvalue);
$childdata = $this->getTreeMenu($id, $itemtpl, $selectedids, $disabledids, $wraptag, $wrapattr, $deeplevel + 1);
$childlist = $childdata ? "<{$wraptag} {$wrapattr}>" . $childdata . "</{$wraptag}>" : "";
$childlist = strtr($childlist, array('@class' => $childdata ? 'last' : ''));
$value = array(
'@childlist' => $childlist,
'@url' => $childdata || !isset($value['@url']) ? "javascript:;" : url($value['@url']),
'@addtabs' => $childdata || !isset($value['@url']) ? "" : (stripos($value['@url'], "?") !== false ? "&" : "?") . "ref=addtabs",
'@caret' => ($childdata && (!isset($value['@badge']) || !$value['@badge']) ? '<i class="fa fa-angle-left"></i>' : ''),
'@badge' => isset($value['@badge']) ? $value['@badge'] : '',
'@class' => ($selected ? ' active' : '') . ($disabled ? ' disabled' : '') . ($childdata ? ' treeview' : ''),
);
$str .= strtr($nstr, $value);
}
}
return $str;
}
/**
* 特殊
* @param integer $myid 要查询的ID
* @param string $itemtpl1 第一种HTML代码方式
* @param string $itemtpl2 第二种HTML代码方式
* @param mixed $selectedids 默认选中
* @param mixed $disabledids 禁用
* @param integer $itemprefix 前缀
*/
public function getTreeSpecial($myid, $itemtpl1, $itemtpl2, $selectedids = 0, $disabledids = 0, $itemprefix = '')
{
$ret = '';
$number = 1;
$childs = $this->getChild($myid);
if ($childs)
{
$total = count($childs);
foreach ($childs as $id => $value)
{
$j = $k = '';
if ($number == $total)
{
$j .= $this->icon[2];
$k = $itemprefix ? $this->nbsp : '';
}
else
{
$j .= $this->icon[1];
$k = $itemprefix ? $this->icon[0] : '';
}
$spacer = $itemprefix ? $itemprefix . $j : '';
$selected = $selectedids && in_array($id, (is_array($selectedids) ? $selectedids : explode(',', $selectedids))) ? 'selected' : '';
$disabled = $disabledids && in_array($id, (is_array($disabledids) ? $disabledids : explode(',', $disabledids))) ? 'disabled' : '';
$value = array_merge($value, array('selected' => $selected, 'disabled' => $disabled, 'spacer' => $spacer));
$value = array_combine(array_map(function($k) {
return '@' . $k;
}, array_keys($value)), $value);
$nstr = strtr(!isset($value['@disabled']) || !$value['@disabled'] ? $itemtpl1 : $itemtpl2, $value);
$ret .= $nstr;
$ret .= $this->getTreeSpecial($id, $itemtpl1, $itemtpl2, $selectedids, $disabledids, $itemprefix . $k . $this->nbsp);
$number++;
}
}
return $ret;
}
/**
*
* 获取树状数组
* @param string $myid 要查询的ID
* @param string $nametpl 名称条目模板
* @param string $itemprefix 前缀
* @return string
*/
public function getTreeArray($myid, $itemprefix = '')
{
$childs = $this->getChild($myid);
$n = 0;
$data = [];
$number = 1;
if ($childs)
{
$total = count($childs);
foreach ($childs as $id => $value)
{
$j = $k = '';
if ($number == $total)
{
$j .= $this->icon[2];
$k = $itemprefix ? $this->nbsp : '';
}
else
{
$j .= $this->icon[1];
$k = $itemprefix ? $this->icon[0] : '';
}
$spacer = $itemprefix ? $itemprefix . $j : '';
$value['spacer'] = $spacer;
$data[$n] = $value;
$data[$n]['childlist'] = $this->getTreeArray($id, $itemprefix . $k . $this->nbsp);
$n++;
$number++;
}
}
return $data;
}
/**
* 将getTreeArray的结果返回为二维数组
* @param array $data
* @return array
*/
public function getTreeList($data = [], $field = 'name')
{
$arr = [];
foreach ($data as $k => $v)
{
$childlist = isset($v['childlist']) ? $v['childlist'] : [];
unset($v['childlist']);
$v[$field] = $v['spacer'] . ' ' . $v[$field];
$v['haschild'] = $childlist ? 1 : 0;
if ($v['id'])
$arr[] = $v;
if ($childlist)
{
$arr = array_merge($arr, $this->getTreeList($childlist, $field));
}
}
return $arr;
}
}
Rsa.php
<?php
namespace utils;
/**
* RSA签名类
*/
class Rsa
{
public $publicKey = '';
public $privateKey = '';
private $_privKey;
/**
* * private key
*/
private $_pubKey;
/**
* * public key
*/
private $_keyPath;
/**
* * the keys saving path
*/
/**
* * the construtor,the param $path is the keys saving path
*/
function __construct($publicKey = null, $privateKey = null)
{
$this->setKey($publicKey, $privateKey);
}
/**
* 设置公钥和私钥
* @param string $publicKey 公钥
* @param string $privateKey 私钥
*/
public function setKey($publicKey = null, $privateKey = null)
{
if (!is_null($publicKey))
$this->publicKey = $publicKey;
if (!is_null($privateKey))
$this->privateKey = $privateKey;
}
/**
* * setup the private key
*/
private function setupPrivKey()
{
if (is_resource($this->_privKey))
{
return true;
}
$pem = chunk_split($this->privateKey, 64, "\n");
$pem = "-----BEGIN PRIVATE KEY-----\n" . $pem . "-----END PRIVATE KEY-----\n";
$this->_privKey = openssl_pkey_get_private($pem);
return true;
}
/**
* * setup the public key
*/
private function setupPubKey()
{
if (is_resource($this->_pubKey))
{
return true;
}
$pem = chunk_split($this->publicKey, 64, "\n");
$pem = "-----BEGIN PUBLIC KEY-----\n" . $pem . "-----END PUBLIC KEY-----\n";
$this->_pubKey = openssl_pkey_get_public($pem);
return true;
}
/**
* * encrypt with the private key
*/
public function privEncrypt($data)
{
if (!is_string($data))
{
return null;
}
$this->setupPrivKey();
$r = openssl_private_encrypt($data, $encrypted, $this->_privKey);
if ($r)
{
return base64_encode($encrypted);
}
return null;
}
/**
* * decrypt with the private key
*/
public function privDecrypt($encrypted)
{
if (!is_string($encrypted))
{
return null;
}
$this->setupPrivKey();
$encrypted = base64_decode($encrypted);
$r = openssl_private_decrypt($encrypted, $decrypted, $this->_privKey);
if ($r)
{
return $decrypted;
}
return null;
}
/**
* * encrypt with public key
*/
public function pubEncrypt($data)
{
if (!is_string($data))
{
return null;
}
$this->setupPubKey();
$r = openssl_public_encrypt($data, $encrypted, $this->_pubKey);
if ($r)
{
return base64_encode($encrypted);
}
return null;
}
/**
* * decrypt with the public key
*/
public function pubDecrypt($crypted)
{
if (!is_string($crypted))
{
return null;
}
$this->setupPubKey();
$crypted = base64_decode($crypted);
$r = openssl_public_decrypt($crypted, $decrypted, $this->_pubKey);
if ($r)
{
return $decrypted;
}
return null;
}
/**
* 构造签名
* @param string $dataString 被签名数据
* @return string
*/
public function sign($dataString)
{
$this->setupPrivKey();
$signature = false;
openssl_sign($dataString, $signature, $this->_privKey);
return base64_encode($signature);
}
/**
* 验证签名
* @param string $dataString 被签名数据
* @param string $signString 已经签名的字符串
* @return number 1签名正确 0签名错误
*/
public function verify($dataString, $signString)
{
$this->setupPubKey();
$signature = base64_decode($signString);
$flg = openssl_verify($dataString, $signature, $this->_pubKey);
return $flg;
}
public function __destruct()
{
is_resource($this->_privKey) && @openssl_free_key($this->_privKey);
is_resource($this->_pubKey) && @openssl_free_key($this->_pubKey);
}
}
Auth.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: luofei614 <weibo.com/luofei614>
// +----------------------------------------------------------------------
// | 修改者: anuo (本权限类在原3.2.3的基础上修改过来的)
// +----------------------------------------------------------------------
namespace utils;
use think\Db;
use think\Config;
use think\Session;
use think\Request;
/**
* 权限认证类
* 功能特性:
* 1,是对规则进行认证,不是对节点进行认证。用户可以把节点当作规则名称实现对节点进行认证。
* $auth=new Auth(); $auth->check('规则名称','用户id')
* 2,可以同时对多条规则进行认证,并设置多条规则的关系(or或者and)
* $auth=new Auth(); $auth->check('规则1,规则2','用户id','and')
* 第三个参数为and时表示,用户需要同时具有规则1和规则2的权限。 当第三个参数为or时,表示用户值需要具备其中一个条件即可。默认为or
* 3,一个用户可以属于多个用户组(think_auth_group_access表 定义了用户所属用户组)。我们需要设置每个用户组拥有哪些规则(think_auth_group 定义了用户组权限)
* 4,支持规则表达式。
* 在think_auth_rule 表中定义一条规则,condition字段就可以定义规则表达式。 如定义{score}>5 and {score}<100
* 表示用户的分数在5-100之间时这条规则才会通过。
*/
class Auth
{
/**
* @var object 对象实例
*/
protected static $instance;
protected $rules = [];
/**
* 当前请求实例
* @var Request
*/
protected $request;
//默认配置
protected $config = [
'auth_on' => 1, // 权限开关
'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。
'auth_group' => 'auth_group', // 用户组数据表名
'auth_group_access' => 'auth_group_access', // 用户-用户组关系表
'auth_rule' => 'auth_rule', // 权限规则表
'auth_user' => 'user', // 用户信息表
];
/**
* 类架构函数
* Auth constructor.
*/
public function __construct()
{
if ($auth = Config::get('auth'))
{
$this->config = array_merge($this->config, $auth);
}
// 初始化request
$this->request = Request::instance();
}
/**
* 初始化
* @access public
* @param array $options 参数
* @return Auth
*/
public static function instance($options = [])
{
if (is_null(self::$instance))
{
self::$instance = new static($options);
}
return self::$instance;
}
/**
* 检查权限
* @param $name string|array 需要验证的规则列表,支持逗号分隔的权限规则或索引数组
* @param $uid int 认证用户的id
* @param string $relation 如果为 'or' 表示满足任一条规则即通过验证;如果为 'and'则表示需满足所有规则才能通过验证
* @param string $mode 执行验证的模式,可分为url,normal
* @return bool 通过验证返回true;失败返回false
*/
public function check($name, $uid, $relation = 'or', $mode = 'url')
{
if (!$this->config['auth_on'])
{
return true;
}
// 获取用户需要验证的所有有效规则列表
$rulelist = $this->getRuleList($uid);
if (in_array('*', $rulelist))
return true;
if (is_string($name))
{
$name = strtolower($name);
if (strpos($name, ',') !== false)
{
$name = explode(',', $name);
}
else
{
$name = [$name];
}
}
$list = []; //保存验证通过的规则名
if ('url' == $mode)
{
$REQUEST = unserialize(strtolower(serialize($this->request->param())));
}
foreach ($rulelist as $rule)
{
$query = preg_replace('/^.+\?/U', '', $rule);
if ('url' == $mode && $query != $rule)
{
parse_str($query, $param); //解析规则中的param
$intersect = array_intersect_assoc($REQUEST, $param);
$rule = preg_replace('/\?.*$/U', '', $rule);
if (in_array($rule, $name) && $intersect == $param)
{
//如果节点相符且url参数满足
$list[] = $rule;
}
}
else
{
if (in_array($rule, $name))
{
$list[] = $rule;
}
}
}
if ('or' == $relation && !empty($list))
{
return true;
}
$diff = array_diff($name, $list);
if ('and' == $relation && empty($diff))
{
return true;
}
return false;
}
/**
* 根据用户id获取用户组,返回值为数组
* @param $uid int 用户id
* @return array 用户所属的用户组 array(
* array('uid'=>'用户id','group_id'=>'用户组id','name'=>'用户组名称','rules'=>'用户组拥有的规则id,多个,号隔开'),
* ...)
*/
public function getGroups($uid)
{
static $groups = [];
if (isset($groups[$uid]))
{
return $groups[$uid];
}
// 执行查询
$user_groups = Db::name($this->config['auth_group_access'])
->alias('aga')
->join('__' . strtoupper($this->config['auth_group']) . '__ ag', 'aga.group_id = ag.id', 'LEFT')
->field('aga.uid,aga.group_id,ag.id,ag.pid,ag.name,ag.rules')
->where("aga.uid='{$uid}' and ag.status='normal'")
->select();
$groups[$uid] = $user_groups ?: [];
return $groups[$uid];
}
/**
* 获得权限规则列表
* @param integer $uid 用户id
* @return array
*/
public function getRuleList($uid)
{
static $_rulelist = []; //保存用户验证通过的权限列表
if (isset($_rulelist[$uid]))
{
return $_rulelist[$uid];
}
if (2 == $this->config['auth_type'] && Session::has('_rule_list_' . $uid))
{
return Session::get('_rule_list_' . $uid);
}
// 读取用户规则节点
$ids = $this->getRuleIds($uid);
if (empty($ids))
{
$_rulelist[$uid] = [];
return [];
}
// 筛选条件
$where = [
'status' => 'normal'
];
if (!in_array('*', $ids))
{
$where['id'] = ['in', $ids];
}
//读取用户组所有权限规则
$this->rules = Db::name($this->config['auth_rule'])->where($where)->field('id,pid,condition,icon,name,title,ismenu')->select();
//循环规则,判断结果。
$rulelist = []; //
if (in_array('*', $ids))
{
$rulelist[] = "*";
}
foreach ($this->rules as $rule)
{
//超级管理员无需验证condition
if (!empty($rule['condition']) && !in_array('*', $ids))
{
//根据condition进行验证
$user = $this->getUserInfo($uid); //获取用户信息,一维数组
$command = preg_replace('/\{(\w*?)\}/', '$user[\'\\1\']', $rule['condition']);
@(eval('$condition=(' . $command . ');'));
if ($condition)
{
$rulelist[$rule['id']] = strtolower($rule['name']);
}
}
else
{
//只要存在就记录
$rulelist[$rule['id']] = strtolower($rule['name']);
}
}
$_rulelist[$uid] = $rulelist;
//登录验证则需要保存规则列表
if (2 == $this->config['auth_type'])
{
//规则列表结果保存到session
Session::set('_rule_list_' . $uid, $rulelist);
}
return array_unique($rulelist);
}
public function getRuleIds($uid)
{
//读取用户所属用户组
$groups = $this->getGroups($uid);
$ids = []; //保存用户所属用户组设置的所有权限规则id
foreach ($groups as $g)
{
$ids = array_merge($ids, explode(',', trim($g['rules'], ',')));
}
$ids = array_unique($ids);
return $ids;
}
/**
* 获得用户资料
* @param $uid
* @return mixed
*/
protected function getUserInfo($uid)
{
static $user_info = [];
$user = Db::name($this->config['auth_user']);
// 获取用户表主键
$_pk = is_string($user->getPk()) ? $user->getPk() : 'uid';
if (!isset($user_info[$uid]))
{
$user_info[$uid] = $user->where($_pk, $uid)->find();
}
return $user_info[$uid];
}
}
数据库表
-- ----------------------------
-- Table structure for fa_auth_group
-- ----------------------------
DROP TABLE IF EXISTS `fa_auth_group`;
CREATE TABLE `fa_auth_group` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父组别',
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '组名',
`rules` text NOT NULL COMMENT '规则ID',
`createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='分组表';
-- ----------------------------
-- Records of fa_auth_group
-- ----------------------------
BEGIN;
INSERT INTO `fa_auth_group` VALUES (1, 0, 'Admin group', '*', 1490883540, 149088354, 'normal');
INSERT INTO `fa_auth_group` VALUES (2, 1, 'Second group', '13,14,16,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,1,9,10,11,7,6,8,2,4,5', 1490883540, 1505465692, 'normal');
INSERT INTO `fa_auth_group` VALUES (3, 2, 'Third group', '1,4,9,10,11,13,14,15,16,17,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,5', 1490883540, 1502205322, 'normal');
INSERT INTO `fa_auth_group` VALUES (4, 1, 'Second group 2', '1,4,13,14,15,16,17,55,56,57,58,59,60,61,62,63,64,65', 1490883540, 1502205350, 'normal');
INSERT INTO `fa_auth_group` VALUES (5, 2, 'Third group 2', '1,2,6,7,8,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34', 1490883540, 1502205344, 'normal');
COMMIT;
-- ----------------------------
-- Table structure for fa_auth_group_access
-- ----------------------------
DROP TABLE IF EXISTS `fa_auth_group_access`;
CREATE TABLE `fa_auth_group_access` (
`uid` int(10) unsigned NOT NULL COMMENT '会员ID',
`group_id` int(10) unsigned NOT NULL COMMENT '级别ID',
UNIQUE KEY `uid_group_id` (`uid`,`group_id`),
KEY `uid` (`uid`),
KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='权限分组表';
-- ----------------------------
-- Records of fa_auth_group_access
-- ----------------------------
BEGIN;
INSERT INTO `fa_auth_group_access` VALUES (1, 1);
INSERT INTO `fa_auth_group_access` VALUES (2, 2);
INSERT INTO `fa_auth_group_access` VALUES (3, 3);
INSERT INTO `fa_auth_group_access` VALUES (4, 5);
INSERT INTO `fa_auth_group_access` VALUES (5, 5);
COMMIT;
-- ----------------------------
-- Table structure for fa_auth_rule
-- ----------------------------
DROP TABLE IF EXISTS `fa_auth_rule`;
CREATE TABLE `fa_auth_rule` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` enum('menu','file') NOT NULL DEFAULT 'file' COMMENT 'menu为菜单,file为权限节点',
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父ID',
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '规则名称',
`title` varchar(50) NOT NULL DEFAULT '' COMMENT '规则名称',
`icon` varchar(50) NOT NULL DEFAULT '' COMMENT '图标',
`condition` varchar(255) NOT NULL DEFAULT '' COMMENT '条件',
`remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
`ismenu` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否为菜单',
`createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重',
`status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`) USING BTREE,
KEY `pid` (`pid`),
KEY `weigh` (`weigh`)
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='节点表';
-- ----------------------------
-- Records of fa_auth_rule
-- ----------------------------
BEGIN;
INSERT INTO `fa_auth_rule` VALUES (1, 'file', 0, 'dashboard', 'Dashboard', 'fa fa-dashboard', '', 'Dashboard tips', 1, 1497429920, 1497429920, 143, 'normal');
INSERT INTO `fa_auth_rule` VALUES (2, 'file', 0, 'general', 'General', 'fa fa-cogs', '', '', 1, 1497429920, 1497430169, 137, 'normal');
INSERT INTO `fa_auth_rule` VALUES (3, 'file', 0, 'category', 'Category', 'fa fa-list', '', 'Category tips', 1, 1497429920, 1497429920, 119, 'normal');
INSERT INTO `fa_auth_rule` VALUES (4, 'file', 0, 'addon', 'Addon', 'fa fa-rocket', '', 'Addon tips', 1, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (5, 'file', 0, 'auth', 'Auth', 'fa fa-group', '', '', 1, 1497429920, 1497430092, 99, 'normal');
INSERT INTO `fa_auth_rule` VALUES (6, 'file', 2, 'general/config', 'Config', 'fa fa-cog', '', 'Config tips', 1, 1497429920, 1497430683, 60, 'normal');
INSERT INTO `fa_auth_rule` VALUES (7, 'file', 2, 'general/attachment', 'Attachment', 'fa fa-file-image-o', '', 'Attachment tips', 1, 1497429920, 1497430699, 53, 'normal');
INSERT INTO `fa_auth_rule` VALUES (8, 'file', 2, 'general/profile', 'Profile', 'fa fa-user', '', '', 1, 1497429920, 1497429920, 34, 'normal');
INSERT INTO `fa_auth_rule` VALUES (9, 'file', 5, 'auth/admin', 'Admin', 'fa fa-user', '', 'Admin tips', 1, 1497429920, 1497430320, 118, 'normal');
INSERT INTO `fa_auth_rule` VALUES (10, 'file', 5, 'auth/adminlog', 'Admin log', 'fa fa-list-alt', '', 'Admin log tips', 1, 1497429920, 1497430307, 113, 'normal');
INSERT INTO `fa_auth_rule` VALUES (11, 'file', 5, 'auth/group', 'Group', 'fa fa-group', '', 'Group tips', 1, 1497429920, 1497429920, 109, 'normal');
INSERT INTO `fa_auth_rule` VALUES (12, 'file', 5, 'auth/rule', 'Rule', 'fa fa-bars', '', 'Rule tips', 1, 1497429920, 1497430581, 104, 'normal');
INSERT INTO `fa_auth_rule` VALUES (13, 'file', 1, 'dashboard/index', 'View', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 136, 'normal');
INSERT INTO `fa_auth_rule` VALUES (14, 'file', 1, 'dashboard/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 135, 'normal');
INSERT INTO `fa_auth_rule` VALUES (15, 'file', 1, 'dashboard/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 133, 'normal');
INSERT INTO `fa_auth_rule` VALUES (16, 'file', 1, 'dashboard/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 134, 'normal');
INSERT INTO `fa_auth_rule` VALUES (17, 'file', 1, 'dashboard/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 132, 'normal');
INSERT INTO `fa_auth_rule` VALUES (18, 'file', 6, 'general/config/index', 'View', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 52, 'normal');
INSERT INTO `fa_auth_rule` VALUES (19, 'file', 6, 'general/config/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 51, 'normal');
INSERT INTO `fa_auth_rule` VALUES (20, 'file', 6, 'general/config/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 50, 'normal');
INSERT INTO `fa_auth_rule` VALUES (21, 'file', 6, 'general/config/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 49, 'normal');
INSERT INTO `fa_auth_rule` VALUES (22, 'file', 6, 'general/config/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 48, 'normal');
INSERT INTO `fa_auth_rule` VALUES (23, 'file', 7, 'general/attachment/index', 'View', 'fa fa-circle-o', '', 'Attachment tips', 0, 1497429920, 1497429920, 59, 'normal');
INSERT INTO `fa_auth_rule` VALUES (24, 'file', 7, 'general/attachment/select', 'Select attachment', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 58, 'normal');
INSERT INTO `fa_auth_rule` VALUES (25, 'file', 7, 'general/attachment/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 57, 'normal');
INSERT INTO `fa_auth_rule` VALUES (26, 'file', 7, 'general/attachment/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 56, 'normal');
INSERT INTO `fa_auth_rule` VALUES (27, 'file', 7, 'general/attachment/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 55, 'normal');
INSERT INTO `fa_auth_rule` VALUES (28, 'file', 7, 'general/attachment/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 54, 'normal');
INSERT INTO `fa_auth_rule` VALUES (29, 'file', 8, 'general/profile/index', 'View', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 33, 'normal');
INSERT INTO `fa_auth_rule` VALUES (30, 'file', 8, 'general/profile/update', 'Update profile', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 32, 'normal');
INSERT INTO `fa_auth_rule` VALUES (31, 'file', 8, 'general/profile/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 31, 'normal');
INSERT INTO `fa_auth_rule` VALUES (32, 'file', 8, 'general/profile/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 30, 'normal');
INSERT INTO `fa_auth_rule` VALUES (33, 'file', 8, 'general/profile/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 29, 'normal');
INSERT INTO `fa_auth_rule` VALUES (34, 'file', 8, 'general/profile/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 28, 'normal');
INSERT INTO `fa_auth_rule` VALUES (35, 'file', 3, 'category/index', 'View', 'fa fa-circle-o', '', 'Category tips', 0, 1497429920, 1497429920, 142, 'normal');
INSERT INTO `fa_auth_rule` VALUES (36, 'file', 3, 'category/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 141, 'normal');
INSERT INTO `fa_auth_rule` VALUES (37, 'file', 3, 'category/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 140, 'normal');
INSERT INTO `fa_auth_rule` VALUES (38, 'file', 3, 'category/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 139, 'normal');
INSERT INTO `fa_auth_rule` VALUES (39, 'file', 3, 'category/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 138, 'normal');
INSERT INTO `fa_auth_rule` VALUES (40, 'file', 9, 'auth/admin/index', 'View', 'fa fa-circle-o', '', 'Admin tips', 0, 1497429920, 1497429920, 117, 'normal');
INSERT INTO `fa_auth_rule` VALUES (41, 'file', 9, 'auth/admin/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 116, 'normal');
INSERT INTO `fa_auth_rule` VALUES (42, 'file', 9, 'auth/admin/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 115, 'normal');
INSERT INTO `fa_auth_rule` VALUES (43, 'file', 9, 'auth/admin/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 114, 'normal');
INSERT INTO `fa_auth_rule` VALUES (44, 'file', 10, 'auth/adminlog/index', 'View', 'fa fa-circle-o', '', 'Admin log tips', 0, 1497429920, 1497429920, 112, 'normal');
INSERT INTO `fa_auth_rule` VALUES (45, 'file', 10, 'auth/adminlog/detail', 'Detail', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 111, 'normal');
INSERT INTO `fa_auth_rule` VALUES (46, 'file', 10, 'auth/adminlog/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 110, 'normal');
INSERT INTO `fa_auth_rule` VALUES (47, 'file', 11, 'auth/group/index', 'View', 'fa fa-circle-o', '', 'Group tips', 0, 1497429920, 1497429920, 108, 'normal');
INSERT INTO `fa_auth_rule` VALUES (48, 'file', 11, 'auth/group/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 107, 'normal');
INSERT INTO `fa_auth_rule` VALUES (49, 'file', 11, 'auth/group/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 106, 'normal');
INSERT INTO `fa_auth_rule` VALUES (50, 'file', 11, 'auth/group/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 105, 'normal');
INSERT INTO `fa_auth_rule` VALUES (51, 'file', 12, 'auth/rule/index', 'View', 'fa fa-circle-o', '', 'Rule tips', 0, 1497429920, 1497429920, 103, 'normal');
INSERT INTO `fa_auth_rule` VALUES (52, 'file', 12, 'auth/rule/add', 'Add', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 102, 'normal');
INSERT INTO `fa_auth_rule` VALUES (53, 'file', 12, 'auth/rule/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 101, 'normal');
INSERT INTO `fa_auth_rule` VALUES (54, 'file', 12, 'auth/rule/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1497429920, 1497429920, 100, 'normal');
INSERT INTO `fa_auth_rule` VALUES (55, 'file', 4, 'addon/index', 'View', 'fa fa-circle-o', '', 'Addon tips', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (56, 'file', 4, 'addon/add', 'Add', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (57, 'file', 4, 'addon/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (58, 'file', 4, 'addon/del', 'Delete', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (59, 'file', 4, 'addon/local', 'Local install', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (60, 'file', 4, 'addon/state', 'Update state', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (61, 'file', 4, 'addon/install', 'Install', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (62, 'file', 4, 'addon/uninstall', 'Uninstall', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (63, 'file', 4, 'addon/config', 'Setting', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (64, 'file', 4, 'addon/refresh', 'Refresh', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (65, 'file', 4, 'addon/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1502035509, 1502035509, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (66, 'file', 0, 'user', 'User', 'fa fa-list', '', '', 1, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (67, 'file', 66, 'user/user', 'User', 'fa fa-user', '', '', 1, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (68, 'file', 67, 'user/user/index', 'View', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (69, 'file', 67, 'user/user/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (70, 'file', 67, 'user/user/add', 'Add', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (71, 'file', 67, 'user/user/del', 'Del', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (72, 'file', 67, 'user/user/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (73, 'file', 66, 'user/group', 'User group', 'fa fa-users', '', '', 1, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (74, 'file', 73, 'user/group/add', 'Add', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (75, 'file', 73, 'user/group/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (76, 'file', 73, 'user/group/index', 'View', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (77, 'file', 73, 'user/group/del', 'Del', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (78, 'file', 73, 'user/group/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (79, 'file', 66, 'user/rule', 'User rule', 'fa fa-circle-o', '', '', 1, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (80, 'file', 79, 'user/rule/index', 'View', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (81, 'file', 79, 'user/rule/del', 'Del', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (82, 'file', 79, 'user/rule/add', 'Add', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (83, 'file', 79, 'user/rule/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
INSERT INTO `fa_auth_rule` VALUES (84, 'file', 79, 'user/rule/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal');
COMMIT;
-- ----------------------------
-- Table structure for fa_user
-- ----------------------------
DROP TABLE IF EXISTS `fa_user`;
CREATE TABLE `fa_user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '组别ID',
`username` varchar(32) NOT NULL DEFAULT '' COMMENT '用户名',
`nickname` varchar(50) NOT NULL DEFAULT '' COMMENT '昵称',
`password` varchar(32) NOT NULL DEFAULT '' COMMENT '密码',
`salt` varchar(30) NOT NULL DEFAULT '' COMMENT '密码盐',
`email` varchar(100) NOT NULL DEFAULT '' COMMENT '电子邮箱',
`mobile` varchar(11) NOT NULL DEFAULT '' COMMENT '手机号',
`avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像',
`level` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '等级',
`gender` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '性别',
`birthday` date COMMENT '生日',
`bio` varchar(100) NOT NULL DEFAULT '' COMMENT '格言',
`score` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '积分',
`successions` int(10) unsigned NOT NULL DEFAULT '1' COMMENT '连续登录天数',
`maxsuccessions` int(10) unsigned NOT NULL DEFAULT '1' COMMENT '最大连续登录天数',
`prevtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '上次登录时间',
`logintime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '登录时间',
`loginip` varchar(50) NOT NULL DEFAULT '' COMMENT '登录IP',
`loginfailure` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '失败次数',
`joinip` varchar(50) NOT NULL DEFAULT '' COMMENT '加入IP',
`jointime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '加入时间',
`createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`token` varchar(50) NOT NULL DEFAULT '' COMMENT 'Token',
`status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态',
`verification` varchar(255) NOT NULL DEFAULT '' COMMENT '验证',
PRIMARY KEY (`id`),
KEY `username` (`username`),
KEY `email` (`email`),
KEY `mobile` (`mobile`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='会员表';
-- ----------------------------
-- Records of fa_user
-- ----------------------------
BEGIN;
INSERT INTO `fa_user` VALUES (1, 1, 'admin', 'admin', 'c13f62012fd6a8fdf06b3452a94430e5', 'rpR6Bv', 'admin@163.com', '13888888888', '/assets/img/avatar.png', 0, 0, '2017-04-15', '', 0, 1, 1, 1516170492, 1516171614, '127.0.0.1', 0, '127.0.0.1', 1491461418, 0, 1516171614, '', 'normal','');
COMMIT;
-- ----------------------------
-- Table structure for fa_user_group
-- ----------------------------
DROP TABLE IF EXISTS `fa_user_group`;
CREATE TABLE `fa_user_group` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT '' COMMENT '组名',
`rules` text COMMENT '权限节点',
`createtime` int(10) DEFAULT NULL COMMENT '添加时间',
`updatetime` int(10) DEFAULT NULL COMMENT '更新时间',
`status` enum('normal','hidden') DEFAULT NULL COMMENT '状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='会员组表';
-- ----------------------------
-- Records of fa_user_group
-- ----------------------------
BEGIN;
INSERT INTO `fa_user_group` VALUES (1, '默认组', '1,2,3,4,5,6,7,8,9,10,11,12', 1515386468, 1516168298, 'normal');
COMMIT;
-- ----------------------------
-- Table structure for fa_user_rule
-- ----------------------------
DROP TABLE IF EXISTS `fa_user_rule`;
CREATE TABLE `fa_user_rule` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(10) DEFAULT NULL COMMENT '父ID',
`name` varchar(50) DEFAULT NULL COMMENT '名称',
`title` varchar(50) DEFAULT '' COMMENT '标题',
`remark` varchar(100) DEFAULT NULL COMMENT '备注',
`ismenu` tinyint(1) DEFAULT NULL COMMENT '是否菜单',
`createtime` int(10) DEFAULT NULL COMMENT '创建时间',
`updatetime` int(10) DEFAULT NULL COMMENT '更新时间',
`weigh` int(10) DEFAULT '0' COMMENT '权重',
`status` enum('normal','hidden') DEFAULT NULL COMMENT '状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='会员规则表';
-- ----------------------------
-- Records of fa_user_rule
-- ----------------------------
BEGIN;
INSERT INTO `fa_user_rule` VALUES (1, 0, 'index', '前台', '', 1, 1516168079, 1516168079, 1, 'normal');
INSERT INTO `fa_user_rule` VALUES (2, 0, 'api', 'API接口', '', 1, 1516168062, 1516168062, 2, 'normal');
INSERT INTO `fa_user_rule` VALUES (3, 1, 'user', '会员模块', '', 1, 1515386221, 1516168103, 12, 'normal');
INSERT INTO `fa_user_rule` VALUES (4, 2, 'user', '会员模块', '', 1, 1515386221, 1516168092, 11, 'normal');
INSERT INTO `fa_user_rule` VALUES (5, 3, 'index/user/login', '登录', '', 0, 1515386247, 1515386247, 5, 'normal');
INSERT INTO `fa_user_rule` VALUES (6, 3, 'index/user/register', '注册', '', 0, 1515386262, 1516015236, 7, 'normal');
INSERT INTO `fa_user_rule` VALUES (7, 3, 'index/user/index', '会员中心', '', 0, 1516015012, 1516015012, 9, 'normal');
INSERT INTO `fa_user_rule` VALUES (8, 3, 'index/user/profile', '个人资料', '', 0, 1516015012, 1516015012, 4, 'normal');
INSERT INTO `fa_user_rule` VALUES (9, 4, 'api/user/login', '登录', '', 0, 1515386247, 1515386247, 6, 'normal');
INSERT INTO `fa_user_rule` VALUES (10, 4, 'api/user/register', '注册', '', 0, 1515386262, 1516015236, 8, 'normal');
INSERT INTO `fa_user_rule` VALUES (11, 4, 'api/user/index', '会员中心', '', 0, 1516015012, 1516015012, 10, 'normal');
INSERT INTO `fa_user_rule` VALUES (12, 4, 'api/user/profile', '个人资料', '', 0, 1516015012, 1516015012, 3, 'normal');
COMMIT;
-- ----------------------------
-- Table structure for fa_user_score_log
-- ----------------------------
DROP TABLE IF EXISTS `fa_user_score_log`;
CREATE TABLE `fa_user_score_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID',
`score` int(10) NOT NULL DEFAULT '0' COMMENT '变更积分',
`before` int(10) NOT NULL DEFAULT '0' COMMENT '变更前积分',
`after` int(10) NOT NULL DEFAULT '0' COMMENT '变更后积分',
`memo` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
`createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='会员积分变动表';
-- ----------------------------
-- Table structure for fa_user_token
-- ----------------------------
DROP TABLE IF EXISTS `fa_user_token`;
CREATE TABLE `fa_user_token` (
`token` varchar(50) NOT NULL COMMENT 'Token',
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID',
`createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`expiretime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '过期时间',
PRIMARY KEY (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='会员Token表';
文件目录
└── utils
├── Http.php
├── Strs.php
├── Jump.php
├── Tools.php
├── Email.php
├── Pinyin.php
├── Tree.php
├── Rsa.php
├── Auth.php
评论已关闭