From c8fed356b92324af4684505428f7226f9a2e886b Mon Sep 17 00:00:00 2001 From: weiz Date: Fri, 10 Nov 2023 11:19:26 +0800 Subject: [PATCH] update --- app/api/config/route.php | 1 - .../http/middleware/VerifySignMiddleware.php | 41 ------------------- app/common.php | 16 ++++++++ 3 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 app/api/http/middleware/VerifySignMiddleware.php diff --git a/app/api/config/route.php b/app/api/config/route.php index 4f75ebd5..e6a26425 100644 --- a/app/api/config/route.php +++ b/app/api/config/route.php @@ -14,7 +14,6 @@ return [ 'middleware' => [ app\api\http\middleware\InitMiddleware::class, // 初始化 - app\api\http\middleware\VerifySignMiddleware::class, // 签名验证 app\api\http\middleware\LoginMiddleware::class, // 登录验证 ], ]; diff --git a/app/api/http/middleware/VerifySignMiddleware.php b/app/api/http/middleware/VerifySignMiddleware.php deleted file mode 100644 index 8dc37c90..00000000 --- a/app/api/http/middleware/VerifySignMiddleware.php +++ /dev/null @@ -1,41 +0,0 @@ -header('appid'); -// $url = $request->header('url'); -// $timestamp = $request->header('timestamp'); -// $sign = $request->header('sign'); -// //验证参数 -// if(empty($appid) || empty($url) || empty($timestamp) || empty($sign)){ -// return JsonService::fail('缺少请求头参数', [], 0); -// } -// //获取子系统信息 -// $system = System::field('app_id,app_key,url,status')->where('app_id',$appid)->where('url',$url)->findOrEmpty(); -// if($system->isEmpty()){ -// return JsonService::fail('应用ID无效', [], 0); -// } -// if($url != $system['url']){ -// return JsonService::fail('请求来源异常', [], 0); -// } -// if($system['status'] != 0){ -// return JsonService::fail('应用已被禁用或注销', [], 0); -// } -// //验证签名 -// $checkSign = ApiSignService::verifySign(['appid'=>$appid,'url'=>$url,'timestamp'=>$timestamp,'sign'=>$sign],$system['app_key']); -// if($checkSign['code'] == 0){ -// return JsonService::fail($checkSign['msg'],[],0); -// } - return $next($request); - } -} \ No newline at end of file diff --git a/app/common.php b/app/common.php index 5cdbfadc..50a59ba9 100644 --- a/app/common.php +++ b/app/common.php @@ -354,3 +354,19 @@ function curl_get($url){ curl_close($ch); return json_decode($output,true); } + +function makeSign($data,$appSecret): string +{ + ksort($data); + $string = ""; + foreach ($data as $k => $v) { + if ($k == "sign" || is_array($v)) { + continue; + } + $string .= $k . "=" . $v . "&"; + } + $string = trim($string, "&"); + $string = $string . "&key=" . $appSecret; + $string = md5(md5($string)); + return strtolower($string); +}