From b02f6e50b8bb97f40349033f15a738a25860f828 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 8 Sep 2020 23:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=20=E4=B8=8D=E5=BD=B1=E5=93=8DValidationMiddl?= =?UTF-8?q?eware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Commons/LanzuRequest.php | 61 ++++++++++++++++++++++++++++++++ config/autoload/dependencies.php | 1 + 2 files changed, 62 insertions(+) create mode 100644 app/Commons/LanzuRequest.php diff --git a/app/Commons/LanzuRequest.php b/app/Commons/LanzuRequest.php new file mode 100644 index 0000000..38e4ce0 --- /dev/null +++ b/app/Commons/LanzuRequest.php @@ -0,0 +1,61 @@ +storeParsedData(function () { + // $request = $this->getRequest(); + // if (is_array($request->getParsedBody())) { + // $data = $request->getParsedBody(); + // } else { + // $data = []; + // } + + // return array_merge($data, $request->getQueryParams()); + // }); + // } + + protected function storeParsedData(callable $callback) + { + if (! Context::has($this->contextkeys['parsedData'])) { + return Context::set($this->contextkeys['parsedData'], call($callback)); + } + + // var_dump(Context::get($this->contextkeys['parsedData'])); + + $preDatas = Context::get($this->contextkeys['parsedData']); + + if(isset($preDatas['market_id'])){ + if($preDatas['market_id']==-1){ + $preDatas['market_id'] = 0; + unset($preDatas['sign']); + $sign = $this->signature($preDatas); + $preDatas['sign'] = $sign; + Context::set($this->contextkeys['parsedData'],$preDatas); + } + } + + return Context::get($this->contextkeys['parsedData']); + } + + private function signature($params) + { + ksort($params); + + $http_query = []; + foreach ($params as $key => $value) { + $http_query[] = $key.'='.$value; + } + + return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key')); + } +} diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 412b76d..949ae87 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -11,6 +11,7 @@ declare(strict_types=1); */ return [ + \Hyperf\HttpServer\Contract\RequestInterface::class => \App\Commons\LanzuRequest::class, \App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class, \App\Service\AttachmentServiceInterface::class => \App\Service\AttachmentService::class, \App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class,