zoukankan      html  css  js  c++  java
  • python实现图灵机器人帮你回复微信好友消息



    '''
    Created on 2018年4月26日 @author: cvv54 ''' #引入itchat包获取微信消息 import itchat from itchat.content import * import hashlib import requests #注册帐号http://www.tuling123.com/ #获得自己的机器人,并记录下apikey #传入消息给机器人并获取回复 def get_response(msg,FromUserName): api_url='http://www.tuling123.com/openapi/api' #填自己的apikey apikey='*************************************' hash=hashlib.md5() userid=hash.update(FromUserName.encode('utf-8')) data = {'key': apikey, 'info': msg, 'userid': userid } try: #给机器人的api接口转发信息 req = requests.post(api_url, data=data).json() #将机器人的回复返回 return req.get('text') except: return #生成微信登录的二维码图片,用户手机扫码登录微信 itchat.auto_login() #只对单独给自己发微信消息的好友自动答复,对群消息不自动答复 @itchat.msg_register([PICTURE,TEXT]) def simple_reply(msg): ''' if msg['Type']==TEXT: ReplyContent='I received message: '+msg['Content'] if msg['Type']==PICTURE: ReplyContent = 'I received picture: '+msg['FileName'] itchat.send_msg('[auto-reply]'+ReplyContent,msg['FromUserName']) ''' #调用函数,发送信息给机器人并将回复返回给respones respones = get_response(msg['Content'], msg['FromUserName']) #将机器人的回复转发给消息发送人,并在前面加上“我是图灵机器人:”区分自动回复与人工回复 itchat.send("我是图灵机器人:"+respones, msg['FromUserName']) itchat.run()
  • 相关阅读:
    剑指offer55. 平衡二叉树
    剑指offer52. 两个链表的第一个公共节点
    LC1043. Partition Array for Maximum Sum
    剑指offer40. Top K
    剑指offer39. 数组中出现次数超过一半的数字
    剑指offer36.将BST原地转换为双向循环链表
    判断大小端
    CentOS安装RabbitMQ 3.8.9
    Nginx 413 Request Too Large 错误
    NginxPC端和移动端区分
  • 原文地址:https://www.cnblogs.com/cvv54/p/8960911.html
Copyright © 2011-2022 走看看