暂无描述

BatchSmsAttributes.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 BatchSmsAttributes
  11. {
  12. public $freeSignName;
  13. public $templateCode;
  14. public $smsParams;
  15. public function __construct(
  16. $freeSignName, $templateCode, $smsParams=null)
  17. {
  18. $this->freeSignName = $freeSignName;
  19. $this->templateCode = $templateCode;
  20. $this->smsParams = $smsParams;
  21. }
  22. public function setFreeSignName($freeSignName)
  23. {
  24. $this->freeSignName = $freeSignName;
  25. }
  26. public function getFreeSignName()
  27. {
  28. return $this->freeSignName;
  29. }
  30. public function setTemplateCode($templateCode)
  31. {
  32. $this->templateCode = $templateCode;
  33. }
  34. public function getTemplateCode()
  35. {
  36. return $this->templateCode;
  37. }
  38. public function addReceiver($phone, $params)
  39. {
  40. if (!is_array($params))
  41. {
  42. throw new MnsException(400, "Params Should be Array!");
  43. }
  44. if ($this->smsParams == null)
  45. {
  46. $this->smsParams = array();
  47. }
  48. $this->smsParams[$phone] = $params;
  49. }
  50. public function getSmsParams()
  51. {
  52. return $this->smsParams;
  53. }
  54. public function writeXML(\XMLWriter $xmlWriter)
  55. {
  56. $jsonArray = array("Type" => "multiContent");
  57. if ($this->freeSignName !== NULL)
  58. {
  59. $jsonArray[Constants::FREE_SIGN_NAME] = $this->freeSignName;
  60. }
  61. if ($this->templateCode !== NULL)
  62. {
  63. $jsonArray[Constants::TEMPLATE_CODE] = $this->templateCode;
  64. }
  65. if ($this->smsParams != null)
  66. {
  67. if (!is_array($this->smsParams))
  68. {
  69. throw new MnsException(400, "SmsParams should be an array!");
  70. }
  71. if (!empty($this->smsParams))
  72. {
  73. $jsonArray[Constants::SMS_PARAMS] = json_encode($this->smsParams, JSON_FORCE_OBJECT);
  74. }
  75. }
  76. if (!empty($jsonArray))
  77. {
  78. $xmlWriter->writeElement(Constants::DIRECT_SMS, json_encode($jsonArray));
  79. }
  80. }
  81. }
  82. ?>