Myluzh Blog

Strive to become a dream architect.

python3 itchat微信自动回复机器人

发布时间: 2020-12-19 文章作者: myluzh 分类名称: Python



import itchat
import requests
import random
import time
def get_response(msg):
    url = 'http://i.itpk.cn/api.php'#自动回复API接口
    data = {
        #接口参数
        'api_key': 'xxxx',  # Tuling Key,API的值
        'api_secret': 'xxxx',  # Tuling Key,API的值
        'question': msg,  # 发出去的消息
        'type':'普通文本',
        'limit':'8'
    }
    print('提出问题',msg)
    rqq = requests.post(url, data=data)
    # 当自动检测编码不正确时,手动指定编码
    rqq.encoding = 'utf-8'
    print('响应内容:', rqq.text)
    time.sleep(random.randint(3,8))#随机延迟3-8秒
    return (rqq.text)
@itchat.msg_register(itchat.content.TEXT) # 用于接收来自朋友间的对话消息
def print_content(msg):
    return get_response(msg['Text'])

itchat.auto_login(hotReload=True,enableCmdQR=True) # 通过微信扫描二维码登录
itchat.run()

标签: itchat 自动回复 python3

发表评论