talk.py 967 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/eny python
  2. # _*_coding:utf-8_*_
  3. import requests
  4. import json
  5. def talk(content, userId):
  6. url = 'http://www.tuling123.com/openapi/api';
  7. s = requests.session()
  8. d = {"key": "653fd927e9ad4b19bbbb58ac07545d9a", "info": content, "userid": userId}
  9. data = json.dumps(d)
  10. r = s.post(url, data=data)
  11. text = json.loads(r.text)
  12. if text['code'] == 100000:
  13. return text['text']
  14. elif text['code'] == 200000:
  15. return text['text'] + '\n' + text['url']
  16. elif text['code'] == 302000:
  17. return text['text'] + '\n' + text['list'][0]['article'] + ':' + text['list'][0]['detailurl']
  18. elif text['code'] == 308000:
  19. return text['text'] + '\n' + text['list'][0]['name'] + ':' + text['list'][0]['detailurl']
  20. elif text['code'] == 40001:
  21. return '参数key错误'
  22. elif text['code'] == 40002:
  23. return '请求内容info为空'
  24. else:
  25. return '机器人失踪啦 ... ... 请稍后再试'