Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

42 lines
1.5KB

  1. # -*- coding: utf-8 -*-#
  2. # filename: receive.py
  3. import xml.etree.ElementTree as ET
  4. from bridge.context import ContextType
  5. from channel.chat_message import ChatMessage
  6. from common.log import logger
  7. def parse_xml(web_data):
  8. if len(web_data) == 0:
  9. return None
  10. xmlData = ET.fromstring(web_data)
  11. return WeChatMPMessage(xmlData)
  12. class WeChatMPMessage(ChatMessage):
  13. def __init__(self, xmlData):
  14. super().__init__(xmlData)
  15. self.to_user_id = xmlData.find('ToUserName').text
  16. self.from_user_id = xmlData.find('FromUserName').text
  17. self.create_time = xmlData.find('CreateTime').text
  18. self.msg_type = xmlData.find('MsgType').text
  19. self.msg_id = xmlData.find('MsgId').text
  20. self.is_group = False
  21. # reply to other_user_id
  22. self.other_user_id = self.from_user_id
  23. if self.msg_type == 'text':
  24. self.ctype = ContextType.TEXT
  25. self.content = xmlData.find('Content').text.encode("utf-8")
  26. elif self.msg_type == 'voice':
  27. self.ctype = ContextType.TEXT
  28. self.content = xmlData.find('Recognition').text.encode("utf-8") # 接收语音识别结果
  29. elif self.msg_type == 'image':
  30. # not implemented
  31. self.pic_url = xmlData.find('PicUrl').text
  32. self.media_id = xmlData.find('MediaId').text
  33. elif self.msg_type == 'event':
  34. self.event = xmlData.find('Event').text
  35. else: # video, shortvideo, location, link
  36. # not implemented
  37. pass