main.py 662 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from wxbot import *
  4. def auto_reply(msg):
  5. body = {'key': '1d2678880f734bc0a23734ace8aec5b1', 'info':msg}
  6. r = requests.post("http://www.tuling123.com/openapi/api", data=body)
  7. resp = json.loads(r.text)
  8. if resp['code'] == 100000:
  9. return resp['text']
  10. else:
  11. return None
  12. class MyWXBot(WXBot):
  13. def handle_msg_all(self, msg):
  14. if msg['msg_type_id'] == 5:
  15. ans = auto_reply(msg['content'])
  16. self.send_msg(msg['user_name'], ans)
  17. def main():
  18. bot = MyWXBot()
  19. bot.DEBUG = True
  20. bot.run()
  21. if __name__ == '__main__':
  22. main()