No Description

SubscribeResponse.php 2.0KB

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