当前位置: 首页 > news >正文

互联网门户网站模板/推广运营是什么工作

互联网门户网站模板,推广运营是什么工作,网址大全360,虚拟商品购物网站源码导语: 哈喽吖铁汁萌~不知道大家在wei信上突然看到“XXX撤回一条消息”的时候,心里痒不痒?现在就教你如何实现消息防撤回的功能。不限手机型号、手机无需root,只要微信号可以登上网页版就可以了(部分不常用和新申请的账…

导语:

哈喽吖铁汁萌~不知道大家在wei信上突然看到“XXX撤回一条消息”的时候,心里痒不痒?现在就教你如何实现消息防撤回的功能。不限手机型号、手机无需root,只要微信号可以登上网页版就可以了(部分不常用和新申请的账号会登不上网页版)。

环境

Centos7

python2.7

itchat 

源码

​
# coding:utf-8import itchatfrom itchat.content import TEXTfrom itchat.content import *import sysimport timeimport rereload(sys)sys.setdefaultencoding('utf8')import osmsg_information = {}face_bug = None  # 针对表情包的内容@itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True,isMpChat=True)def handle_receive_msg(msg):global face_bugmsg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())  # 接受消息的时间msg_from = itchat.search_friends(userName=msg['FromUserName'])['NickName']  # 在好友列表中查询发送信息的好友昵称msg_time = msg['CreateTime']  # 信息发送的时间msg_id = msg['MsgId']  # 每条信息的idmsg_content = None  # 储存信息的内容msg_share_url = None  # 储存分享的链接,比如分享的文章和音乐print msg['Type']print msg['MsgId']if msg['Type'] == 'Text' or msg['Type'] == 'Friends':  # 如果发送的消息是文本或者好友推荐msg_content = msg['Text']print msg_content# 如果发送的消息是附件、视屏、图片、语音elif msg['Type'] == "Attachment" or msg['Type'] == "Video" \or msg['Type'] == 'Picture' \or msg['Type'] == 'Recording':msg_content = msg['FileName']  # 内容就是他们的文件名msg['Text'](str(msg_content))  # 下载文件# print msg_contentelif msg['Type'] == 'Card':  # 如果消息是推荐的名片msg_content = msg['RecommendInfo']['NickName'] + '的名片'  # 内容就是推荐人的昵称和性别if msg['RecommendInfo']['Sex'] == 1:msg_content += '性别为男'else:msg_content += '性别为女'print msg_contentelif msg['Type'] == 'Map':  # 如果消息为分享的位置信息x, y, location = re.search("<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*", msg['OriContent']).group(1, 2, 3)if location is None:msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()  # 内容为详细的地址else:msg_content = r"" + locationelif msg['Type'] == 'Sharing':  # 如果消息为分享的音乐或者文章,详细的内容为文章的标题或者是分享的名字msg_content = msg['Text']msg_share_url = msg['Url']  # 记录分享的urlprint msg_share_urlface_bug = msg_content##将信息存储在字典中,每一个msg_id对应一条信息msg_information.update({msg_id: {"msg_from": msg_from, "msg_time": msg_time, "msg_time_rec": msg_time_rec,"msg_type": msg["Type"],"msg_content": msg_content, "msg_share_url": msg_share_url}})##这个是用于监听是否有friend消息撤回@itchat.msg_register(NOTE, isFriendChat=True, isGroupChat=True, isMpChat=True)def information(msg):# 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句if '撤回了一条消息' in msg['Content']:old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)  # 在返回的content查找撤回的消息的idold_msg = msg_information.get(old_msg_id)  # 得到消息print old_msgif len(old_msg_id) < 11:  # 如果发送的是表情包itchat.send_file(face_bug, toUserName='filehelper')else:  # 发送撤回的提示给文件助手msg_body = "【" \+ old_msg.get('msg_from') + " 撤回了 】\n" \+ old_msg.get("msg_type") + " 消息:" + "\n" \+ old_msg.get('msg_time_rec') + "\n" \+ r"" + old_msg.get('msg_content')# 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手if old_msg['msg_type'] == "Sharing":msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')# 将撤回消息发送到文件助手itchat.send_msg(msg_body, toUserName='filehelper')# 有文件的话也要将文件发送回去if old_msg["msg_type"] == "Picture" \or old_msg["msg_type"] == "Recording" \or old_msg["msg_type"] == "Video" \or old_msg["msg_type"] == "Attachment":file = '@fil@%s' % (old_msg['msg_content'])itchat.send(msg=file, toUserName='filehelper')os.remove(old_msg['msg_content'])# 删除字典旧消息msg_information.pop(old_msg_id)@itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isGroupChat=True)def handle_receive_msg(msg):global face_bugmsg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())  # 接受消息的时间# groupid = msg['FromUserName']# chatroom = itchat.search_chatrooms(userName=groupid)msg_Actual_from = msg['ActualNickName']# msg_Actual_from = msg['User']# msg_from = msg_Actual_from['Self']['NickName']msg_from = msg_Actual_frommsg_time = msg['CreateTime']  # 信息发送的时间msg_id = msg['MsgId']  # 每条信息的idmsg_content = None  # 储存信息的内容msg_share_url = None  # 储存分享的链接,比如分享的文章和音乐print msg['Type']print msg['MsgId']if msg['Type'] == 'Text' or msg['Type'] == 'Friends':  # 如果发送的消息是文本或者好友推荐msg_content = msg['Text']print msg_content# 如果发送的消息是附件、视屏、图片、语音elif msg['Type'] == "Attachment" or msg['Type'] == "Video" \or msg['Type'] == 'Picture' \or msg['Type'] == 'Recording':msg_content = msg['FileName']  # 内容就是他们的文件名msg['Text'](str(msg_content))  # 下载文件# print msg_contentelif msg['Type'] == 'Card':  # 如果消息是推荐的名片msg_content = msg['RecommendInfo']['NickName'] + '的名片'  # 内容就是推荐人的昵称和性别if msg['RecommendInfo']['Sex'] == 1:msg_content += '性别为男'else:msg_content += '性别为女'print msg_contentelif msg['Type'] == 'Map':  # 如果消息为分享的位置信息x, y, location = re.search("<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*", msg['OriContent']).group(1, 2, 3)if location is None:msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()  # 内容为详细的地址else:msg_content = r"" + locationelif msg['Type'] == 'Sharing':  # 如果消息为分享的音乐或者文章,详细的内容为文章的标题或者是分享的名字msg_content = msg['Text']msg_share_url = msg['Url']  # 记录分享的urlprint msg_share_urlface_bug = msg_content##将信息存储在字典中,每一个msg_id对应一条信息msg_information.update({msg_id: {"msg_from": msg_from, "msg_time": msg_time, "msg_time_rec": msg_time_rec,"msg_type": msg["Type"],"msg_content": msg_content, "msg_share_url": msg_share_url}})##这个是用于监听是否有Group消息撤回@itchat.msg_register(NOTE, isGroupChat=True, isMpChat=True)def information(msg):# 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句if '撤回了一条消息' in msg['Content']:old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)  # 在返回的content查找撤回的消息的idold_msg = msg_information.get(old_msg_id)  # 得到消息print old_msgif len(old_msg_id) < 11:  # 如果发送的是表情包itchat.send_file(face_bug, toUserName='filehelper')else:  # 发送撤回的提示给文件助手msg_body = "【" \+ old_msg.get('msg_from') + " 群消息撤回提醒】\n" \+ " 撤回了 " + old_msg.get("msg_type") + " 消息:" + "\n" \+ old_msg.get('msg_time_rec') + "\n" \+ r"" + old_msg.get('msg_content')# 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手if old_msg['msg_type'] == "Sharing":msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')# 将撤回消息发送到文件助手itchat.send_msg(msg_body, toUserName='filehelper')# 有文件的话也要将文件发送回去if old_msg["msg_type"] == "Picture" \or old_msg["msg_type"] == "Recording" \or old_msg["msg_type"] == "Video" \or old_msg["msg_type"] == "Attachment":file = '@fil@%s' % (old_msg['msg_content'])itchat.send(msg=file, toUserName='filehelper')os.remove(old_msg['msg_content'])# 删除字典旧消息msg_information.pop(old_msg_id)# Main (enableCmdQr = True 时,将会生成二维码图片,如 =2 时二维码乱码的话 改为1 即可itchat.auto_login(enableCmdQR=2, hotReload=True)itchat.run()​

如果想看懂代码的话,在有python一点基础的前提下搞懂 Python 中的 装饰器 概念。下面是用到itchat中主要的一段代码​​​​​​​

def msg_register(self, msgType, isFriendChat=False, isGroupChat=False, isMpChat=False):''' a decorator constructorreturn a specific decorator based on information given '''if not (isinstance(msgType, list) or isinstance(msgType, tuple)):msgType = [msgType]def _msg_register(fn):for _msgType in msgType:if isFriendChat:self.functionDict['FriendChat'][_msgType] = fnif isGroupChat:self.functionDict['GroupChat'][_msgType] = fnif isMpChat:self.functionDict['MpChat'][_msgType] = fnif not any((isFriendChat, isGroupChat, isMpChat)):self.functionDict['FriendChat'][_msgType] = fnreturn fnreturn _msg_register

运行

1.连接云服务器,安装pip

 2.使用pip 安装 itchat库 (一个利用微信网页版api接口写的,有兴趣的话可以鼓捣鼓捣)

 3.将脚本文件上传到云服务器

 4.运行代码 1)扫码登录

 2.登录成功.

 效果

