Qcloud.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CatchAdmin [Just Like ~ ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
  8. // +----------------------------------------------------------------------
  9. // | Author: JaguarJack [ njphper@gmail.com ]
  10. // +----------------------------------------------------------------------
  11. namespace catchAdmin\domain\support\signature;
  12. class Qcloud
  13. {
  14. /**
  15. * @var array
  16. */
  17. protected $params;
  18. /**
  19. * Qcloud constructor.
  20. * @param $params
  21. */
  22. public function __construct(array $params)
  23. {
  24. $this->params = $params;
  25. }
  26. /**
  27. * key 替换
  28. *
  29. * @param $key
  30. * @return mixed|string|string[]
  31. */
  32. protected function replaceKey($key)
  33. {
  34. return strpos($key, '_') === false ?
  35. $key : str_replace('_', '.', $key);
  36. }
  37. /**
  38. * 签名
  39. *
  40. * @time 2020年09月25日
  41. * @param $method
  42. * @return string
  43. */
  44. public function signature(string $method)
  45. {
  46. ksort($this->params);
  47. $queryString = '';
  48. foreach ($this->params as $key => $param) {
  49. $queryString .= '&' . $this->replaceKey($key) . '=' . $param;
  50. }
  51. $signString = $method . config('catch.domains.qcloud.api_domain') . '/v2/index.php?'
  52. . substr($queryString, 1);
  53. return base64_encode(hash_hmac('sha1', $signString, config('catch.domains.qcloud.access_secret'), true));
  54. }
  55. }