python itchat自动回复

我的python版本是 Python 3.10.5

之前试过2.7版本的会报错

#!/usr/bin/python
#coding=utf-8
import json
import requests

import itchat
from itchat.content import *

def get_response(msg):
    apiUrl= "https://api.ownthink.com/bot?spoken="
    r =  requests.get(apiUrl+msg)
    r = json.loads(r.text)
    print("log--r:",r)
    print("log--data",r['data']['info']['text'])
    return r["data"]['info']['text']

@itchat.msg_register([PICTURE,TEXT])

def simple_reply(msg):
    # boom_obj = itchat.search_friends(remarkName=1)[0]['UserName'] 
    username = itchat.search_friends(userName=msg['FromUserName'])['NickName']

    print("log--:username",username)
    # 用户名
    if username == '🤓': 
        print(1)
        if msg['Type'] == TEXT:
            content = msg['Content']
            print('log--:content',content)
            r = get_response(content)
            print("log--:api返回值",r)
            # ReplyContent = 'I received message: '+msg['Content']+r
            ReplyContent = r
        if msg['Type'] == PICTURE:
            ReplyContent = 'I received picture: '+msg['FileName']
        itchat.send_msg(ReplyContent,msg['FromUserName'])
itchat.auto_login(hotReload=True)
# itchat.auto_login(hotReload=True,enableCmdQR=2)
itchat.run()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值