No Description

ChangeMessageVisibilityResponse.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Exception\MnsException;
  5. use AliyunMNS\Exception\QueueNotExistException;
  6. use AliyunMNS\Exception\MessageNotExistException;
  7. use AliyunMNS\Exception\InvalidArgumentException;
  8. use AliyunMNS\Exception\ReceiptHandleErrorException;
  9. use AliyunMNS\Responses\BaseResponse;
  10. use AliyunMNS\Common\XMLParser;
  11. use AliyunMNS\Model\Message;
  12. class ChangeMessageVisibilityResponse extends BaseResponse
  13. {
  14. protected $receiptHandle;
  15. protected $nextVisibleTime;
  16. public function __construct()
  17. {
  18. }
  19. public function getReceiptHandle()
  20. {
  21. return $this->receiptHandle;
  22. }
  23. public function getNextVisibleTime()
  24. {
  25. return $this->nextVisibleTime;
  26. }
  27. public function parseResponse($statusCode, $content)
  28. {
  29. $this->statusCode = $statusCode;
  30. if ($statusCode == 200) {
  31. $this->succeed = TRUE;
  32. } else {
  33. $this->parseErrorResponse($statusCode, $content);
  34. }
  35. $xmlReader = $this->loadXmlContent($content);
  36. try {
  37. $message = Message::fromXML($xmlReader, TRUE);
  38. $this->receiptHandle = $message->getReceiptHandle();
  39. $this->nextVisibleTime = $message->getNextVisibleTime();
  40. } catch (\Exception $e) {
  41. throw new MnsException($statusCode, $e->getMessage(), $e);
  42. } catch (\Throwable $t) {
  43. throw new MnsException($statusCode, $t->getMessage());
  44. }
  45. }
  46. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  47. {
  48. $this->succeed = FALSE;
  49. $xmlReader = $this->loadXmlContent($content);
  50. try {
  51. $result = XMLParser::parseNormalError($xmlReader);
  52. if ($result['Code'] == Constants::INVALID_ARGUMENT)
  53. {
  54. throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  55. }
  56. if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
  57. {
  58. throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  59. }
  60. if ($result['Code'] == Constants::MESSAGE_NOT_EXIST)
  61. {
  62. throw new MessageNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  63. }
  64. if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
  65. {
  66. throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  67. }
  68. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  69. } catch (\Exception $e) {
  70. if ($exception != NULL) {
  71. throw $exception;
  72. } elseif($e instanceof MnsException) {
  73. throw $e;
  74. } else {
  75. throw new MnsException($statusCode, $e->getMessage());
  76. }
  77. } catch (\Throwable $t) {
  78. throw new MnsException($statusCode, $t->getMessage());
  79. }
  80. }
  81. }
  82. ?>