Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

receive.py 1.5KB

1 rok temu
1 rok temu
1 rok temu
1 rok temu
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.tmp_dir import TmpDir
  7. from common.log import logger
  8. def parse_xml(web_data):
  9. if len(web_data) == 0:
  10. return None
  11. xmlData = ET.fromstring(web_data)
  12. return WeChatMPMessage(xmlData)
  13. class WeChatMPMessage(ChatMessage):
  14. def __init__(self, xmlData):
  15. super().__init__(xmlData)
  16. self.to_user_id = xmlData.find('ToUserName').text
  17. self.from_user_id = xmlData.find('FromUserName').text
  18. self.create_time = xmlData.find('CreateTime').text
  19. self.msg_type = xmlData.find('MsgType').text
  20. self.msg_id = xmlData.find('MsgId').text
  21. self.is_group = False
  22. # reply to other_user_id
  23. self.other_user_id = self.from_user_id
  24. if self.msg_type == 'text':
  25. self.ctype = ContextType.TEXT
  26. self.content = xmlData.find('Content').text.encode("utf-8")
  27. elif self.msg_type == 'voice':
  28. self.ctype = ContextType.TEXT
  29. self.content = xmlData.find('Recognition').text.encode("utf-8") # 接收语音识别结果
  30. elif self.msg_type == 'image':
  31. # not implemented
  32. self.pic_url = xmlData.find('PicUrl').text
  33. self.media_id = xmlData.find('MediaId').text
  34. elif self.msg_type == 'event':
  35. self.event = xmlData.find('Event').text
  36. else: # video, shortvideo, location, link
  37. # not implemented
  38. pass