AlipayOpenPublicMessageCustomSendModel.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. from alipay.aop.api.domain.Article import Article
  6. from alipay.aop.api.domain.Text import Text
  7. class AlipayOpenPublicMessageCustomSendModel(object):
  8. def __init__(self):
  9. self._articles = None
  10. self._chat = None
  11. self._event_type = None
  12. self._msg_type = None
  13. self._text = None
  14. self._to_user_id = None
  15. @property
  16. def articles(self):
  17. return self._articles
  18. @articles.setter
  19. def articles(self, value):
  20. if isinstance(value, list):
  21. self._articles = list()
  22. for i in value:
  23. if isinstance(i, Article):
  24. self._articles.append(i)
  25. else:
  26. self._articles.append(Article.from_alipay_dict(i))
  27. @property
  28. def chat(self):
  29. return self._chat
  30. @chat.setter
  31. def chat(self, value):
  32. self._chat = value
  33. @property
  34. def event_type(self):
  35. return self._event_type
  36. @event_type.setter
  37. def event_type(self, value):
  38. self._event_type = value
  39. @property
  40. def msg_type(self):
  41. return self._msg_type
  42. @msg_type.setter
  43. def msg_type(self, value):
  44. self._msg_type = value
  45. @property
  46. def text(self):
  47. return self._text
  48. @text.setter
  49. def text(self, value):
  50. if isinstance(value, Text):
  51. self._text = value
  52. else:
  53. self._text = Text.from_alipay_dict(value)
  54. @property
  55. def to_user_id(self):
  56. return self._to_user_id
  57. @to_user_id.setter
  58. def to_user_id(self, value):
  59. self._to_user_id = value
  60. def to_alipay_dict(self):
  61. params = dict()
  62. if self.articles:
  63. if isinstance(self.articles, list):
  64. for i in range(0, len(self.articles)):
  65. element = self.articles[i]
  66. if hasattr(element, 'to_alipay_dict'):
  67. self.articles[i] = element.to_alipay_dict()
  68. if hasattr(self.articles, 'to_alipay_dict'):
  69. params['articles'] = self.articles.to_alipay_dict()
  70. else:
  71. params['articles'] = self.articles
  72. if self.chat:
  73. if hasattr(self.chat, 'to_alipay_dict'):
  74. params['chat'] = self.chat.to_alipay_dict()
  75. else:
  76. params['chat'] = self.chat
  77. if self.event_type:
  78. if hasattr(self.event_type, 'to_alipay_dict'):
  79. params['event_type'] = self.event_type.to_alipay_dict()
  80. else:
  81. params['event_type'] = self.event_type
  82. if self.msg_type:
  83. if hasattr(self.msg_type, 'to_alipay_dict'):
  84. params['msg_type'] = self.msg_type.to_alipay_dict()
  85. else:
  86. params['msg_type'] = self.msg_type
  87. if self.text:
  88. if hasattr(self.text, 'to_alipay_dict'):
  89. params['text'] = self.text.to_alipay_dict()
  90. else:
  91. params['text'] = self.text
  92. if self.to_user_id:
  93. if hasattr(self.to_user_id, 'to_alipay_dict'):
  94. params['to_user_id'] = self.to_user_id.to_alipay_dict()
  95. else:
  96. params['to_user_id'] = self.to_user_id
  97. return params
  98. @staticmethod
  99. def from_alipay_dict(d):
  100. if not d:
  101. return None
  102. o = AlipayOpenPublicMessageCustomSendModel()
  103. if 'articles' in d:
  104. o.articles = d['articles']
  105. if 'chat' in d:
  106. o.chat = d['chat']
  107. if 'event_type' in d:
  108. o.event_type = d['event_type']
  109. if 'msg_type' in d:
  110. o.msg_type = d['msg_type']
  111. if 'text' in d:
  112. o.text = d['text']
  113. if 'to_user_id' in d:
  114. o.to_user_id = d['to_user_id']
  115. return o