Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

52 lines
1.7KB

  1. # -*- coding: utf-8 -*-#
  2. # filename: reply.py
  3. import time
  4. class Msg(object):
  5. def __init__(self):
  6. pass
  7. def send(self):
  8. return "success"
  9. class TextMsg(Msg):
  10. def __init__(self, toUserName, fromUserName, content):
  11. self.__dict = dict()
  12. self.__dict['ToUserName'] = toUserName
  13. self.__dict['FromUserName'] = fromUserName
  14. self.__dict['CreateTime'] = int(time.time())
  15. self.__dict['Content'] = content
  16. def send(self):
  17. XmlForm = """
  18. <xml>
  19. <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
  20. <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
  21. <CreateTime>{CreateTime}</CreateTime>
  22. <MsgType><![CDATA[text]]></MsgType>
  23. <Content><![CDATA[{Content}]]></Content>
  24. </xml>
  25. """
  26. return XmlForm.format(**self.__dict)
  27. class ImageMsg(Msg):
  28. def __init__(self, toUserName, fromUserName, mediaId):
  29. self.__dict = dict()
  30. self.__dict['ToUserName'] = toUserName
  31. self.__dict['FromUserName'] = fromUserName
  32. self.__dict['CreateTime'] = int(time.time())
  33. self.__dict['MediaId'] = mediaId
  34. def send(self):
  35. XmlForm = """
  36. <xml>
  37. <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
  38. <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
  39. <CreateTime>{CreateTime}</CreateTime>
  40. <MsgType><![CDATA[image]]></MsgType>
  41. <Image>
  42. <MediaId><![CDATA[{MediaId}]]></MediaId>
  43. </Image>
  44. </xml>
  45. """
  46. return XmlForm.format(**self.__dict)