From f3b174b7725bfdcb00bf1fd67734315573cecad9 Mon Sep 17 00:00:00 2001 From: zcy Date: Thu, 12 May 2022 15:44:26 +0800 Subject: [PATCH] sign --- app/Http/Controllers/OutController.php | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/OutController.php b/app/Http/Controllers/OutController.php index 64fe0a4..a97022b 100644 --- a/app/Http/Controllers/OutController.php +++ b/app/Http/Controllers/OutController.php @@ -10,7 +10,7 @@ class OutController extends Controller{ $msg = ''; try { $ts = $request->get('ts'); - $sign = $this->getSign($ts, 'get_config'); + $sign = $this->getSign('get_config',$ts ); if ($sign != $request->get('sign')) { $this->returnJson([], 400, "签名不对"); exit; @@ -34,15 +34,22 @@ class OutController extends Controller{ try { $ts = $request->get('ts'); - $sign = $this->getSign($ts, 'edit_config'); + $app_address = $request->post('app_address'); + $app_key = $request->post('app_key'); + $gui_address = $request->post('gui_address'); + + $arr = [ + 'app_address' => $app_address, + 'app_key' => $app_key, + 'gui_address' => $gui_address, + ]; + + $sign = $this->getSign('edit_config', $ts, $arr); if ($sign != $request->get('sign')) { $this->returnJson([], 400, "签名不对"); exit; } - $app_address=$request->post('app_address'); - $app_key=$request->post('app_key'); - $gui_address=$request->post('gui_address'); System::where(['id'=>1])->update( [ @@ -51,11 +58,7 @@ class OutController extends Controller{ 'gui_address' => $this->encry_data($gui_address), ] ); - $arr = [ - 'app_address' => $app_address, - 'app_key' => $app_key, - 'gui_address' => $gui_address, - ]; + $this->returnJson($arr); exit; @@ -65,13 +68,14 @@ class OutController extends Controller{ $this->returnJson([], 400, $msg); } - private function getSign($ts,$api): string + private function getSign($api,$ts,$arr=[]): string { $sinArr = [ - 'secret' => config('secret.sign_key') , + 'secret' => config('secret.sign_key'), 'ts' => $ts, 'api' => $api, ]; + $sinArr = array_merge($sinArr, $arr); $str = implode("|", $sinArr); return md5($str); }