no message

This commit is contained in:
kuaifan 2021-08-27 14:00:31 +08:00
parent 7a4fb01926
commit 5b07a03be6
3 changed files with 111 additions and 128 deletions

View File

@ -5,6 +5,8 @@ namespace App\Http\Middleware;
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); @error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
use Closure; use Closure;
use Request;
use URL;
class WebApi class WebApi
{ {
@ -20,6 +22,21 @@ class WebApi
global $_A; global $_A;
$_A = []; $_A = [];
if (Request::input('__Access-Control-Allow-Origin') || Request::header('__Access-Control-Allow-Origin')) {
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:Content-Type, platform, platform-channel, token, release, Access-Control-Allow-Origin');
}
$APP_FORCE_URL_SCHEME = env('APP_FORCE_URL_SCHEME', 'auto');
if ($APP_FORCE_URL_SCHEME == 'https' || $APP_FORCE_URL_SCHEME === true) {
URL::forceScheme('https');
} elseif ($APP_FORCE_URL_SCHEME == 'http' || $APP_FORCE_URL_SCHEME === false) {
URL::forceScheme('http');
} elseif (Request::header('x-forwarded-server-port', 80) == 443) {
URL::forceScheme('https');
}
return $next($request); return $next($request);
} }
} }

View File

@ -95,7 +95,7 @@ class Base
*/ */
public static function is_cidr($cidr) public static function is_cidr($cidr)
{ {
if (strpos($cidr, '/') !== false) { if (str_contains($cidr, '/')) {
list($cidr, $netmask) = explode('/', $cidr, 2); list($cidr, $netmask) = explode('/', $cidr, 2);
if ($netmask > 32 || $netmask < 0 || trim($netmask) == '') { if ($netmask > 32 || $netmask < 0 || trim($netmask) == '') {
return false; return false;
@ -406,12 +406,12 @@ class Base
} }
$data = trim($data); $data = trim($data);
if ($data == '') return $default; if ($data == '') return $default;
if (strpos(strtolower($data), 'array') === 0 && strtolower($data) !== 'array') { if (str_starts_with(strtolower($data), 'array') && strtolower($data) !== 'array') {
@ini_set('display_errors', 'on'); @ini_set('display_errors', 'on');
@eval("\$array = $data;"); @eval("\$array = $data;");
@ini_set('display_errors', 'off'); @ini_set('display_errors', 'off');
} else { } else {
if (strpos($data, '{\\') === 0) { if (str_starts_with($data, '{\\')) {
$data = stripslashes($data); $data = stripslashes($data);
} }
$array = json_decode($data, true); $array = json_decode($data, true);
@ -743,12 +743,12 @@ class Base
if (empty($str)) { if (empty($str)) {
return $str; return $str;
} }
if (substr($str, 0, 2) == "//" || if (str_starts_with($str, "//") ||
substr($str, 0, 7) == "http://" || str_starts_with($str, "http://") ||
substr($str, 0, 8) == "https://" || str_starts_with($str, "https://") ||
substr($str, 0, 6) == "ftp://" || str_starts_with($str, "ftp://") ||
substr($str, 0, 1) == "/" || str_starts_with($str, "/") ||
substr(str_replace(' ', '', $str), 0, 11) == "data:image/" str_starts_with(str_replace(' ', '', $str), "data:image/")
) { ) {
return $str; return $str;
} else { } else {
@ -802,14 +802,14 @@ class Base
if (preg_match($pattern, $content)) { if (preg_match($pattern, $content)) {
preg_match_all($pattern, $content, $matchs); preg_match_all($pattern, $content, $matchs);
foreach ($matchs[3] as $index => $value) { foreach ($matchs[3] as $index => $value) {
if (!(substr($value, 0, 7) == "http://" || if (!(str_starts_with($value, "http://") ||
substr($value, 0, 8) == "https://" || str_starts_with($value, "https://") ||
substr($value, 0, 6) == "ftp://" || str_starts_with($value, "ftp://") ||
substr(str_replace(' ', '', $value), 0, 11) == "data:image/" str_starts_with(str_replace(' ', '', $value), "data:image/")
)) { )) {
if (substr($value, 0, 2) == "//") { if (str_starts_with($value, "//")) {
$value = "http:" . $value; $value = "http:" . $value;
} elseif (substr($value, 0, 1) == "/") { } elseif (str_starts_with($value, "/")) {
$value = substr($value, 1); $value = substr($value, 1);
} }
$newValue = "<img" . $matchs[1][$index] . "src=" . $matchs[2][$index] . self::fillUrl($value) . $matchs[2][$index]; $newValue = "<img" . $matchs[1][$index] . "src=" . $matchs[2][$index] . self::fillUrl($value) . $matchs[2][$index];
@ -1051,7 +1051,7 @@ class Base
if (!is_string($string) || !is_string($find)) { if (!is_string($string) || !is_string($find)) {
return false; return false;
} }
return !(strpos($string, $find) === FALSE); return str_contains($string, $find);
} }
/** /**
@ -1059,7 +1059,7 @@ class Base
* @param string $string //原字符串 * @param string $string //原字符串
* @param string $find //判断字符串 * @param string $find //判断字符串
* @param bool|false $lower //是否不区分大小写 * @param bool|false $lower //是否不区分大小写
* @return int * @return bool
*/ */
public static function leftExists($string, $find, $lower = false) public static function leftExists($string, $find, $lower = false)
{ {
@ -1070,7 +1070,7 @@ class Base
$string = strtolower($string); $string = strtolower($string);
$find = strtolower($find); $find = strtolower($find);
} }
return (substr($string, 0, strlen($find)) == $find); return str_starts_with($string, $find);
} }
/** /**
@ -1089,7 +1089,7 @@ class Base
$string = strtolower($string); $string = strtolower($string);
$find = strtolower($find); $find = strtolower($find);
} }
return (substr($string, strlen($find) * -1) == $find); return str_ends_with($string, $find);
} }
/** /**
@ -1131,10 +1131,10 @@ class Base
*/ */
public static function getMiddle($str, $ta = '', $tb = '') public static function getMiddle($str, $ta = '', $tb = '')
{ {
if ($ta && strpos($str, $ta) !== false) { if ($ta && str_contains($str, $ta)) {
$str = substr($str, strpos($str, $ta) + strlen($ta)); $str = substr($str, strpos($str, $ta) + strlen($ta));
} }
if ($tb && strpos($str, $tb) !== false) { if ($tb && str_contains($str, $tb)) {
$str = substr($str, 0, strpos($str, $tb)); $str = substr($str, 0, strpos($str, $tb));
} }
return $str; return $str;
@ -1584,7 +1584,7 @@ class Base
if (Base::isMobile($str)) { if (Base::isMobile($str)) {
return substr($str, 0, 3) . "****" . substr($str, -4); return substr($str, 0, 3) . "****" . substr($str, -4);
} }
$pattern = '/([\d]{4})([\d]{4})([\d]{4})([\d]{4})([\d]{0,})?/i'; $pattern = '/([\d]{4})([\d]{4})([\d]{4})([\d]{4})([\d]*)?/i';
if (preg_match($pattern, $str)) { if (preg_match($pattern, $str)) {
return preg_replace($pattern, '$1 **** **** **** $5', $str); return preg_replace($pattern, '$1 **** **** **** $5', $str);
} }
@ -1891,9 +1891,9 @@ class Base
if (substr_count($ip, '.') == 3 && $ip == $range) { if (substr_count($ip, '.') == 3 && $ip == $range) {
return true; return true;
} }
if (strpos($range, '/') !== false) { if (str_contains($range, '/')) {
list($range, $netmask) = explode('/', $range, 2); list($range, $netmask) = explode('/', $range, 2);
if (strpos($netmask, '.') !== false) { if (str_contains($netmask, '.')) {
$netmask = str_replace('*', '0', $netmask); $netmask = str_replace('*', '0', $netmask);
$netmask_dec = ip2long($netmask); $netmask_dec = ip2long($netmask);
return ((ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec)); return ((ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec));
@ -1911,12 +1911,12 @@ class Base
return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec)); return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec));
} }
} else { } else {
if (strpos($range, '*') !== false) { if (str_contains($range, '*')) {
$lower = str_replace('*', '0', $range); $lower = str_replace('*', '0', $range);
$upper = str_replace('*', '255', $range); $upper = str_replace('*', '255', $range);
$range = "$lower-$upper"; $range = "$lower-$upper";
} }
if (strpos($range, '-') !== false) { if (str_contains($range, '-')) {
list($lower, $upper) = explode('-', $range, 2); list($lower, $upper) = explode('-', $range, 2);
$lower_dec = (float)sprintf("%u", ip2long($lower)); $lower_dec = (float)sprintf("%u", ip2long($lower));
$upper_dec = (float)sprintf("%u", ip2long($upper)); $upper_dec = (float)sprintf("%u", ip2long($upper));
@ -2042,7 +2042,7 @@ class Base
*/ */
public static function isWechat() public static function isWechat()
{ {
return strpos(Request::server('HTTP_USER_AGENT'), 'MicroMessenger') !== false; return str_contains(Request::server('HTTP_USER_AGENT'), 'MicroMessenger');
} }
/** /**
@ -2052,9 +2052,9 @@ class Base
public static function browser() public static function browser()
{ {
$user_agent = Request::server('HTTP_USER_AGENT'); $user_agent = Request::server('HTTP_USER_AGENT');
if (strpos($user_agent, 'AlipayClient') !== false) { if (str_contains($user_agent, 'AlipayClient')) {
return 'alipay'; return 'alipay';
} elseif (strpos($user_agent, 'MicroMessenger') !== false) { } elseif (str_contains($user_agent, 'MicroMessenger')) {
return 'weixin'; return 'weixin';
} else { } else {
return 'none'; return 'none';
@ -2137,50 +2137,48 @@ class Base
"height" => -1, //图片高度 "height" => -1, //图片高度
"ext" => $extension, //文件后缀名 "ext" => $extension, //文件后缀名
]; ];
if (in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) { //图片尺寸
//图片尺寸 $paramet = getimagesize($array['file']);
$paramet = getimagesize($array['file']); $array['width'] = $paramet[0];
$array['width'] = $paramet[0]; $array['height'] = $paramet[1];
$array['height'] = $paramet[1]; //原图压缩
//原图压缩 if ($param['scale'] && is_array($param['scale'])) {
if ($param['scale'] && is_array($param['scale'])) { list($width, $height) = $param['scale'];
list($width, $height) = $param['scale']; if (($width > 0 && $array['width'] > $width) || ($height > 0 && $array['height'] > $height)) {
if (($width > 0 && $array['width'] > $width) || ($height > 0 && $array['height'] > $height)) { $cut = ($width > 0 && $height > 0) ? 1 : -1;
$cut = ($width > 0 && $height > 0) ? 1 : -1; $cut = $param['scale'][2] ?? $cut;
$cut = $param['scale'][2] ?? $cut; //图片压缩
//图片压缩 $tmpFile = $array['file'] . '_tmp.jpg';
$tmpFile = $array['file'] . '_tmp.jpg'; if (Base::imgThumb($array['file'], $tmpFile, $width, $height, $cut)) {
if (Base::imgThumb($array['file'], $tmpFile, $width, $height, $cut)) { $tmpSize = filesize($tmpFile);
$tmpSize = filesize($tmpFile); if ($tmpSize > $fileSize) {
if ($tmpSize > $fileSize) { @unlink($tmpFile);
@unlink($tmpFile); } else {
} else { @unlink($array['file']);
@unlink($array['file']); rename($tmpFile, $array['file']);
rename($tmpFile, $array['file']);
}
} }
//图片尺寸 }
$paramet = getimagesize($array['file']); //图片尺寸
$array['width'] = $paramet[0]; $paramet = getimagesize($array['file']);
$array['height'] = $paramet[1]; $array['width'] = $paramet[0];
//重命名 $array['height'] = $paramet[1];
if ($scaleName) { //重命名
$scaleName = str_replace(['{WIDTH}', '{HEIGHT}'], [$array['width'], $array['height']], $scaleName); if ($scaleName) {
if (rename($array['file'], Base::rightDelete($array['file'], $fileName) . $scaleName)) { $scaleName = str_replace(['{WIDTH}', '{HEIGHT}'], [$array['width'], $array['height']], $scaleName);
$array['file'] = Base::rightDelete($array['file'], $fileName) . $scaleName; if (rename($array['file'], Base::rightDelete($array['file'], $fileName) . $scaleName)) {
$array['path'] = Base::rightDelete($array['path'], $fileName) . $scaleName; $array['file'] = Base::rightDelete($array['file'], $fileName) . $scaleName;
$array['url'] = Base::rightDelete($array['url'], $fileName) . $scaleName; $array['path'] = Base::rightDelete($array['path'], $fileName) . $scaleName;
} $array['url'] = Base::rightDelete($array['url'], $fileName) . $scaleName;
} }
} }
} }
//生成缩略图
$array['thumb'] = $array['path'];
if (Base::imgThumb($array['file'], $array['file'] . "_thumb.jpg", 180, 0)) {
$array['thumb'] .= "_thumb.jpg";
}
$array['thumb'] = Base::fillUrl($array['thumb']);
} }
//生成缩略图
$array['thumb'] = $array['path'];
if (Base::imgThumb($array['file'], $array['file'] . "_thumb.jpg", 180, 0)) {
$array['thumb'] .= "_thumb.jpg";
}
$array['thumb'] = Base::fillUrl($array['thumb']);
return Base::retSuccess('success', $array); return Base::retSuccess('success', $array);
} }
} }
@ -2245,7 +2243,7 @@ class Base
return Base::retError('错误的类型参数'); return Base::retError('错误的类型参数');
} }
$extension = strtolower($file->getClientOriginalExtension()); $extension = strtolower($file->getClientOriginalExtension());
if ($type && is_array($type) && !in_array($extension, $type)) { if ($type && !in_array($extension, $type)) {
return Base::retError('文件格式错误,限制类型:' . implode(",", $type)); return Base::retError('文件格式错误,限制类型:' . implode(",", $type));
} }
try { try {
@ -2294,20 +2292,12 @@ class Base
$data = imagecreatefromstring(file_get_contents($array['file'])); $data = imagecreatefromstring(file_get_contents($array['file']));
$exif = @exif_read_data($array['file']); $exif = @exif_read_data($array['file']);
if (!empty($exif['Orientation'])) { if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) { $data = match ($exif['Orientation']) {
case 8: 8 => imagerotate($data, 90, 0),
$data = imagerotate($data, 90, 0); 3 => imagerotate($data, 180, 0),
break; 6 => imagerotate($data, -90, 0),
case 3: default => null,
$data = imagerotate($data, 180, 0); };
break;
case 6:
$data = imagerotate($data, -90, 0);
break;
default:
$data = null;
break;
}
if ($data !== null) { if ($data !== null) {
imagejpeg($data, $array['file']); imagejpeg($data, $array['file']);
} }
@ -2506,41 +2496,13 @@ class Base
*/ */
public static function extIcon($ext) public static function extIcon($ext)
{ {
$value = 'images/ext/file.png'; return match ($ext) {
switch ($ext) { "docx" => 'images/ext/doc.png',
case "docx": "xlsx" => 'images/ext/xls.png',
$value = 'images/ext/doc.png'; "pptx" => 'images/ext/ppt.png',
break; "ai", "avi", "bmp", "cdr", "doc", "eps", "gif", "mov", "mp3", "mp4", "pdf", "ppt", "pr", "psd", "rar", "svg", "tif", "txt", "xls", "zip" => 'images/ext/' . $ext . '.png',
case "xlsx": default => 'images/ext/file.png',
$value = 'images/ext/xls.png'; };
break;
case "pptx":
$value = 'images/ext/ppt.png';
break;
case "ai":
case "avi":
case "bmp":
case "cdr":
case "doc":
case "eps":
case "gif":
case "mov":
case "mp3":
case "mp4":
case "pdf":
case "ppt":
case "pr":
case "psd":
case "rar":
case "svg":
case "tif":
case "txt":
case "xls":
case "zip":
$value = 'images/ext/' . $ext . '.png';
break;
}
return $value;
} }
/** /**
@ -2602,14 +2564,10 @@ class Base
$arr = []; $arr = [];
foreach ($args as $k => $v) { foreach ($args as $k => $v) {
if (isset($args[$k + 1]) && $args[$k + 1]) { if (isset($args[$k + 1]) && $args[$k + 1]) {
switch ($k) { $arr[$k] = match ($k) {
case 0: 0 => $pailie($v, $args[$k + 1]),
$arr[$k] = $pailie($v, $args[$k + 1]); default => $pailie($arr[$k - 1], $args[$k + 1]),
break; };
default:
$arr[$k] = $pailie($arr[$k - 1], $args[$k + 1]);
break;
}
} }
} }
$key = count($arr) - 1; $key = count($arr) - 1;
@ -2618,14 +2576,14 @@ class Base
/** /**
* 获取当前是本月第几个星期 * 获取当前是本月第几个星期
* @return false|float * @return float
*/ */
public static function getMonthWeek() public static function getMonthWeek()
{ {
$time = strtotime(date("Y-m-01")); $time = strtotime(date("Y-m-01"));
$w = date('w', $time); $w = date('w', $time);
$j = date("j"); $j = date("j");
return ceil(($j + $w) / 7); return ceil(($j . $w) / 7);
} }
/** /**

8
cmd
View File

@ -171,6 +171,14 @@ if [ $# -gt 0 ];then
env_set APP_DEBUG "true" env_set APP_DEBUG "true"
fi fi
supervisorctl_restart php supervisorctl_restart php
elif [[ "$1" == "https" ]]; then
shift 1
if [[ "$@" == "auto" ]];then
env_set APP_FORCE_URL_SCHEME "auto"
else
env_set APP_FORCE_URL_SCHEME "true"
fi
supervisorctl_restart php
elif [[ "$1" == "artisan" ]]; then elif [[ "$1" == "artisan" ]]; then
shift 1 shift 1
e="php artisan $@" && $COMPOSE exec php /bin/bash -c "$e" e="php artisan $@" && $COMPOSE exec php /bin/bash -c "$e"