提交 a74522a7 编写于 作者: 李光春's avatar 李光春

- 优化代码

上级 496b4a9c
## v6.0.87 / 2020-07-17
- 优化代码
## v6.0.86 / 2020-07-17
- 优化代码
- 优化代码
## v6.0.85 / 2020-07-17
- 扩展包不再包含数据库文件,允许通过配置文件路径的方式
......
......@@ -79,7 +79,6 @@ class ApiController extends stdClass
*/
public function error($msg = 'error', $code = 1, $data = [])
{
if ($data === []) $data = new stdClass();
throw new HttpResponseException(json([
'code' => $code, 'msg' => $msg, 'timestamp' => time(), 'data' => $data,
]));
......@@ -93,7 +92,6 @@ class ApiController extends stdClass
*/
public function success($data = [], $msg = 'success', $code = 0)
{
if ($data === []) $data = new stdClass();
throw new HttpResponseException(json([
'code' => $code, 'msg' => $msg, 'timestamp' => time(), 'data' => $data,
]));
......@@ -108,7 +106,6 @@ class ApiController extends stdClass
*/
public function aesSuccess($data = [], $msg = 'success', $code = 0, $name = 'sniff_h5')
{
if ($data === []) $data = new stdClass();
$timestamp = time();
throw new HttpResponseException(json([
'code' => $code, 'msg' => $msg, 'timestamp' => $timestamp, 'data' => [
......
......@@ -126,7 +126,9 @@ class Controller extends stdClass
$this->$name = $value;
} elseif (is_array($name)) {
foreach ($name as $k => $v) {
if (is_string($k)) $this->$k = $v;
if (is_string($k)) {
$this->$k = $v;
}
}
}
return $this;
......
......@@ -66,7 +66,7 @@ class Mysql
*/
public function set($cache_value)
{
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$this->judge();
$result = Db::table($this->table)
->insert([
'cache_name' => $this->cache_name,
......@@ -84,12 +84,11 @@ class Mysql
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws ModelNotFoundException|DtaException
*/
public function get()
{
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$this->judge();
$cache = Db::table($this->table)
->where('cache_name', $this->cache_name)
->order('id desc')
......@@ -101,12 +100,11 @@ class Mysql
/**
* 删除
* @return int
* @throws DbException
* @throws DtaException
* @throws DbException|DtaException
*/
public function delete()
{
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->delete();
......@@ -120,12 +118,11 @@ class Mysql
* 更新
* @param $cache_value
* @return int
* @throws DbException
* @throws DtaException
* @throws DbException|DtaException
*/
public function update($cache_value)
{
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
......@@ -144,8 +141,7 @@ class Mysql
* @return int
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws ModelNotFoundException|DtaException
*/
public function inc(int $int = 1)
{
......@@ -167,8 +163,7 @@ class Mysql
* @return int
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws ModelNotFoundException|DtaException
*/
public function dec(int $int = 1)
{
......@@ -183,4 +178,14 @@ class Mysql
}
return true;
}
/**
* @throws DtaException
*/
private function judge()
{
if (empty($this->cache_name)) {
throw new DtaException("名称未配置");
}
}
}
......@@ -28,7 +28,7 @@ use think\db\exception\ModelNotFoundException;
/**
* 定义当前版本
*/
const VERSION = '6.0.86';
const VERSION = '6.0.87';
if (!function_exists('get_ip_info')) {
/**
......
......@@ -69,7 +69,9 @@ class ThinkException extends Handle
*/
private function show($msg)
{
if (empty($msg)) return true;
if (empty($msg)) {
return true;
}
$nt = config('dtapp.exception.type', '');
if (!empty($nt) && $nt == 'dingtalk') {
$access_token = config('dtapp.exception.dingtalk.access_token', '');
......
......@@ -57,7 +57,9 @@ class Arrays
public function split(array $array, $num = 5): array
{
$arrRet = array();
if (!isset($array) || empty($array)) return $arrRet;
if (!isset($array) || empty($array)) {
return $arrRet;
}
$iCount = count($array) / $num;
if (!is_int($iCount)) {
$iCount = ceil($iCount);
......
......@@ -58,7 +58,9 @@ class Files
*/
public function deletes(string $name): bool
{
if (empty($name)) throw new Exception('请检查需要删除文件夹的名称');
if (empty($name)) {
throw new Exception('请检查需要删除文件夹的名称');
}
//先删除目录下的文件:
$dh = opendir($name);
while ($file = readdir($dh)) {
......@@ -90,7 +92,9 @@ class Files
*/
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{
if (empty($name)) throw new Exception('请检查需要打包的路径名称');
if (empty($name)) {
throw new Exception('请检查需要打包的路径名称');
}
try {
// 获取目录下所有某个结尾的文件列表
$list = glob($name . "{$file_name}.{$suffix_name}");
......
......@@ -75,7 +75,9 @@ class QqWryService extends Service
public function __construct(App $app)
{
$this->ipPath = config('dtapp.ip_path', '');
if (empty($this->ipPath)) throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置');
if (empty($this->ipPath)) {
throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置');
}
$this->fp = 0;
if (($this->fp = fopen($this->ipPath . 'qqwry.dat', 'rb')) !== false) {
$this->firstIp = $this->getLong();
......@@ -157,7 +159,10 @@ class QqWryService extends Service
}
static $locationData = [];
if (!isset($locationData[$ip])) {
if (!$this->fp) throw new DtaException('数据库文件不存在!'); // 如果数据文件没有被正确打开,则直接返回错误
if (!$this->fp) {
// 如果数据文件没有被正确打开,则直接返回错误
throw new DtaException('数据库文件不存在!');
}
$location['ip'] = $ip; // 将输入的域名转化为IP地址
$ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址
// 不合法的IP地址会被转化为255.255.255.255
......@@ -221,8 +226,12 @@ class QqWryService extends Service
break;
}
// CZ88.NET表示没有有效信息
if (trim($location['all']) == 'CZ88.NET') $location['all'] = $this->unknown;
if (trim($location['extend']) == 'CZ88.NET') $location['extend'] = '';
if (trim($location['all']) == 'CZ88.NET') {
$location['all'] = $this->unknown;
}
if (trim($location['extend']) == 'CZ88.NET') {
$location['extend'] = '';
}
$location['all'] = iconv("gb2312", "UTF-8//IGNORE", $location['all']);
$location['extend'] = iconv("gb2312", "UTF-8//IGNORE", $location['extend']);
$location['extend'] = $location['extend'] === null ? '' : $location['extend'];
......@@ -359,7 +368,9 @@ class QqWryService extends Service
*/
public function __destruct()
{
if ($this->fp) fclose($this->fp);
if ($this->fp) {
fclose($this->fp);
}
$this->fp = 0;
}
......
......@@ -130,7 +130,9 @@ class StorageService extends Service
*/
public function bytes(string $name)
{
if (empty($this->path)) $this->getConfig();
if (empty($this->path)) {
$this->getConfig();
}
$bytes = filesize($this->path . $name);
if ($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
......
......@@ -44,7 +44,9 @@ class AesService extends Service
*/
public function encrypt($data)
{
if (!empty(is_array($data))) $data = json_encode($data, JSON_UNESCAPED_UNICODE);
if (!empty(is_array($data))) {
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
}
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->key, 1, $this->iv)));
}
......
......@@ -249,11 +249,14 @@ class WatermarkService extends Service
->remotely($backtrack['music_info']['avatar'])
->save($backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $music_info_play = StorageService::instance()
->path($this->storagePath)
->remotely($backtrack['music_info']['play'])
->save($backtrack['music_info']['mid'] . ".mp3");
else $music_info_play = ['size' => '0kb'];
if (!empty($backtrack['music_info']['play'])) {
$music_info_play = StorageService::instance()
->path($this->storagePath)
->remotely($backtrack['music_info']['play'])
->save($backtrack['music_info']['mid'] . ".mp3");
} else {
$music_info_play = ['size' => '0kb'];
}
// 音频封面
$music_info_cover = StorageService::instance()
->path($this->storagePath)
......@@ -299,9 +302,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = OssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = OssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = OssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = OssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -329,9 +335,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = CosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = CosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = CosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = CosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -359,9 +368,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = ObsService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = ObsService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = ObsService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = ObsService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -389,9 +401,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = BosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = BosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = BosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = BosService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -419,9 +434,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = KodoService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = KodoService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = KodoService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = KodoService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -449,9 +467,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = UssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = UssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = UssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = UssService::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -479,9 +500,12 @@ class WatermarkService extends Service
$backtrack['yun']['music_info']['avatar'] = Ks3Service::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".jpeg", $system_path . $backtrack['music_info']['mid'] . ".jpeg");
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = Ks3Service::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
else $backtrack['yun']['music_info']['play'] = '';
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = Ks3Service::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . ".mp3", $system_path . $backtrack['music_info']['mid'] . ".mp3");
} else {
$backtrack['yun']['music_info']['play'] = '';
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = Ks3Service::instance()
->upload($yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg", $system_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg");
......@@ -510,8 +534,11 @@ class WatermarkService extends Service
// 音频头像
$backtrack['yun']['music_info']['avatar'] = $new_yun_path . $backtrack['music_info']['mid'] . ".jpeg";
// 音频文件
if (!empty($backtrack['music_info']['play'])) $backtrack['yun']['music_info']['play'] = $new_yun_path . $backtrack['music_info']['mid'] . ".mp3";
else $backtrack['yun']['music_info']['play'] = $new_yun_path;
if (!empty($backtrack['music_info']['play'])) {
$backtrack['yun']['music_info']['play'] = $new_yun_path . $backtrack['music_info']['mid'] . ".mp3";
} else {
$backtrack['yun']['music_info']['play'] = $new_yun_path;
}
// 音频封面
$backtrack['yun']['music_info']['cover'] = $new_yun_path . $backtrack['music_info']['mid'] . "_cover" . ".jpeg";
// 视频封面
......
......@@ -494,8 +494,11 @@ class JinBaoService extends Service
*/
private function object2array(&$object)
{
if (is_object($object)) $arr = (array)($object);
else $arr = &$object;
if (is_object($object)) {
$arr = (array)($object);
} else {
$arr = &$object;
}
if (is_array($arr)) {
foreach ($arr as $varName => $varValue) {
$arr[$varName] = $this->object2array($varValue);
......
......@@ -440,11 +440,13 @@ class MiniService extends Service
$file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json";
// 获取数据
$accessToken = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
if (empty($accessToken) || !is_array($accessToken)) $accessToken = [
'access_token' => '',
'expires_in' => '',
'expires_time' => '',
];
if (empty($accessToken) || !is_array($accessToken)) {
$accessToken = [
'access_token' => '',
'expires_in' => '',
'expires_time' => '',
];
}
if (empty($accessToken['expires_time'])) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
......
......@@ -316,7 +316,9 @@ class WebAppService extends Service
}
// 获取数据
$accessToken = $this->getAccessToken();
if (!isset($accessToken['access_token'])) throw new DtaException("获取access_token错误," . $accessToken['errmsg']);
if (!isset($accessToken['access_token'])) {
throw new DtaException("获取access_token错误," . $accessToken['errmsg']);
}
$res = HttpService::instance()
->url("{$this->api_url}cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi")
->toArray();
......@@ -643,11 +645,13 @@ class WebAppService extends Service
$file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json";
// 获取数据
$accessToken = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
if (empty($accessToken) || !is_array($accessToken)) $accessToken = [
'access_token' => '',
'expires_in' => '',
'expires_time' => '',
];
if (empty($accessToken) || !is_array($accessToken)) {
$accessToken = [
'access_token' => '',
'expires_in' => '',
'expires_time' => '',
];
}
if (empty($accessToken['expires_time'])) {
// 文件不存在
$accessToken_res = HttpService::instance()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册