个人微信接入图灵机器人(python版)

效果图

准备工作

  • itchat,requests
  • 注册图灵账号,创建机器人,获取API-KEY

代码实现

import itchat
from itchat.content import *
import json
import requests


@itchat.msg_register([TEXT])
def text_reply(msg):
    info = msg['Text'].encode('utf-8')
    url = 'http://www.tuling123.com/openapi/api'
    data = {u"key": "这里填入你的API-key", "info": info, u"loc": "", "userid": ""}
    response=requests.post(url,data).content
    s = json.loads(response, encoding='utf-8')
    print('s == %s' % s)
    if s['code'] == 100000:
        itchat.send(s['text'], msg['FromUserName'])

itchat.auto_login(hotReload=True)
itchat.run(debug=True)
posted @ 2018-01-14 23:01  假隐士  阅读(3102)  评论(0编辑  收藏  举报