欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python之微信-微信群发

程序员文章站 2022-03-25 19:12:00
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()