Python - 调用图灵机器人API V2.0实现微信自动回复

 思维导图

Python - 调用图灵机器人API V2.0实现微信自动回复_第1张图片



图灵机器人: 

Python - 调用图灵机器人API V2.0实现微信自动回复_第2张图片

官网:http://www.turingapi.com/

官方教程:https://www.kancloud.cn/turing/www-tuling123-com/718227



源码: 

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 19 22:07:22 2019

@author: dell
"""

import itchat
import requests
import json
itchat.auto_login(hotReload=True)

friends = itchat.get_friends()

def getResponse(msg):
    url = "http://openapi.tuling123.com/openapi/api/v2"
    data = {
    	"reqType":0,
        "perception": {
            "inputText": {
                "text": msg
            },
            "inputImage": {
                "url": "imageUrl"
            }
        },
        "userInfo": {
            "apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "userId": "Geclipse"
        }
    }
    data = json.dumps(data)
    r = requests.post(url,data).json()
    return r['results'][0]['values']['text']


@itchat.msg_register(itchat.content.TEXT)    #读取接受到的消息的TEXT部分内容,存储进默认的msg

def auto_reply(msg):
    friends_message = msg['Text']
    name = msg['FromUserName']
    reply = getResponse(friends_message)
    itchat.send(reply,toUserName=name)

itchat.run()

 

 

你可能感兴趣的:(Python)