Нет описания

SmsAttributes.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace AliyunMNS\Model;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Exception\MnsException;
  5. /**
  6. * Please refer to
  7. * https://help.aliyun.com/document_detail/44501.html
  8. * for more details
  9. */
  10. class SmsAttributes
  11. {
  12. public $freeSignName;
  13. public $templateCode;
  14. public $smsParams;
  15. public $receiver;
  16. public function __construct(
  17. $freeSignName, $templateCode, $smsParams=array(), $receiver=null)
  18. {
  19. $this->freeSignName = $freeSignName;
  20. $this->templateCode = $templateCode;
  21. $this->smsParams = $smsParams;
  22. $this->receiver = $receiver;
  23. }
  24. public function setFreeSignName($freeSignName)
  25. {
  26. $this->freeSignName = $freeSignName;
  27. }
  28. public function getFreeSignName()
  29. {
  30. return $this->freeSignName;
  31. }
  32. public function setTemplateCode($templateCode)
  33. {
  34. $this->templateCode = $templateCode;
  35. }
  36. public function getTemplateCode()
  37. {
  38. return $this->templateCode;
  39. }
  40. public function setSmsParams($smsParams)
  41. {
  42. $this->smsParams = $smsParams;
  43. }
  44. public function getSmsParams()
  45. {
  46. return $this->smsParams;
  47. }
  48. public function setReceiver($receiver)
  49. {
  50. $this->receiver = $receiver;
  51. }
  52. public function getReceiver()
  53. {
  54. return $this->receiver;
  55. }
  56. public function writeXML(\XMLWriter $xmlWriter)
  57. {
  58. $jsonArray = array();
  59. if ($this->freeSignName !== NULL)
  60. {
  61. $jsonArray[Constants::FREE_SIGN_NAME] = $this->freeSignName;
  62. }
  63. if ($this->templateCode !== NULL)
  64. {
  65. $jsonArray[Constants::TEMPLATE_CODE] = $this->templateCode;
  66. }
  67. if ($this->receiver !== NULL)
  68. {
  69. $jsonArray[Constants::RECEIVER] = $this->receiver;
  70. }
  71. if ($this->smsParams !== null)
  72. {
  73. if (!is_array($this->smsParams))
  74. {
  75. throw new MnsException(400, "SmsParams should be an array!");
  76. }
  77. $jsonArray[Constants::SMS_PARAMS] = json_encode($this->smsParams, JSON_FORCE_OBJECT);
  78. }
  79. if (!empty($jsonArray))
  80. {
  81. $xmlWriter->writeElement(Constants::DIRECT_SMS, json_encode($jsonArray));
  82. }
  83. }
  84. }
  85. ?>