Geen omschrijving

Topic.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace AliyunMNS;
  3. use AliyunMNS\Http\HttpClient;
  4. use AliyunMNS\AsyncCallback;
  5. use AliyunMNS\Model\TopicAttributes;
  6. use AliyunMNS\Model\SubscriptionAttributes;
  7. use AliyunMNS\Model\UpdateSubscriptionAttributes;
  8. use AliyunMNS\Requests\SetTopicAttributeRequest;
  9. use AliyunMNS\Responses\SetTopicAttributeResponse;
  10. use AliyunMNS\Requests\GetTopicAttributeRequest;
  11. use AliyunMNS\Responses\GetTopicAttributeResponse;
  12. use AliyunMNS\Requests\PublishMessageRequest;
  13. use AliyunMNS\Responses\PublishMessageResponse;
  14. use AliyunMNS\Requests\SubscribeRequest;
  15. use AliyunMNS\Responses\SubscribeResponse;
  16. use AliyunMNS\Requests\UnsubscribeRequest;
  17. use AliyunMNS\Responses\UnsubscribeResponse;
  18. use AliyunMNS\Requests\GetSubscriptionAttributeRequest;
  19. use AliyunMNS\Responses\GetSubscriptionAttributeResponse;
  20. use AliyunMNS\Requests\SetSubscriptionAttributeRequest;
  21. use AliyunMNS\Responses\SetSubscriptionAttributeResponse;
  22. use AliyunMNS\Requests\ListSubscriptionRequest;
  23. use AliyunMNS\Responses\ListSubscriptionResponse;
  24. class Topic
  25. {
  26. private $topicName;
  27. private $client;
  28. public function __construct(HttpClient $client, $topicName)
  29. {
  30. $this->client = $client;
  31. $this->topicName = $topicName;
  32. }
  33. public function getTopicName()
  34. {
  35. return $this->topicName;
  36. }
  37. public function setAttribute(TopicAttributes $attributes)
  38. {
  39. $request = new SetTopicAttributeRequest($this->topicName, $attributes);
  40. $response = new SetTopicAttributeResponse();
  41. return $this->client->sendRequest($request, $response);
  42. }
  43. public function getAttribute()
  44. {
  45. $request = new GetTopicAttributeRequest($this->topicName);
  46. $response = new GetTopicAttributeResponse();
  47. return $this->client->sendRequest($request, $response);
  48. }
  49. public function generateQueueEndpoint($queueName)
  50. {
  51. return "acs:mns:" . $this->client->getRegion() . ":" . $this->client->getAccountId() . ":queues/" . $queueName;
  52. }
  53. public function generateMailEndpoint($mailAddress)
  54. {
  55. return "mail:directmail:" . $mailAddress;
  56. }
  57. public function generateSmsEndpoint($phone = null)
  58. {
  59. if ($phone)
  60. {
  61. return "sms:directsms:" . $phone;
  62. }
  63. else
  64. {
  65. return "sms:directsms:anonymous";
  66. }
  67. }
  68. public function generateBatchSmsEndpoint()
  69. {
  70. return "sms:directsms:anonymous";
  71. }
  72. public function publishMessage(PublishMessageRequest $request)
  73. {
  74. $request->setTopicName($this->topicName);
  75. $response = new PublishMessageResponse();
  76. return $this->client->sendRequest($request, $response);
  77. }
  78. public function subscribe(SubscriptionAttributes $attributes)
  79. {
  80. $attributes->setTopicName($this->topicName);
  81. $request = new SubscribeRequest($attributes);
  82. $response = new SubscribeResponse();
  83. return $this->client->sendRequest($request, $response);
  84. }
  85. public function unsubscribe($subscriptionName)
  86. {
  87. $request = new UnsubscribeRequest($this->topicName, $subscriptionName);
  88. $response = new UnsubscribeResponse();
  89. return $this->client->sendRequest($request, $response);
  90. }
  91. public function getSubscriptionAttribute($subscriptionName)
  92. {
  93. $request = new GetSubscriptionAttributeRequest($this->topicName, $subscriptionName);
  94. $response = new GetSubscriptionAttributeResponse();
  95. return $this->client->sendRequest($request, $response);
  96. }
  97. public function setSubscriptionAttribute(UpdateSubscriptionAttributes $attributes)
  98. {
  99. $attributes->setTopicName($this->topicName);
  100. $request = new SetSubscriptionAttributeRequest($attributes);
  101. $response = new SetSubscriptionAttributeResponse();
  102. return $this->client->sendRequest($request, $response);
  103. }
  104. public function listSubscription($retNum = NULL, $prefix = NULL, $marker = NULL)
  105. {
  106. $request = new ListSubscriptionRequest($this->topicName, $retNum, $prefix, $marker);
  107. $response = new ListSubscriptionResponse();
  108. return $this->client->sendRequest($request, $response);
  109. }
  110. }
  111. ?>