Config.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace Qiniu;
  3. final class Config
  4. {
  5. const SDK_VER = '7.2.10';
  6. const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
  7. const RSF_HOST = 'rsf.qiniu.com';
  8. const API_HOST = 'api.qiniu.com';
  9. const RS_HOST = 'rs.qiniu.com'; //RS Host
  10. const UC_HOST = 'uc.qbox.me'; //UC Host
  11. const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
  12. const ARGUS_HOST = 'argus.atlab.ai';
  13. const CASTER_HOST = 'pili-caster.qiniuapi.com';
  14. const SMS_HOST="https://sms.qiniuapi.com";
  15. const RTCAPI_VERSION = 'v3';
  16. const SMS_VERSION='v1';
  17. // Zone 空间对应的存储区域
  18. public $region;
  19. //BOOL 是否使用https域名
  20. public $useHTTPS;
  21. //BOOL 是否使用CDN加速上传域名
  22. public $useCdnDomains;
  23. // Zone Cache
  24. private $regionCache;
  25. // 构造函数
  26. public function __construct(Region $z = null)
  27. {
  28. $this->zone = $z;
  29. $this->useHTTPS = false;
  30. $this->useCdnDomains = false;
  31. $this->regionCache = array();
  32. }
  33. public function getUpHost($accessKey, $bucket)
  34. {
  35. $region = $this->getRegion($accessKey, $bucket);
  36. if ($this->useHTTPS === true) {
  37. $scheme = "https://";
  38. } else {
  39. $scheme = "http://";
  40. }
  41. $host = $region->srcUpHosts[0];
  42. if ($this->useCdnDomains === true) {
  43. $host = $region->cdnUpHosts[0];
  44. }
  45. return $scheme . $host;
  46. }
  47. public function getUpBackupHost($accessKey, $bucket)
  48. {
  49. $region = $this->getRegion($accessKey, $bucket);
  50. if ($this->useHTTPS === true) {
  51. $scheme = "https://";
  52. } else {
  53. $scheme = "http://";
  54. }
  55. $host = $region->cdnUpHosts[0];
  56. if ($this->useCdnDomains === true) {
  57. $host = $region->srcUpHosts[0];
  58. }
  59. return $scheme . $host;
  60. }
  61. public function getRsHost($accessKey, $bucket)
  62. {
  63. $region = $this->getRegion($accessKey, $bucket);
  64. if ($this->useHTTPS === true) {
  65. $scheme = "https://";
  66. } else {
  67. $scheme = "http://";
  68. }
  69. return $scheme . $region->rsHost;
  70. }
  71. public function getRsfHost($accessKey, $bucket)
  72. {
  73. $region = $this->getRegion($accessKey, $bucket);
  74. if ($this->useHTTPS === true) {
  75. $scheme = "https://";
  76. } else {
  77. $scheme = "http://";
  78. }
  79. return $scheme . $region->rsfHost;
  80. }
  81. public function getIovipHost($accessKey, $bucket)
  82. {
  83. $region = $this->getRegion($accessKey, $bucket);
  84. if ($this->useHTTPS === true) {
  85. $scheme = "https://";
  86. } else {
  87. $scheme = "http://";
  88. }
  89. return $scheme . $region->iovipHost;
  90. }
  91. public function getApiHost($accessKey, $bucket)
  92. {
  93. $region = $this->getRegion($accessKey, $bucket);
  94. if ($this->useHTTPS === true) {
  95. $scheme = "https://";
  96. } else {
  97. $scheme = "http://";
  98. }
  99. return $scheme . $region->apiHost;
  100. }
  101. private function getRegion($accessKey, $bucket)
  102. {
  103. $cacheId = "$accessKey:$bucket";
  104. if (isset($this->regionCache[$cacheId])) {
  105. $region = $this->regionCache[$cacheId];
  106. } elseif (isset($this->zone)) {
  107. $region = $this->zone;
  108. $this->regionCache[$cacheId] = $region;
  109. } else {
  110. $region = Zone::queryZone($accessKey, $bucket);
  111. $this->regionCache[$cacheId] = $region;
  112. }
  113. return $region;
  114. }
  115. }