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