No Description

SendMessageResponse.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Exception\MnsException;
  5. use AliyunMNS\Exception\QueueNotExistException;
  6. use AliyunMNS\Exception\InvalidArgumentException;
  7. use AliyunMNS\Exception\MalformedXMLException;
  8. use AliyunMNS\Responses\BaseResponse;
  9. use AliyunMNS\Common\XMLParser;
  10. use AliyunMNS\Traits\MessageIdAndMD5;
  11. class SendMessageResponse extends BaseResponse
  12. {
  13. use MessageIdAndMD5;
  14. public function __construct()
  15. {
  16. }
  17. public function parseResponse($statusCode, $content)
  18. {
  19. $this->statusCode = $statusCode;
  20. if ($statusCode == 201) {
  21. $this->succeed = TRUE;
  22. } else {
  23. $this->parseErrorResponse($statusCode, $content);
  24. }
  25. $xmlReader = $this->loadXmlContent($content);
  26. try {
  27. $this->readMessageIdAndMD5XML($xmlReader);
  28. } catch (\Exception $e) {
  29. throw new MnsException($statusCode, $e->getMessage(), $e);
  30. } catch (\Throwable $t) {
  31. throw new MnsException($statusCode, $t->getMessage());
  32. }
  33. }
  34. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  35. {
  36. $this->succeed = FALSE;
  37. $xmlReader = $this->loadXmlContent($content);
  38. try {
  39. $result = XMLParser::parseNormalError($xmlReader);
  40. if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
  41. {
  42. throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  43. }
  44. if ($result['Code'] == Constants::INVALID_ARGUMENT)
  45. {
  46. throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  47. }
  48. if ($result['Code'] == Constants::MALFORMED_XML)
  49. {
  50. throw new MalformedXMLException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  51. }
  52. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  53. } catch (\Exception $e) {
  54. if ($exception != NULL) {
  55. throw $exception;
  56. } elseif($e instanceof MnsException) {
  57. throw $e;
  58. } else {
  59. throw new MnsException($statusCode, $e->getMessage());
  60. }
  61. } catch (\Throwable $t) {
  62. throw new MnsException($statusCode, $t->getMessage());
  63. }
  64. }
  65. }
  66. ?>