#此程序需在有网络的条件下运行 import itchat from itchat.content import * import re @itchat.msg_register([TEXT]) def text_reply(msg): print("..%s.."%msg['Text']) #span去除前后空格 再进行匹配 match = re.search('年',msg['Text']).span() if match: itchat.send('你也新年快乐啊~',msg['FromUserName']) else: print('haha') #程序一运行,生成一个二维码,等待用户扫描 itchat.auto_login(enableCmdQR=True,hotReload=True) itchat.run()