itchat发送微信消息

1.1 微信机器人自动回复消息

  1、运行程序,会弹出二维码,扫描授权后即可实现自动回复信息 参考01  参考02

#coding=utf8
import itchat, time
from itchat.content import *

@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply(msg):
    itchat.send(‘%s: %s‘ % (msg[‘Type‘], msg[‘Text‘]), msg[‘FromUserName‘])

@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
def download_files(msg):
    msg[‘Text‘](msg[‘FileName‘])
    return ‘@%[email protected]%s‘ % ({‘Picture‘: ‘img‘, ‘Video‘: ‘vid‘}.get(msg[‘Type‘], ‘fil‘), msg[‘FileName‘])

@itchat.msg_register(FRIENDS)
def add_friend(msg):
    itchat.add_friend(**msg[‘Text‘]) # 该操作会自动将新好友的消息录入,不需要重载通讯录
    itchat.send_msg(‘Nice to meet you!‘, msg[‘RecommendInfo‘][‘UserName‘])

@itchat.msg_register(TEXT, isGroupChat=True)
def text_reply(msg):
    if msg[‘isAt‘]:
        itchat.send(u‘@%s\u2005I received: %s‘ % (msg[‘ActualNickName‘], msg[‘Content‘]), msg[‘FromUserName‘])

itchat.auto_login(True)
itchat.run()

微信自动回复

#coding=utf8
import itchat,time

# 自动回复
# 封装好的装饰器,当接收到的消息是Text,即文字消息
@itchat.msg_register(‘Text‘)
def text_reply(msg):
    # 当消息不是由自己发出的时候
    if not msg[‘FromUserName‘] == myUserName:
        # 发送一条提示给文件助手
        itchat.send_msg(u"[%s]收到好友@%s 的信息:%s\n" %
                        (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg[‘CreateTime‘])),
                         msg[‘User‘][‘NickName‘],
                         msg[‘Text‘]), ‘filehelper‘)
        # 回复给好友
        return u‘[自动回复]您好,我现在有事不在,一会再和您联系。\n已经收到您的的信息:%s\n‘ % (msg[‘Text‘])

if __name__ == ‘__main__‘:
    itchat.auto_login()

    # 获取自己的UserName
    myUserName = itchat.get_friends(update=True)[0]["UserName"]
    itchat.run()

微信自动回复方法2

原文地址:https://www.cnblogs.com/jiaxinzhu/p/12595940.html

时间: 2024-08-30 10:15:06

itchat发送微信消息的相关文章

2.转发。基于itchat的微信消息同步机器人

原文:https://www.jianshu.com/p/7aeadca0c9bd# 看到了该网址有基于itchat的微信消息同步机器人,转过来继续研究.以下是转过来的: 最近 全栈数据工程师养成攻略 的微信群已经将近500人,开了二群之后为了打通不同微信群之间的消息,花了点时间做了个消息同步机器人,在任意群收到消息时同步到其他群,并且将聊天内容上传至数据库,以供进一步分析.统计和展示. 基本思路是,用 Python 模拟微信网页版登陆,接收到群里消息后,对文本.图片.分享等各类消息类型分别处理

脱离微信客户端发送微信消息(二)

Python版本:使用微信API发送微信消息 本文代码借用朋友编写的成品代码,使用Python3编写,配合上一篇文章:<脱离微信客户端发送微信消息(一)>经过试验完全可以发送微信消息. 文件:BaseData.py Python3代码: 1 # -*- coding: utf-8 -*- 2 3 corpid="XXXXXXX" # 设置-权限设置-部门-查看CorpID 4 corpsecret="YYYYYYYYYY" # 设置-权限设置-部门-查看

itchat发送微信文本消息、文件等【python】

前言 Itchat是一个开源的微信个人接口.使用python调用itchat的API,可以完成一个能够处理所有信息的微信机器人.比如说你可以写python,利用itchat,去搜索特定的人,然后向这个人发送消息.图片.视频.附件等等. 应用场景 在做自动化测试框架时,往往如果有case没有通过时,一般都会发邮件,或者发送短信进行通知相关人员.因为微信毕竟是现在非常主流的社交工具.如果在case有失败的情况下,如果能通过微信发送信息到相关人,岂不是更好.如果能把自动化运行的报告,最为附件发送给相应

通过Powershell 发送微信消息

前期需要注册一个微信企业号(度娘可以找到好多帖子)这部分就不再详细说了. 主要通过Powershell 调取微信企业号API来实现发送消息的目的. 下面是一个写好的函数大家可以直接调用: function send-weixin { Param(         [Parameter(Mandatory = $True, Position = 1)]         [String]$Username,         [Parameter(Mandatory = $True, Position

用python批量发送微信消息

根据用户的备注名来给用户发送特定的消息,在itchat获取的friends列表中,username每次登陆之后都会出现变化. 1 #-*- coding:utf-8 -*- 2 """ 3 __author__ = BlingBling 4 """ 5 6 import time 7 import itchat 8 import xlrd 9 10 11 # 登录 12 if itchat.check_login() == 200: 13 pri

Web微信之发送微信消息

requests.post(url=url,json=post_dict) requests.post(url=url,data=json.dumps(post_dict),headers={'content_Type':'application/json;charset=utf-8'}) ensure_ascii=False 中文不会转化unicode编码 .strip() 去空格 含中文发送要用字节格式 原文地址:https://www.cnblogs.com/jintian/p/11406

python发送微信及企业微信消息

1.发送微信消息 直接使用第三方库 itchat,其文档中有详细使用方式:https://itchat.readthedocs.io/zh/latest/ 如下实例为 发送群聊信息 # -*- coding: utf-8 -*- # (C) Guangcai Ren, 2019 # All rights reserved import logging import itchat log = logging.getLogger(__name__) # itchat 微信官方教程:https://i

微信发送模板消息代码示例

最近一个微信的项目里需要发送微信模板消息给卖家或者供应商等,微信开发其实也就按照微信的官方接口要求组装起来即可,下面简单介绍一下我的微信模板发送代码. 1.获取access token,至于access token是什么,大家可以自行微信接口文档看一下,这边不多说 获取access token我这边主要是用定时器没大概2分钟获取一次,每天获取的次数是100000次,用法如下: 1 #region 2 3 using System; 4 using System.Timers; 5 6 #endr

在测试环境发送 微信模板消息 调试 --Sangit

一.如何在测试环境发送 1.强制access_token,把正式公众号的token写到测试环境代码,发送模板消息微信只根据access_token来判断公众号 2.同时把测试用户在正式环境的openid也写到测试环境的代码 二.如何查看模板消息是否发送成功 因为系统发送模板消息用的是 swoole服务 来监听发送,所以需要通过 strace命令 追踪进程状态信息 1.通过ps命令查看进程的pid 2.通过strace命令追踪进程 3.然后调用发送模板消息,可以看到追踪进程 发送的数据与返回值,可