Нет описания

Subscription.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * 订阅/取消订阅标签.
  4. * @author wangkuiwei
  5. * @name Subscription
  6. *
  7. */
  8. namespace xmpush;
  9. class Subscription extends HttpBase {
  10. public function __construct() {
  11. parent::__construct();
  12. }
  13. public function subscribe($regId, $topic, $retries = 1) {
  14. $fields = array('registration_id' => $regId, 'topic' => $topic);
  15. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC(), $fields, $retries);
  16. }
  17. public function subscribeForRegids($regIdList, $topic, $retries = 1) {
  18. $jointRegIds = '';
  19. foreach ($regIdList as $regId) {
  20. if (isset($regId)) {
  21. $jointRegIds .= $regId . Constants::$comma;
  22. }
  23. }
  24. $fields = array('registration_id' => $jointRegIds, 'topic' => $topic);
  25. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC(), $fields, $retries);
  26. }
  27. public function unsubscribe($regId, $topic, $retries = 1) {
  28. $fields = array('registration_id' => $regId, 'topic' => $topic);
  29. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC(), $fields, $retries);
  30. }
  31. public function unsubscribeForRegids($regIdList, $topic, $retries = 1) {
  32. $jointRegIds = '';
  33. foreach ($regIdList as $regId) {
  34. if (isset($regId)) {
  35. $jointRegIds .= $regId . Constants::$comma;
  36. }
  37. }
  38. $fields = array('registration_id' => $jointRegIds, 'topic' => $topic);
  39. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC(), $fields, $retries);
  40. }
  41. public function subscribeTopicByAlias($aliasList, $topic, $retries = 1) {
  42. $jointAliases = '';
  43. foreach ($aliasList as $alias) {
  44. if (isset($alias)) {
  45. $jointAliases .= $alias . Constants::$comma;
  46. }
  47. }
  48. $fields = array('aliases' => $jointAliases, 'topic' => $topic);
  49. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC_BY_ALIAS(), $fields, $retries);
  50. }
  51. public function unsubscribeTopicByAlias($aliasList, $topic, $retries = 1) {
  52. $jointAliases = '';
  53. foreach ($aliasList as $alias) {
  54. if (isset($alias)) {
  55. $jointAliases .= $alias . Constants::$comma;
  56. }
  57. }
  58. $fields = array('aliases' => $jointAliases, 'topic' => $topic);
  59. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC_BY_ALIAS(), $fields, $retries);
  60. }
  61. public function subscribeByPackageName($regId, $topic, $packageName, $retries = 1) {
  62. $fields = array('registration_id' => $regId, 'topic' => $topic, 'restricted_package_name' => $packageName);
  63. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC(), $fields, $retries);
  64. }
  65. public function subscribeForRegidsByPackageName($regIdList, $topic, $packageName, $retries = 1) {
  66. $jointRegIds = '';
  67. foreach ($regIdList as $regId) {
  68. if (isset($regId)) {
  69. $jointRegIds .= $regId . Constants::$comma;
  70. }
  71. }
  72. $fields = array('registration_id' => $jointRegIds, 'topic' => $topic, 'restricted_package_name' => $packageName);
  73. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC(), $fields, $retries);
  74. }
  75. public function unsubscribeByPackageName($regId, $topic, $packageName, $retries = 1) {
  76. $fields = array('registration_id' => $regId, 'topic' => $topic, 'restricted_package_name' => $packageName);
  77. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC(), $fields, $retries);
  78. }
  79. public function unsubscribeForRegidsByPackageName($regIdList, $topic, $packageName, $retries = 1) {
  80. $jointRegIds = '';
  81. foreach ($regIdList as $regId) {
  82. if (isset($regId)) {
  83. $jointRegIds .= $regId . Constants::$comma;
  84. }
  85. }
  86. $fields = array('registration_id' => $jointRegIds, 'topic' => $topic, 'restricted_package_name' => $packageName);
  87. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC(), $fields, $retries);
  88. }
  89. public function subscribeTopicByPackageNameAlias($aliasList, $topic, $packageName, $retries = 1) {
  90. $jointAliases = '';
  91. foreach ($aliasList as $alias) {
  92. if (isset($alias)) {
  93. $jointAliases .= $alias . Constants::$comma;
  94. }
  95. }
  96. $fields = array('aliases' => $jointAliases, 'topic' => $topic, 'restricted_package_name' => $packageName);
  97. return $this->postResult(PushRequestPath::V2_SUBSCRIBE_TOPIC_BY_ALIAS(), $fields, $retries);
  98. }
  99. public function unsubscribeTopicByPackageNameAlias($aliasList, $topic, $packageName, $retries = 1) {
  100. $jointAliases = '';
  101. foreach ($aliasList as $alias) {
  102. if (isset($alias)) {
  103. $jointAliases .= $alias . Constants::$comma;
  104. }
  105. }
  106. $fields = array('aliases' => $jointAliases, 'topic' => $topic, 'restricted_package_name' => $packageName);
  107. return $this->postResult(PushRequestPath::V2_UNSUBSCRIBE_TOPIC_BY_ALIAS(), $fields, $retries);
  108. }
  109. }
  110. ?>