CommonParams.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CatchAdmin [Just Like ~ ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2020 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;
  12. use catchAdmin\domain\support\signature\Aliyun;
  13. use catchAdmin\domain\support\signature\Qcloud;
  14. /**
  15. * 公共参数
  16. *
  17. * Class CommonParams
  18. * @package catchAdmin\domain\support
  19. */
  20. class CommonParams
  21. {
  22. /**
  23. * 阿里云公共参数
  24. *
  25. * @param array $params
  26. * @param string $method
  27. * @return array
  28. */
  29. public static function aliyun(array $params, $method = 'GET')
  30. {
  31. date_default_timezone_set('UTC');
  32. $params = array_merge($params, [
  33. 'Format' => 'json',
  34. 'Version' => '2015-01-09',
  35. 'AccessKeyId' => config('catch.domains.aliyun.access_key'),
  36. 'SignatureMethod' => 'HMAC-SHA1',
  37. 'Timestamp' => date('Y-m-d\TH:i:s\Z'),
  38. 'SignatureVersion' => '1.0',
  39. 'SignatureNonce' => uniqid()
  40. ]);
  41. $params['Signature'] = (new Aliyun($params))->signature($method);
  42. return $params;
  43. }
  44. /**
  45. * 腾讯云公共参数
  46. *
  47. * @param array $params
  48. * @param string $method
  49. * @return array
  50. */
  51. public static function qcloud(array $params, $method = 'GET')
  52. {
  53. $params = array_merge($params, [
  54. 'SecretId' => config('catch.domains.qcloud.access_key'),
  55. 'SignatureMethod' => 'HmacSHA1',
  56. 'Timestamp' => time(),
  57. 'Nonce' => uniqid()
  58. ]);
  59. $params['Signature'] = (new Qcloud($params))->signature($method);
  60. return $params;
  61. }
  62. }