v6
李光春 4 years ago
parent e748456320
commit aac15a74a7

@ -1,3 +1,6 @@
## v6.0.107 / 2020-08-15
- 优化
## v6.0.106 / 2020-08-08 ## v6.0.106 / 2020-08-08
- 修复数组门面增加数组删除空格函数问题 - 修复数组门面增加数组删除空格函数问题

@ -34,8 +34,6 @@
"ext-dom": "*", "ext-dom": "*",
"topthink/framework": "^6.0.0", "topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0", "topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0",
"topthink/think-multi-app": "^1.0",
"aliyuncs/oss-sdk-php": "^2.3", "aliyuncs/oss-sdk-php": "^2.3",
"obs/esdk-obs-php": "^3.19", "obs/esdk-obs-php": "^3.19",
"baidubce/bce-sdk-php": "^0.8.22", "baidubce/bce-sdk-php": "^0.8.22",

@ -65,7 +65,7 @@ class ApiController extends stdClass
$this->app = $app; $this->app = $app;
$this->request = $app->request; $this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\ApiController', $this); $this->app->bind('DtApp\ThinkLibrary\ApiController', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) { if (in_array($this->request->action(), get_class_methods(__CLASS__), true)) {
$this->error('Access without permission.'); $this->error('Access without permission.');
} }
$this->initialize(); $this->initialize();
@ -193,11 +193,8 @@ class ApiController extends stdClass
if (empty($name)) { if (empty($name)) {
return $this->aes_decrypt_data; return $this->aes_decrypt_data;
} }
if (isset($this->aes_decrypt_data[$name])) {
return $this->aes_decrypt_data[$name]; return $this->aes_decrypt_data[$name] ?? $default;
} else {
return $default;
}
} }
/** /**

@ -52,7 +52,7 @@ class Controller extends stdClass
$this->app = $app; $this->app = $app;
$this->request = $app->request; $this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\Controller', $this); $this->app->bind('DtApp\ThinkLibrary\Controller', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) { if (in_array($this->request->action(), get_class_methods(__CLASS__), true)) {
$this->error('Access without permission.'); $this->error('Access without permission.');
} }
$this->initialize(); $this->initialize();

@ -21,12 +21,11 @@ use DtApp\ThinkLibrary\cache\Mysql;
use DtApp\ThinkLibrary\exception\DtaException; use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\QqWryService; use DtApp\ThinkLibrary\service\QqWryService;
use DtApp\ThinkLibrary\service\SystemService; use DtApp\ThinkLibrary\service\SystemService;
use think\db\exception\DbException;
/** /**
* 定义当前版本 * 定义当前版本
*/ */
const VERSION = '6.0.106'; const VERSION = '6.0.107';
if (!function_exists('get_ip_info')) { if (!function_exists('get_ip_info')) {
/** /**
@ -61,9 +60,8 @@ if (!function_exists('get_ip')) {
//为了兼容百度的CDN所以转成数组 //为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return $arr[0]; return $arr[0];
} else {
return $_SERVER['REMOTE_ADDR'];
} }
return $_SERVER['REMOTE_ADDR'];
} }
} }
@ -90,8 +88,8 @@ if (!function_exists('dtacache')) {
* @param array $value * @param array $value
* @param int $expire * @param int $expire
* @return bool|int|string * @return bool|int|string
* @throws DbException
* @throws DtaException * @throws DtaException
* @throws \think\db\exception\DbException
*/ */
function dtacache($name = '', $value = [], $expire = 6000) function dtacache($name = '', $value = [], $expire = 6000)
{ {
@ -99,19 +97,20 @@ if (!function_exists('dtacache')) {
if (empty($value)) { if (empty($value)) {
return $myc->name($name) return $myc->name($name)
->get(); ->get();
}
$judge = $myc->name($name)
->get();
if (empty($judge)) {
$myc->name($name)
->expire($expire)
->set($value);
} else { } else {
if (empty($myc->name($name) $myc->name($name)
->get())) { ->expire($expire)
$myc->name($name) ->update($value);
->expire($expire)
->set($value);
} else {
$myc->name($name)
->expire($expire)
->update($value);
}
return $myc->name($name)
->get();
} }
return $myc->name($name)
->get();
} }
} }

@ -64,7 +64,7 @@ class Arrays
if (!is_int($iCount)) { if (!is_int($iCount)) {
$iCount = ceil($iCount); $iCount = ceil($iCount);
} else { } else {
$iCount += 1; ++$iCount;
} }
for ($i = 0; $i < $iCount; ++$i) { for ($i = 0; $i < $iCount; ++$i) {
$arrInfos = array_slice($array, $i * $num, $num); $arrInfos = array_slice($array, $i * $num, $num);
@ -86,7 +86,7 @@ class Arrays
{ {
$out = array(); $out = array();
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if (!in_array($value, $out)) { if (!in_array($value, $out, true)) {
$out[$key] = $value; $out[$key] = $value;
} }
} }

@ -79,9 +79,9 @@ class Files
//删除当前文件夹: //删除当前文件夹:
if (rmdir($name)) { if (rmdir($name)) {
return true; return true;
} else {
return false;
} }
return false;
} }
/** /**
@ -97,23 +97,18 @@ class Files
if (empty($name)) { if (empty($name)) {
throw new DtaException('请检查需要打包的路径名称'); throw new DtaException('请检查需要打包的路径名称');
} }
try { $list = glob($name . "{$file_name}.{$suffix_name}");
// 获取目录下所有某个结尾的文件列表 $fileList = $list;
$list = glob($name . "{$file_name}.{$suffix_name}"); $zip = new ZipArchive();
$fileList = $list; // 打开压缩包
$zip = new ZipArchive(); $zip->open($name, ZipArchive::CREATE);
// 打开压缩包 //向压缩包中添加文件
$zip->open($name, ZipArchive::CREATE); foreach ($fileList as $file) {
//向压缩包中添加文件 $zip->addFile($file, basename($file));
foreach ($fileList as $file) {
$zip->addFile($file, basename($file));
}
//关闭压缩包
$zip->close();
return true;
} catch (\DtaException $e) {
return false;
} }
//关闭压缩包
$zip->close();
return true;
} }
/** /**
@ -139,9 +134,9 @@ class Files
} }
$file->close(); $file->close();
return $files; return $files;
} else {
return [];
} }
return [];
} }
/** /**
@ -154,15 +149,17 @@ class Files
$files = $this->getFiles($path); $files = $this->getFiles($path);
if (!is_array($files)) { if (!is_array($files)) {
return false; return false;
} elseif (empty($files)) { }
if (empty($files)) {
return false; return false;
} else { }
foreach ($files as $item => $file) {
if (is_dir($file)) { foreach ($files as $item => $file) {
rmdir($file); if (is_dir($file)) {
} elseif (is_file($file)) { rmdir($file);
unlink($file); } elseif (is_file($file)) {
} unlink($file);
} }
} }
return true; return true;

@ -21,6 +21,8 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use Exception;
/** /**
* 随机管理类 * 随机管理类
* @mixin Randoms * @mixin Randoms
@ -33,6 +35,7 @@ class Randoms
* @param int $length 长度 * @param int $length 长度
* @param int $type 类型1 纯数字2 纯小写字母3 纯大写字母4 数字和小写字母5 数字和大写字母6 大小写字母7 数字和大小写字母 * @param int $type 类型1 纯数字2 纯小写字母3 纯大写字母4 数字和小写字母5 数字和大写字母6 大小写字母7 数字和大小写字母
* @return string * @return string
* @throws Exception
*/ */
public function generate(int $length = 6, int $type = 1) public function generate(int $length = 6, int $type = 1)
{ {
@ -61,30 +64,30 @@ class Randoms
$str = ''; $str = '';
// 生成字符串 // 生成字符串
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {
$str .= $charset[mt_rand(0, count($charset) - 1)]; $str .= $charset[random_int(0, count($charset) - 1)];
// 验证规则 // 验证规则
if ($type == 4 && strlen($str) >= 2) { if ($type == 4 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) { if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) {
$str = substr($str, 0, -1); $str = substr($str, 0, -1);
$i = $i - 1; --$i;
} }
} }
if ($type == 5 && strlen($str) >= 2) { if ($type == 5 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[A-Z]+/', $str)) { if (!preg_match('/\d+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1); $str = substr($str, 0, -1);
$i = $i - 1; --$i;
} }
} }
if ($type == 6 && strlen($str) >= 2) { if ($type == 6 && strlen($str) >= 2) {
if (!preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) { if (!preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1); $str = substr($str, 0, -1);
$i = $i - 1; --$i;
} }
} }
if ($type == 7 && strlen($str) >= 3) { if ($type == 7 && strlen($str) >= 3) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) { if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -2); $str = substr($str, 0, -2);
$i = $i - 2; $i -= 2;
} }
} }
} }

