説明なし

Constants.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * 常量定义.
  4. * @author wangkuiwei
  5. * @name Constants
  6. * @desc 常量定义
  7. *
  8. */
  9. namespace xmpush;
  10. class Constants {
  11. public static $domain = 'https://api.xmpush.xiaomi.com';
  12. public static $comma = ',';
  13. public static $multi_topic_split = ';$;';
  14. public static $packageName = '';
  15. public static $bundle_id = '';
  16. public static $secret = '';
  17. /**
  18. * 是否在网络访问问题时,自动切换访问的域名
  19. */
  20. public static $autoSwitchHost = true;
  21. /**
  22. * 网络访问的超时时间,当超过该时间时,则认为可用性较低,会优先选择其他域名
  23. */
  24. public static $accessTimeOut = 5000;
  25. public static $HTTP_PROTOCOL = "https";
  26. public static $USE_HTTPS = true;
  27. /**
  28. * 是否测试环境
  29. */
  30. public static $sandbox = false;
  31. /**
  32. * 如果设置了IP、域名,则使用手动设置的值,只用于内部测试,不对外开放
  33. */
  34. /**
  35. * @return string
  36. */
  37. public static $host = null;
  38. const reg_url = '/v3/message/regid';
  39. const alias_url = '/v3/message/alias';
  40. const user_account_url = '/v2/message/user_account';
  41. const topic_url = '/v3/message/topic';
  42. const multi_topic_url = '/v3/message/multi_topic';
  43. const all_url = '/v3/message/all';
  44. const multi_messages_regids_url = '/v2/multi_messages/regids';
  45. const multi_messages_aliases_url = '/v2/multi_messages/aliases';
  46. const multi_messages_user_accounts_url = '/v2/multi_messages/user_accounts';
  47. const stats_url = '/v1/stats/message/counters';
  48. const message_trace_url = '/v1/trace/message/status';
  49. const messages_trace_url = '/v1/trace/messages/status';
  50. const validation_regids_url = '/v1/validation/regids';
  51. const subscribe_url = '/v2/topic/subscribe';
  52. const unsubscribe_url = '/v2/topic/unsubscribe';
  53. const subscribe_alias_url = '/v2/topic/subscribe/alias';
  54. const unsubscribe_alias_url = '/v2/topic/unsubscribe/alias';
  55. const fetch_invalid_regids_url = 'https://feedback.xmpush.xiaomi.com/v1/feedback/fetch_invalid_regids';
  56. const delete_schedule_job = '/v2/schedule_job/delete';
  57. const check_schedule_job_exist = '/v2/schedule_job/exist';
  58. const get_all_aliases = '/v1/alias/all';
  59. const get_all_topics = '/v1/topic/all';
  60. const UNION = 'UNION';
  61. const INTERSECTION = 'INTERSECTION';
  62. const EXCEPT = 'EXCEPT';
  63. /**
  64. * 相关域名定义
  65. */
  66. const HOST_EMQ = "emq.xmpush.xiaomi.com";
  67. const HOST_SANDBOX = "sandbox.xmpush.xiaomi.com";
  68. const HOST_PRODUCTION = "api.xmpush.xiaomi.com";
  69. const HOST_PRODUCTION_B1 = "lg.api.xmpush.xiaomi.com";
  70. const HOST_PRODUCTION_B2 = "c3.api.xmpush.xiaomi.com";
  71. const HOST_PRODUCTION_FEEDBACK = "feedback.xmpush.xiaomi.com";
  72. const X_PUSH_HOST_LIST = "X-PUSH-HOST-LIST";
  73. const HOST_RESPONSE_EXPECT_TIME = 5; // 响应时间低于这个值,host降权
  74. const X_PUSH_SDK_VERSION = "X-PUSH-SDK-VERSION";
  75. const SDK_VERSION = "PHP_SDK_V2.2.20";
  76. const EXTRA_PARAM_NOTIFY_EFFECT = "notify_effect";
  77. const NOTIFY_LAUNCHER_ACTIVITY = "1";
  78. const NOTIFY_ACTIVITY = "2";
  79. const NOTIFY_WEB = "3";
  80. const EXTRA_PARAM_INTENT_URI = "intent_uri";
  81. const EXTRA_PARAM_WEB_URI = "web_uri";
  82. public static function setPackage($package) {
  83. self::$packageName = $package;
  84. }
  85. public static function setSecret($secret) {
  86. self::$secret = $secret;
  87. }
  88. public static function setBundleId($bundleId) {
  89. self::$bundle_id = $bundleId;
  90. }
  91. public static function useOfficial() {
  92. self::$domain = 'https://api.xmpush.xiaomi.com';
  93. self::$sandbox = false;
  94. self::$host = null;
  95. }
  96. public static function useSandbox() {
  97. self::$domain = 'https://sandbox.xmpush.xiaomi.com';
  98. self::$sandbox = true;
  99. self::$host = null;
  100. }
  101. /**
  102. * 仅限内部使用,用户测试专门的IP
  103. */
  104. public static function useInternalHost($hostOrIP) {
  105. self::$host = $hostOrIP;
  106. }
  107. public static function useHttp() {
  108. self::$HTTP_PROTOCOL = "http";
  109. }
  110. }
  111. ?>