You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Commons;
  4. use Hyperf\HttpServer\Request;
  5. use Hyperf\Utils\Context;
  6. class LanzuRequest extends Request
  7. {
  8. // protected function getInputData(): array
  9. // {
  10. // return $this->storeParsedData(function () {
  11. // $request = $this->getRequest();
  12. // if (is_array($request->getParsedBody())) {
  13. // $data = $request->getParsedBody();
  14. // } else {
  15. // $data = [];
  16. // }
  17. // return array_merge($data, $request->getQueryParams());
  18. // });
  19. // }
  20. protected function storeParsedData(callable $callback)
  21. {
  22. if (! Context::has($this->contextkeys['parsedData'])) {
  23. return Context::set($this->contextkeys['parsedData'], call($callback));
  24. }
  25. // var_dump(Context::get($this->contextkeys['parsedData']));
  26. $preDatas = Context::get($this->contextkeys['parsedData']);
  27. if(isset($preDatas['market_id'])){
  28. if($preDatas['market_id']==-1){
  29. $preDatas['market_id'] = 0;
  30. unset($preDatas['sign']);
  31. $sign = $this->signature($preDatas);
  32. $preDatas['sign'] = $sign;
  33. Context::set($this->contextkeys['parsedData'],$preDatas);
  34. }
  35. }
  36. return Context::get($this->contextkeys['parsedData']);
  37. }
  38. private function signature($params)
  39. {
  40. ksort($params);
  41. $http_query = [];
  42. foreach ($params as $key => $value) {
  43. $http_query[] = $key.'='.$value;
  44. }
  45. return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key'));
  46. }
  47. }