No Description

GetAccountAttributesResponse.php 1.9KB

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