This commit is contained in:
2022-09-09 15:15:19 +08:00
parent a15297de92
commit e395dd279d
2 changed files with 132 additions and 103 deletions

4
.env
View File

@@ -28,4 +28,6 @@ REGIONID=cn-hangzhou
SIGNNAME=域展科技
TEMPLATECODE=SMS_176560077
OSS_BUCKET=hphb-storage
OSS_ENDPOINT=oss-cn-beijing.aliyuncs.com
OSS_ENDPOINT=hphb-cdn.uzchain.tech
#OSS_ENDPOINT=oss-cn-beijing.aliyuncs.com

View File

@@ -35,23 +35,33 @@ const TIMEOUT_ERROR_MESSAGE = "数据超时";
// 获取客户端IP
if (! function_exists('get_client_ip')) {
function get_client_ip(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
function get_client_ip()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
} else {
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
} else {
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
} else {
if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'],
"unknown")) {
$ip = $_SERVER['REMOTE_ADDR'];
else
} else {
$ip = "unknown";
}
}
}
}
return ($ip);
}
}
if (! function_exists('show')) {
function show($message = '',$code = ERROR_CODE,$data = [],$appKey="",$httpStatus = 200){
function show($message = '', $code = ERROR_CODE, $data = [], $appKey = "", $httpStatus = 200)
{
if ($appKey == "" && ! empty($GLOBALS['appkey'])) {
$appKey = $GLOBALS['appkey'];
}
@@ -65,13 +75,16 @@ if(!function_exists('show')){
/**
* 验证手机号是否正确
* @author honfei
*
* @param number $mobile
* @author honfei
*/
if (! function_exists('is_mobile_number')) {
function is_mobile_number($mobile)
{
if (!is_numeric($mobile)) return false;
if (! is_numeric($mobile)) {
return false;
}
return (bool) preg_match('#^1[3,4,5,7,8,9]{1}[\d]{9}$#', $mobile);
}
}
@@ -79,13 +92,16 @@ if(!function_exists('is_mobile_number')) {
/**
* 生成随机字符串
*
* @param int $length 生成随机字符串的长度
* @param string $char 组成随机字符串的字符串
* @return string $string 生成的随机字符串
*/
if (! function_exists('strRand')) {
function strRand(int $length = 32, string $char = '0123456789&abcdefghijklmnopqrstuvwxyz@ABCDEFGHIJKLMNOPQRSTUVWXYZ$')
{
function strRand(
int $length = 32,
string $char = '0123456789&abcdefghijklmnopqrstuvwxyz@ABCDEFGHIJKLMNOPQRSTUVWXYZ$'
) {
if (! is_int($length) || $length < 0) {
return false;
}
@@ -98,9 +114,9 @@ if(!function_exists('strRand')) {
}
/**
* Discuz 经典双向加密/解密
*
* @param string $string 明文 或 密文
* @param string $operation DECODE表示解密,其它表示加密
* @param string $key 密匙
@@ -116,10 +132,12 @@ if(!function_exists('authcode')) {
$key = md5($key ? $key : env('data_auth_key'));
$keya = md5(substr($key, 0, 16));
$keyb = md5(substr($key, 16, 16));
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0,
$ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
$cryptkey = $keya.md5($keya.$keyc);
$key_length = strlen($cryptkey);
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d',
$expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
$string_length = strlen($string);
$result = '';
$box = range(0, 255);
@@ -142,7 +160,8 @@ if(!function_exists('authcode')) {
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
}
if ($operation == 'DECODE') {
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10,
16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
return substr($result, 26);
} else {
return '';
@@ -196,8 +215,8 @@ if (!function_exists('aliyun')) {
$config = [
'access' => env('ALIYUNSMS.ACCESSKEYID'),
'access_key' => env('ALIYUNSMS.ACCESSKEY'),
'bucket' => 'hphb-storage',
'url' => 'https://oss-cn-beijing.aliyuncs.com'
'bucket' => env('ALIYUNSMS.OSS_BUCKET'),
'url' => env('ALIYUNSMS.OSS_ENDPOINT'),
];
$path = "r/".$localfile;
$localfile = env("UPLOAD_DIRECTORY").'/'.$localfile;//文件路径,必须是本地的。
@@ -225,7 +244,6 @@ if (!function_exists('aliyun')) {
}
function getExt($filename)
{
$arr = explode('.', $filename);
@@ -233,7 +251,8 @@ function getExt($filename)
}
function StudentToArray($list = []) : array {
function StudentToArray($list = []): array
{
$result = [];
$result['lastIndex'] = 0;
$result['list'] = [];
@@ -262,7 +281,8 @@ function StudentToArray($list = []) : array {
}
function lastindex(){
function lastindex()
{
return empty($GLOBALS['data']['data']["lastindex"]) ? 0 : $GLOBALS['data']['data']["lastindex"];
}
@@ -270,13 +290,20 @@ function lastindex(){
if (! function_exists('getAllUsersMessage')) {
function getAllUsersMessage($list = [], $userIdField = "", $getFieldString = "")
{
if (empty($list)) return;
if (empty($list)) {
return;
}
$UserIds = [];
foreach ($list as $vo) $UserIds[] = $vo[$userIdField];
if (empty($UserIds)) return;
foreach ($list as $vo) {
$UserIds[] = $vo[$userIdField];
}
if (empty($UserIds)) {
return;
}
$UserIds = array_unique($UserIds);
$getAllUsersMessage = [];
$UserLists = Db::name("app_users")->where("id", "IN", $UserIds)->field($getFieldString)->select()->toArray();
$UserLists = Db::name("app_users")->where("id", "IN",
$UserIds)->field($getFieldString)->select()->toArray();
foreach ($UserLists as $vo) {
$getAllUsersMessage[$vo['id']] = $vo;
}