我的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()