Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

79 rindas
2.4KB

  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 VoiceMsg(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[voice]]></MsgType>
  41. <Voice>
  42. <MediaId><![CDATA[{MediaId}]]></MediaId>
  43. </Voice>
  44. </xml>
  45. """
  46. return XmlForm.format(**self.__dict)
  47. class ImageMsg(Msg):
  48. def __init__(self, toUserName, fromUserName, mediaId):
  49. self.__dict = dict()
  50. self.__dict["ToUserName"] = toUserName
  51. self.__dict["FromUserName"] = fromUserName
  52. self.__dict["CreateTime"] = int(time.time())
  53. self.__dict["MediaId"] = mediaId
  54. def send(self):
  55. XmlForm = """
  56. <xml>
  57. <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
  58. <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
  59. <CreateTime>{CreateTime}</CreateTime>
  60. <MsgType><![CDATA[image]]></MsgType>
  61. <Image>
  62. <MediaId><![CDATA[{MediaId}]]></MediaId>
  63. </Image>
  64. </xml>
  65. """
  66. return XmlForm.format(**self.__dict)