python

超轻量级php框架startmvc

Python实现的微信红包提醒功能示例

更新时间:2020-07-26 05:36:01 作者:startmvc
本文实例讲述了Python实现的微信红包提醒功能。分享给大家供大家参考,具体如下:#coding=u

本文实例讲述了Python实现的微信红包提醒功能。分享给大家供大家参考,具体如下:


#coding=utf-8
import itchat
from itchat.content import TEXT
from itchat.content import *
import sys
import time
import re
reload(sys)
sys.setdefaultencoding('utf8')
import os
@itchat.msg_register(NOTE,isGroupChat=True)#监听群内红包消息
def receive_red_packet(msg):
 if u"收到红包" in msg['Content']:
 groups = itchat.get_chatrooms(update=True)
 users = itchat.search_chatrooms(name=u'Happy一家人')#把红包消息通知给这个群
 userName = users[0]['UserName']#获取这个群的唯一标示
 for g in groups:
 if msg['FromUserName'] == g['UserName']:#根据群消息的FromUserName匹配是哪个群
 group_name = g['NickName']
 msgbody = u'有人在群"%s"发了红包,请立即打电话给我,让我去抢'%group_name
 itchat.send(msgbody,toUserName=userName) #告诉指定的好友群内有红包
itchat.auto_login(hotReload=True)
itchat.run()

Python 微信红包 提醒