Python之微信-微信群发

Python之微信-微信群发

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import requests
from wxpy import *

# bot = Bot(cache_path=True)
bot = Bot()


# 调用图灵机器人API,发送消息并获得机器人的回复
def auto_reply(text):
    url = "http://www.tuling123.com/openapi/api"
    # 0f6b8d0107ee43039aa1941dc94729de
    # 9df516a74fc443769b233b01e8536a42
    api_key = "0f6b8d0107ee43039aa1941dc94729de"
    payload = {
        "key": api_key,
        "info": text,
    }
    r = requests.post(url, data=json.dumps(payload))
    result = json.loads(r.content)  # 获取对方给你发送的消息
    if result == '你好':
        return "我不好"
    if result == "老公" or result == '老婆':
        return "Ta睡着了,我爱死你了"
    if result == "我要剁手":
        return "那你把脚也剁了把"
    return "老婆大人,你好,我在打游戏,要打扰我"  # 回复好友消息


@bot.register()
def send_message(msg):
    return auto_reply(msg.text)


embed()

猜你喜欢

转载自www.cnblogs.com/nickchen121/p/10825921.html
今日推荐