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

个人微信接入图灵机器人(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)

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

上一篇:微信公众号问题:{"errcode":40125,"errmsg":"invalid appsecret, view more at http:\/\/t.cn\/LOEdzVq, hints: [ req_id: kL8J90219sg58 ]"}


下一篇:python Django框架接口微信公众平台