发送消息

 收到信息

  开始撤回

撤回通知

 可能好多人会说,我没有服务器,该怎么办!其实我放在服务器上是为了二十四小时都在运行,这样可以一直都在防撤回状态了。

end

好了这期就分享到这结束了~希望对你们有一些帮助!喜欢的话记得给小编个三连再走噢~🤞🤞

想领取完整源码跟Python学习资料可点击这行字体

http://www.lbrq.cn/news/1345051.html

相关文章:

  • 石龙网站仿做/seo优化方法
  • 建网站的公司南京/山东关键词网络推广
  • 建设单位企业锁登陆网站/站内营销推广方式
  • 广州市财贸建设开发监理网站/广州竞价托管代运营
  • 精灵网站建设/镇江网站建设推广
  • 企业网站seo哪里好/微博营销案例
  • 找人做网站注意/软文推广公司有哪些
  • 建设网站应该注意的地方/西安最新消息今天
  • 想做一个网站怎么做/网络营销的发展现状及趋势
  • 佛山响应式网站设计/抖音营销推广怎么做
  • 官网网站建设需求/企业营销型网站
  • 泗县做网站/seo推广什么意思
  • 网站数据库怎么做同步/竞价托管推广
  • 网站建设 问卷调查/保定seo排名外包
  • 龙岗网站设计市场/片多多可以免费看电视剧吗
  • 左中右三栏布局网站建设/百度seo怎么提高排名
  • 什么是网站版式/seo双标题软件
  • table做网站的好处/广州番禺发布网
  • 网上商城平台运营方案/提升seo排名的方法
  • 传奇新开网站/温州seo推广外包
  • 沈阳做网站哪家便宜/上海站优云网络科技有限公司
  • 口碑好的秦皇岛网站建设哪里有/济南网络推广
  • 高唐做创建网站的公司/整合营销传播的定义
  • wordpress cos/厦门seo优化推广
  • 云南省建设工程网站/网站建站公司
  • 公司网站如何做百度收录/百度明星人气排行榜
  • 励志做的很好的网站/百度收录入口
  • 转播网站如何做/推广app赚佣金平台有哪些
  • 西安做网站优化公司报价/seo入门培训学校
  • 太钢建设公司官网/网络优化的基本方法
  • 企业高性能web服务器——Nginx
  • MySQL 处理重复数据详细说明
  • 【Python 语法糖小火锅 · 第 4 涮】
  • Day37--动态规划--52. 携带研究材料(卡码网),518. 零钱兑换 II,377. 组合总和 Ⅳ,57. 爬楼梯(卡码网)
  • USRP X310 X410 参数对比
  • Prometheus监控平台部署与应用