BatchSendMessageRequest.php
1.8 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
<?php
namespace AliyunMNS\Requests;
use AliyunMNS\Constants;
use AliyunMNS\Requests\BaseRequest;
use AliyunMNS\Model\SendMessageRequestItem;
class BatchSendMessageRequest extends BaseRequest
{
protected $queueName;
protected $sendMessageRequestItems;
// boolean, whether the message body will be encoded in base64
protected $base64;
public function __construct(array $sendMessageRequestItems, $base64 = TRUE)
{
parent::__construct('post', NULL);
$this->queueName = NULL;
$this->sendMessageRequestItems = $sendMessageRequestItems;
$this->base64 = $base64;
}
public function setBase64($base64)
{
$this->base64 = $base64;
}
public function isBase64()
{
return ($this->base64 == TRUE);
}
public function setQueueName($queueName)
{
$this->queueName = $queueName;
$this->resourcePath = 'queues/' . $queueName . '/messages';
}
public function getQueueName()
{
return $this->queueName;
}
public function getSendMessageRequestItems()
{
return $this->sendMessageRequestItems;
}
public function addSendMessageRequestItem(SendMessageRequestItem $item)
{
$this->sendMessageRequestItems[] = $item;
}
public function generateBody()
{
$xmlWriter = new \XMLWriter;
$xmlWriter->openMemory();
$xmlWriter->startDocument("1.0", "UTF-8");
$xmlWriter->startElementNS(NULL, "Messages", Constants::MNS_XML_NAMESPACE);
foreach ($this->sendMessageRequestItems as $item)
{
$item->writeXML($xmlWriter, $this->base64);
}
$xmlWriter->endElement();
$xmlWriter->endDocument();
return $xmlWriter->outputMemory();
}
public function generateQueryString()
{
return NULL;
}
}
?>