CdnRepository.php 766 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Repositories\Utils;
  3. use Carbon\Carbon;
  4. class CdnRepository
  5. {
  6. /**
  7. * 主密码
  8. * @var string
  9. */
  10. protected $key1 = 'AwMnF1TSnIvyhmC9';
  11. /**
  12. * 辅密码
  13. * @var string
  14. */
  15. protected $key2 = 'g84alOZMtOrU3C2e';
  16. /**
  17. * 获取鉴权query参数key=value
  18. * @param $fileRelativePath
  19. * @return string
  20. */
  21. public function getSignKeyValue($fileRelativePath)
  22. {
  23. // 过期时间,这里设置3小时后的timestamp.
  24. $expiredTime = Carbon::now()->addHours(3)->timestamp;
  25. $sstring = $fileRelativePath."-".$expiredTime."-0-0-".$this->key1;
  26. $md5 = md5($sstring);
  27. $authKey = "auth_key=".$expiredTime."-0-0-".$md5;
  28. return $authKey;
  29. }
  30. }