Sin descripción

PublishMessageRequest.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace AliyunMNS\Requests;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Requests\BaseRequest;
  5. use AliyunMNS\Traits\MessagePropertiesForPublish;
  6. class PublishMessageRequest extends BaseRequest
  7. {
  8. use MessagePropertiesForPublish;
  9. private $topicName;
  10. public function __construct($messageBody, $messageAttributes = NULL)
  11. {
  12. parent::__construct('post', NULL);
  13. $this->topicName = NULL;
  14. $this->messageBody = $messageBody;
  15. $this->messageAttributes = $messageAttributes;
  16. }
  17. public function setTopicName($topicName)
  18. {
  19. $this->topicName = $topicName;
  20. $this->resourcePath = 'topics/' . $topicName . '/messages';
  21. }
  22. public function getTopicName()
  23. {
  24. return $this->topicName;
  25. }
  26. public function generateBody()
  27. {
  28. $xmlWriter = new \XMLWriter;
  29. $xmlWriter->openMemory();
  30. $xmlWriter->startDocument("1.0", "UTF-8");
  31. $xmlWriter->startElementNS(NULL, "Message", Constants::MNS_XML_NAMESPACE);
  32. $this->writeMessagePropertiesForPublishXML($xmlWriter);
  33. $xmlWriter->endElement();
  34. $xmlWriter->endDocument();
  35. return $xmlWriter->outputMemory();
  36. }
  37. public function generateQueryString()
  38. {
  39. return NULL;
  40. }
  41. }
  42. ?>