小冰微信聊天

python3 + wxpy + requests

使用方法

首先到http://www.tuling123.com申请一个api_key,填入下方的api_key。然后修改自己的微信好友名称

WeChat.py

# -*- coding: utf-8 -*-
from wxpy import *
import json
import requests
import time
#console_qr是否开启纯控制台模式 cache_path是否开启cache缓存便于下次登录
bot = Bot(console_qr=False,cache_path=True)
#bot.file_helper.send("hella") #给文件助手(file_helper)发消息
my_friend = bot.friends().search('微信好友名称')[0] #定位好友
#print(type(bot.friends()))
#my_friend.send('啊啊啊'+str(i)) #发送“Hello!”测试一下对接是否成功。


# 调用图灵机器人API,发送消息并获得机器人的回复
def auto_reply(text):
    url = "http://www.tuling123.com/openapi/api"
    api_key = "你的api_key"
    payload = {
        "key": api_key,
        "info": text,
        "userid": "123456"
    }
    r = requests.post(url, data=json.dumps(payload))
    result = json.loads(r.content)
    time.sleep(2)
    return result["text"].replace('。','').replace('“空”','傻瓜')

@bot.register(my_friend)
def forward_message(msg):
    return auto_reply(msg.text)
embed()

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