@ -37,7 +37,7 @@ class Requests
public function isEmpty(array $data, array $arr): array public function isEmpty(array $data, array $arr): array
{ {
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (empty(isset($data["$v"]) ? $data["$v"] : '')) { if (empty($data[(string)$v] ?? '')) {
return []; return [];
} }
} }
@ -53,7 +53,7 @@ class Requests
public function isEmptyRet(array $data, array $arr): array public function isEmptyRet(array $data, array $arr): array
{ {
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (empty(isset($data["$v"]) ? $data["$v"] : '')) { if (empty($data[(string)$v] ?? '')) {
(new Returns)->jsonError('请检查参数', 102); (new Returns)->jsonError('请检查参数', 102);
} }
} }
@ -118,7 +118,7 @@ class Requests
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
//找不到为flase,否则为true //找不到为flase,否则为true
if (isset($_SERVER['HTTP_VIA'])) { if (isset($_SERVER['HTTP_VIA'])) {
return stristr(request()->server('HTTP_VIA'), "wap") ? true : false; return stripos(request()->server('HTTP_VIA'), "wap") !== false;
} }
//判断手机发送的客户端标志 //判断手机发送的客户端标志
if (isset($_SERVER['HTTP_USER_AGENT'])) { if (isset($_SERVER['HTTP_USER_AGENT'])) {
@ -150,10 +150,7 @@ class Requests
*/ */
public function isWeiXin(): bool public function isWeiXin(): bool
{ {
if (strpos(request()->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false) { return strpos(request()->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false;
return true;
}
return false;
} }
/** /**
@ -162,10 +159,7 @@ class Requests
*/ */
public function isWeiXinMp(): bool public function isWeiXinMp(): bool
{ {
if (strpos(request()->server('HTTP_USER_AGENT'), 'miniProgram') !== false) { return strpos(request()->server('HTTP_USER_AGENT'), 'miniProgram') !== false;
return true;
}
return false;
} }
/** /**
@ -174,10 +168,7 @@ class Requests
*/ */
public function isAliPay(): bool public function isAliPay(): bool
{ {
if (strpos(request()->server('HTTP_USER_AGENT'), 'Alipay') !== false) { return strpos(request()->server('HTTP_USER_AGENT'), 'Alipay') !== false;
return true;
}
return false;
} }
/** /**
@ -186,12 +177,7 @@ class Requests
*/ */
public function isQQ(): bool public function isQQ(): bool
{ {
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) { return (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) && strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false;
if (strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false) {
return true;
}
}
return false;
} }
/** /**
@ -201,11 +187,7 @@ class Requests
public function isQQBrowser(): bool public function isQQBrowser(): bool
{ {
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) { if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) {
if (strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false) { return !(strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false);
return false;
} else {
return true;
}
} }
return false; return false;
} }

@ -30,6 +30,12 @@ use think\exception\HttpResponseException;
*/ */
class Returns class Returns
{ {
public function __construct()
{
date_default_timezone_set('Asia/Shanghai');
header('Content-Type:application/json; charset=utf-8');
}
/** /**
* 返回Json-成功 * 返回Json-成功
* @param array $data 数据 * @param array $data 数据
@ -39,13 +45,21 @@ class Returns
*/ */
public function jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = []) public function jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = [])
{ {
date_default_timezone_set('Asia/Shanghai');
header('Content-Type:application/json; charset=utf-8');
if (!empty($ext) && is_array($ext)) { if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => $data], $ext))); throw new HttpResponseException(json(array_merge([
} else { 'code' => $code,
throw new HttpResponseException(json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => $data])); 'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
} }
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
} }
/** /**
@ -57,12 +71,20 @@ class Returns
*/ */
public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []) public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = [])
{ {
date_default_timezone_set('Asia/Shanghai');
header('Content-Type:application/json; charset=utf-8');
if (!empty($ext) && is_array($ext)) { if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => $data], $ext))); throw new HttpResponseException(json(array_merge([
} else { 'code' => $code,
throw new HttpResponseException(json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => $data])); 'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
} }
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
} }
} }

