From fee8635fb46b590c6d7745013eadd8c98236e453 Mon Sep 17 00:00:00 2001 From: suyi Date: Thu, 9 May 2024 13:47:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/app/functions.php b/server/app/functions.php index c08c5f6..d1445be 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -524,6 +524,10 @@ if (!function_exists('getAgreementHost')){ * @return array|string|null */ function getAgreementHost() { + //兼容脚本环境使用 + if (!request()){ + return getenv('SERVER_LISTEN','http://127.0.0.1'); + } if(!strstr(request()->host(), 'http://') && !strstr(request()->host(), 'https://')){ return request()->header('Scheme','http')."://".request()->host(); } -- Gitee From 51030a6113da4da6d34258d544bbe11d0d507490 Mon Sep 17 00:00:00 2001 From: suyi Date: Thu, 9 May 2024 13:48:57 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/scripts/importAdmin.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/scripts/importAdmin.php diff --git a/server/scripts/importAdmin.php b/server/scripts/importAdmin.php new file mode 100644 index 0000000..fa8e490 --- /dev/null +++ b/server/scripts/importAdmin.php @@ -0,0 +1,13 @@ +toArray(); + echo json_encode($adminLists); +} +main(); \ No newline at end of file -- Gitee From 45e62ae0c1af09912dd1511c5f0377bb98abdcfd Mon Sep 17 00:00:00 2001 From: suyi Date: Thu, 16 May 2024 16:22:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/common/service/UploadService.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server/app/common/service/UploadService.php b/server/app/common/service/UploadService.php index 619df9b..4e0bf7f 100644 --- a/server/app/common/service/UploadService.php +++ b/server/app/common/service/UploadService.php @@ -41,8 +41,14 @@ class UploadService // 上传文件 $saveDir = $saveDir . '/' . date('Ymd'); - if (!$StorageDriver->upload(public_path()."/".$saveDir)) { - throw new Exception($StorageDriver->getError()); + if ($config['default']=='local'){ + if (!$StorageDriver->upload(public_path()."/".$saveDir)) { + throw new Exception($StorageDriver->getError()); + } + }else{ + if (!$StorageDriver->upload($saveDir)) { + throw new Exception($StorageDriver->getError()); + } } // 3、处理文件名称 @@ -110,8 +116,14 @@ class UploadService // 上传文件 $saveDir = $saveDir . '/' . date('Ymd'); - if (!$StorageDriver->upload(public_path()."/".$saveDir)) { - throw new Exception($StorageDriver->getError()); + if ($config['default']=='local'){ + if (!$StorageDriver->upload(public_path()."/".$saveDir)) { + throw new Exception($StorageDriver->getError()); + } + }else{ + if (!$StorageDriver->upload($saveDir)) { + throw new Exception($StorageDriver->getError()); + } } // 3、处理文件名称 -- Gitee From 91cd1f3860531581ec7cd8ee86ea49a930d83b6f Mon Sep 17 00:00:00 2001 From: suyi Date: Thu, 16 May 2024 16:24:16 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/functions.php | 108 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/server/app/functions.php b/server/app/functions.php index d1445be..cdede71 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -533,4 +533,110 @@ if (!function_exists('getAgreementHost')){ } return request()->host(); } -} \ No newline at end of file +} +if (!function_exists('requestFormPost')){ + function requestFormPost(string $url,mixed $data,string|null &$error,$result_json_format = true,array $addHeaders = []): bool|array|string|null { + $headers = array('Content-Type: application/x-www-form-urlencoded'); + $headers = array_merge($headers,$addHeaders); + $curl = curl_init(); // 启动一个CURL会话 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, true); // 自动设置Referer + curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求 + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // Post提交的数据包 + curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $result = curl_exec($curl); // 执行操作 + if (curl_errno($curl)) { + $error = curl_error($curl);//捕抓异常 + return false; + } + curl_close($curl); // 关闭CURL会话 + if (!$result_json_format){ + return $result; + } + $json = json_decode($result,true); + if (!$json){ + $error = "json 格式化失败";//捕抓异常 + return false; + } + return $json; + } +} +if (!function_exists('requestJsonPost')){ + function requestJsonPost(string $url,mixed $data,string|null &$error,$result_json_format = true,array $addHeaders = []): bool|array|string|null { + $data_json = $data?:''; + if (is_array($data)){ + $data_json = json_encode($data); // 将数据编码为JSON + } + $headers = array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json)); + $headers = array_merge($headers,$addHeaders); + $curl = curl_init(); // 初始化cURL会话 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, true); // 自动设置Referer + curl_setopt($curl, CURLOPT_POST, true); // 设置cURL选项,进行POST请求 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); // 设置cURL选项,POST发送的数据 + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // 设置HTTP头部信息 + curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 + $result = curl_exec($curl); // 执行操作 + if (curl_errno($curl)) { + $error = curl_error($curl);//捕抓异常 + return false; + } + curl_close($curl); // 关闭CURL会话 + if (!$result_json_format){ + return $result; + } + $json = json_decode($result,true); + if (!$json){ + $error = "json 格式化失败";//捕抓异常 + return false; + } + return $json; + } +} +if (!function_exists('requestGet')){ + function requestGet(string $url,mixed $data,string|null &$error,$result_json_format = true,array $addHeaders = []):bool|array|string|null{ + $params = $data; + if (is_array($data)){ + $params = http_build_query($data); + } + $req_url = $url.'?'.$params; + $curl = curl_init(); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($curl, CURLOPT_URL, $req_url); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, true); // 自动设置Referer + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //获取的信息以文件流的形式返回 + curl_setopt($curl, CURLOPT_HEADER, false);//设置不要返回头 + curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_HTTPHEADER, $addHeaders); // 设置HTTP头部信息 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 + + $result = curl_exec($curl); // 执行操作 + if (curl_errno($curl)) { + $error = curl_error($curl);//捕抓异常 + return false; + } + curl_close($curl); // 关闭CURL会话 + if (!$result_json_format){ + return $result; + } + $json = json_decode($result,true); + if (!$json){ + $error = "json 格式化失败";//捕抓异常 + return false; + } + return $json; + } -- Gitee