我是靠谱客的博主 现实烤鸡,这篇文章主要介绍python 微信机器人自动聊天+回怼表情包+Adidas公众号自动抽签 二、机器人自动回复机器人自动聊天,现在分享给大家,希望可以做个参考。

上一章讲到了开发的原因和wxpy的初步使用

这一章的主要内容是如何引入机器人进行自动回复

机器人自动聊天

from __future__ import unicode_literals
from wxpy import *
import requests
import json
import re
import urllib.request  #urllib2
import threading
import glob
import random
import urllib
import base64
import os
from apscheduler.schedulers.blocking import BlockingScheduler
bot = Bot(cache_path=True)


# 监听你的微信消息 except_self:True 不监控自己发送的信息 由于只有一个微信 测试只能设置成false
@bot.register(except_self=False)
def print_others(msg):
    message = msg.text
    type = msg.type
    reply = u''
    if type == 'Text':
       # 机器人自动陪聊
        if get_response(message) != '亲爱的,当天请求次数已用完。':
            reply = get_response(message)
        else:
            reply = ''
        return reply
    # return 等于msg.replay() 回复机器人的回答 给 发送给你信息的人
    return  reply
             

# 注册图灵机器人 实名认证后每天有一百条免费试用 
def get_response(msg):
    apiUrl = 'http://www.tuling123.com/openapi/api'   #图灵机器人的api
    # 将别人发与你的信息发送给图灵的接口,它会根据你发送的信息进行智能回复 然后传输给你
    payload = {
        'key': '',  # api Key
        'info': msg,  # 这是我们收到的消息
        'userid': 'wechat-robot',  # 这里可随意修改
    }
    # 通过如下命令发送一个post请求
    r = requests.post(apiUrl, data=json.dumps(payload))
    # 图灵机器人根据发送的信息智能返回的回答
    mes = json.loads(r.text)['text']
    return mes

参考文档
①wxpy的开发文档

最后

以上就是现实烤鸡最近收集整理的关于python 微信机器人自动聊天+回怼表情包+Adidas公众号自动抽签 二、机器人自动回复机器人自动聊天的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部