@ -65,72 +65,7 @@ class Strings
*/ */
public function filter(string $str): string public function filter(string $str): string
{ {
$str = str_replace('`', '', $str); $str = str_replace(array('`', '·', '~', '!', '', '@', '#', '$', '¥', '%', '^', '……', '&', '*', '(', ')', '', '', '-', '_', '——', '+', '=', '|', '\\', '[', ']', '【', '】', '{', '}', ';', '', ':', '', '\'', '"', '“', '”', ',', '', '<', '>', '《', '》', '.', '。', '/', '、', '?', '', '╮', '(', ')', 'r', 'ぷ', '〆', 'ゞ', 'ヤ', 'ゼ', 'ǎ', 'ǎ', '〆', 'む', '§', '上门'), '', $str);
$str = str_replace('·', '', $str);
$str = str_replace('~', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('@', '', $str);
$str = str_replace('#', '', $str);
$str = str_replace('$', '', $str);
$str = str_replace('¥', '', $str);
$str = str_replace('%', '', $str);
$str = str_replace('^', '', $str);
$str = str_replace('……', '', $str);
$str = str_replace('&', '', $str);
$str = str_replace('*', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('-', '', $str);
$str = str_replace('_', '', $str);
$str = str_replace('——', '', $str);
$str = str_replace('+', '', $str);
$str = str_replace('=', '', $str);
$str = str_replace('|', '', $str);
$str = str_replace('\\', '', $str);
$str = str_replace('[', '', $str);
$str = str_replace(']', '', $str);
$str = str_replace('【', '', $str);
$str = str_replace('】', '', $str);
$str = str_replace('{', '', $str);
$str = str_replace('}', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace('', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('\'', '', $str);
$str = str_replace('"', '', $str);
$str = str_replace('“', '', $str);
$str = str_replace('”', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('<', '', $str);
$str = str_replace('>', '', $str);
$str = str_replace('《', '', $str);
$str = str_replace('》', '', $str);
$str = str_replace('.', '', $str);
$str = str_replace('。', '', $str);
$str = str_replace('/', '', $str);
$str = str_replace('、', '', $str);
$str = str_replace('?', '', $str);
$str = str_replace('', '', $str);
$str = str_replace('╮', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('r', '', $str);
$str = str_replace('ぷ', '', $str);
$str = str_replace('〆', '', $str);
$str = str_replace('ゞ', '', $str);
$str = str_replace('ヤ', '', $str);
$str = str_replace('ゼ', '', $str);
$str = str_replace('ǎ', '', $str);
$str = str_replace('ǎ', '', $str);
$str = str_replace('〆', '', $str);
$str = str_replace('む', '', $str);
$str = str_replace('§', '', $str);
$str = str_replace('上门', '', $str);
return trim($str); return trim($str);
} }
@ -151,12 +86,9 @@ class Strings
} }
} }
return false; return false;
} else {
if ($str == $nee) {
return true;
}
return false;
} }
return $str == $nee;
} }
/** /**

@ -21,6 +21,8 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use Exception;
/** /**
* 唯一ID管理类 * 唯一ID管理类
* @mixin UnIqIds * @mixin UnIqIds
@ -34,24 +36,25 @@ class UnIqIds
* @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母) * @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母)
* @param string $prefix 编码前缀 * @param string $prefix 编码前缀
* @return string * @return string
* @throws Exception
*/ */
public function random($size = 10, $type = 1, $prefix = ''): string public function random($size = 10, $type = 1, $prefix = ''): string
{ {
$numbs = '0123456789'; $numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz'; $chars = 'abcdefghijklmnopqrstuvwxyz';
if (intval($type) === 1) { if ((int)$type === 1) {
$chars = $numbs; $chars = $numbs;
} }
if (intval($type) === 2) { if ((int)$type === 2) {
$chars = "{$chars}"; $chars = "{$chars}";
} }
if (intval($type) === 3) { if ((int)$type === 3) {
$chars = "{$numbs}{$chars}"; $chars = "{$numbs}{$chars}";
} }
$string = $prefix . $chars[rand(1, strlen($chars) - 1)]; $string = $prefix . $chars[random_int(1, strlen($chars) - 1)];
if (isset($chars)) { if (isset($chars)) {
while (strlen($string) < $size) { while (strlen($string) < $size) {
$string .= $chars[rand(0, strlen($chars) - 1)]; $string .= $chars[random_int(0, strlen($chars) - 1)];
} }
} }
return $string; return $string;
@ -62,6 +65,7 @@ class UnIqIds
* @param integer $size * @param integer $size
* @param string $prefix * @param string $prefix
* @return string * @return string
* @throws Exception
*/ */
public function date($size = 16, $prefix = ''): string public function date($size = 16, $prefix = ''): string
{ {
@ -70,7 +74,7 @@ class UnIqIds
} }
$string = $prefix . date('Ymd') . (date('H') + date('i')) . date('s'); $string = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
while (strlen($string) < $size) { while (strlen($string) < $size) {
$string .= rand(0, 9); $string .= random_int(0, 9);
} }
return $string; return $string;
} }
@ -80,6 +84,7 @@ class UnIqIds
* @param integer $size * @param integer $size
* @param string $prefix * @param string $prefix
* @return string * @return string
* @throws Exception
*/ */
public function number($size = 12, $prefix = ''): string public function number($size = 12, $prefix = ''): string
{ {
@ -87,9 +92,9 @@ class UnIqIds
if ($size < 10) { if ($size < 10) {
$size = 10; $size = 10;
} }
$string = $prefix . ($time[0] . $time[1]) . substr($time, 2) . rand(0, 9); $string = $prefix . ($time[0] . $time[1]) . substr($time, 2) . random_int(0, 9);
while (strlen($string) < $size) { while (strlen($string) < $size) {
$string .= rand(0, 9); $string .= random_int(0, 9);
} }
return $string; return $string;
} }

@ -81,9 +81,9 @@ class Urls
$pattern = "#(http|https)://(.*\.)?.*\..*#i"; $pattern = "#(http|https)://(.*\.)?.*\..*#i";
if (preg_match($pattern, $url)) { if (preg_match($pattern, $url)) {
return true; return true;
} else {
return false;
} }
return false;
} }
/** /**

@ -404,8 +404,8 @@ class ApiService extends Service
//定义cookie保存位置 //定义cookie保存位置
$file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/'; $file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/';
$cookie_file = $file . md5($this->panel) . '.cookie'; $cookie_file = $file . md5($this->panel) . '.cookie';
if (empty(Files::judgeContents($file))) { if (empty(Files::judgeContents($file)) && !mkdir($file, 0777, true) && !is_dir($file)) {
mkdir($file, 0777, true); throw new \RuntimeException(sprintf('Directory "%s" was not created', $file));
} }
if (!file_exists($cookie_file)) { if (!file_exists($cookie_file)) {
$fp = fopen($cookie_file, 'w+'); $fp = fopen($cookie_file, 'w+');

@ -96,8 +96,8 @@ class ObsService extends Service
]); ]);
if (isset($resp['RequestId'])) { if (isset($resp['RequestId'])) {
return config('dtapp.huaweicloud.obs.url', '') . $object; return config('dtapp.huaweicloud.obs.url', '') . $object;
} else {
return false;
} }
return false;
} }
} }

@ -83,11 +83,11 @@ class KodoService extends Service
// 构建 UploadManager 对象 // 构建 UploadManager 对象
$uploadMgr = new UploadManager(); $uploadMgr = new UploadManager();
// 调用 UploadManager 的 putFile 方法进行文件的上传。 // 调用 UploadManager 的 putFile 方法进行文件的上传。
list($ret, $err) = $uploadMgr->putFile($token, $object, $filePath); [$ret, $err] = $uploadMgr->putFile($token, $object, $filePath);
if ($err !== null) { if ($err !== null) {
return false; return false;
} else {
return config('dtapp.qiniu.kodo.url', '') . $object;
} }
return config('dtapp.qiniu.kodo.url', '') . $object;
} }
} }

@ -94,16 +94,14 @@ class CosService extends Service
); );
$key = $object; $key = $object;
$file = fopen($filePath, "rb"); $file = fopen($filePath, "rb");
if ($file) { if ($file && empty($this->bucket)) {
if (empty($this->bucket)) { $this->getConfig();
$this->getConfig(); $result = $cosClient->putObject(
$result = $cosClient->putObject( array(
array( 'Bucket' => $this->bucket,
'Bucket' => $this->bucket, 'Key' => $key,
'Key' => $key, 'Body' => $file)
'Body' => $file) );
);
}
} }
return config('dtapp.tencent.cos.url', '') . $object; return config('dtapp.tencent.cos.url', '') . $object;
} }

@ -332,7 +332,7 @@ class WebAppService extends Service
} }
} }
// 注意 URL 一定要动态获取,不能 hardcode. // 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time(); $timestamp = time();
$nonceStr = $this->createNonceStr(); $nonceStr = $this->createNonceStr();
@ -355,7 +355,7 @@ class WebAppService extends Service
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = ""; $str = "";
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); $str .= $chars[random_int(0, strlen($chars) - 1)];
} }
return $str; return $str;
} }
@ -667,12 +667,15 @@ class WebAppService extends Service
if (!empty($cache_mysql_value)) { if (!empty($cache_mysql_value)) {
$access_token['access_token'] = $cache_mysql_value; $access_token['access_token'] = $cache_mysql_value;
} else { } else {
// 获取远程Token
$accessToken_res = HttpService::instance() $accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray(); ->toArray();
// 保存到数据库
dtacache($file, $accessToken_res['access_token'], 6000); dtacache($file, $accessToken_res['access_token'], 6000);
$access_token['access_token'] = $accessToken_res['access_token']; $access_token['access_token'] = $accessToken_res['access_token'];
} }
// 判断token是否可以使用
$judge = HttpService::instance() $judge = HttpService::instance()
->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$access_token['access_token']}") ->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$access_token['access_token']}")
->toArray(); ->toArray();

@ -99,15 +99,15 @@ class Mysql implements SessionHandlerInterface
$result = Db::table($this->table_name) $result = Db::table($this->table_name)
->insert($params); ->insert($params);
return $result ? true : false; return $result ? true : false;
} else {
$params = [
'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']),
'session_data' => $data
];
$result = Db::table($this->table_name)
->where('id', $get['id'])
->update($params);
return $result ? true : false;
} }
$params = [
'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']),
'session_data' => $data
];
$result = Db::table($this->table_name)
->where('id', $get['id'])
->update($params);
return $result ? true : false;
} }
} }

Loading…
Cancel
Save