├── QQ.py ├── README.MD ├── config.json └── requirements.txt /QQ.py: -------------------------------------------------------------------------------- 1 | from email import message 2 | import json 3 | from tokenize import group 4 | from flask import Flask,request,jsonify 5 | import json 6 | import requests 7 | import httpx 8 | try: 9 | with open("config.json","r",encoding = 'UTF-8') as f: 10 | config = json.load(f) 11 | group_whitelist = config["WhiteList"] 12 | MiPush = config["MiPush"] 13 | FCM = config["FCM"] 14 | KEY = config["KEY"] 15 | except: 16 | print("读取配置文件异常,请检查配置文件是否存在或语法是否有问题") 17 | assert() 18 | try: 19 | groupInfo = json.loads(requests.get("http://localhost:5700/get_group_list").text) 20 | userId = json.loads(requests.get("http://localhost:5700/get_login_info").text)["data"]["user_id"] 21 | except: 22 | print("无法从go-cqhttp获取信息,请检查go-cqhttp是否运行或端口配置是否正确") 23 | assert() 24 | app = Flask(__name__) 25 | def msgFormat(msg): 26 | if "CQ:image" in msg: 27 | msg = "[图片]" 28 | elif "CQ:record" in msg: 29 | msg = "[语音]" 30 | elif "CQ:share" in msg: 31 | msg = "[链接]" 32 | elif "CQ:music" in msg: 33 | msg = "[音乐分享]" 34 | elif "CQ:redbag" in msg: 35 | msg = "[红包]" 36 | elif "CQ:forward" in msg: 37 | msg = "[合并转发]" 38 | elif "戳一戳" in msg: 39 | msg = "戳了你一下" 40 | return msg 41 | def getGroupName(groupId): 42 | length = len(groupInfo["data"]) 43 | for i in range(length): 44 | if groupId == groupInfo["data"][i]["group_id"]: 45 | return groupInfo["data"][i]["group_name"] 46 | @app.route("/",methods=['POST']) 47 | async def recvMsg(): 48 | data = request.get_data() 49 | json_data = json.loads(data.decode("utf-8")) 50 | if json_data["post_type"] == "meta_event": 51 | if json_data["meta_event_type"] == "heartbeat": 52 | print("接收心跳信号成功") 53 | elif json_data["post_type"] == "request": 54 | if json_data["request_type"] == "friend": 55 | friendId = json_data["user_id"] 56 | print("新的好友添加请求:%s"%friendId) 57 | if MiPush == "True": 58 | await httpx.AsyncClient().post("https://tdtt.top/send",data={'title':"新的好友添加请求",'content':'%s想要添加您为好友'%friendId,'alias':KEY}) 59 | elif FCM == "True": 60 | await httpx.AsyncClient().post("https://wirepusher.com/send",data={'id':KEY,'title':"新的好友添加请求",'message':'%s想要添加您为好友'%friendId,'type':'FriendAdd'}) 61 | elif json_data["message_type"] == "private": 62 | nickName = json_data["sender"]["nickname"] 63 | msg = msgFormat(json_data["message"]) 64 | print("来自%s的私聊消息:%s"%(nickName,msg)) 65 | if MiPush == "True": 66 | await httpx.AsyncClient().post("https://tdtt.top/send",data={'title':nickName,'content':'%s'%(msg),'alias':KEY}) 67 | elif FCM == "True": 68 | await httpx.AsyncClient().post("https://wirepusher.com/send",data={'id':KEY,'title':nickName,'message':msg,'type':'privateMsg'}) 69 | elif json_data["message_type"] == "group": 70 | groupId = json_data["group_id"] 71 | groupName = getGroupName(groupId) 72 | nickName = json_data["sender"]["nickname"] 73 | msg = msgFormat(json_data["message"]) 74 | if groupId in group_whitelist: 75 | print("群聊%s的消息:%s:%s"%(groupName,nickName,msg)) 76 | if MiPush == "True": 77 | await httpx.AsyncClient().post("https://tdtt.top/send",data={'title':'%s'%groupName,'content':'%s:%s'%(nickName,msg),'alias':KEY}) 78 | if FCM == "True": 79 | await httpx.AsyncClient().post("https://wirepusher.com/send",data={'id':'%s'%KEY,'title':groupName,'message':'%s:%s'%(nickName,msg),'type':'groupMsg'}) 80 | elif "[CQ:at,qq=%s]"%userId in msg: 81 | msg = msg.replace("[CQ:at,qq=%s]"%userId,"[有人@我]") 82 | print("群聊%s有人@我:%s:%s"%(groupName,nickName,msg)) 83 | if MiPush == "True": 84 | await httpx.AsyncClient().post("https://tdtt.top/send",data={'title':'%s'%groupName,'content':'%s:%s'%(nickName,msg),'alias':KEY}) 85 | if FCM == "True": 86 | await httpx.AsyncClient().post("https://wirepusher.com/send",data={'id':'%s'%KEY,'title':groupName,'message':'%s:%s'%(nickName,msg),'type':'groupMsg'}) 87 | return "200 OK" 88 | if __name__ == '__main__': 89 | app.run(host="0.0.0.0",port=5000) -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | 这是一个能够对QQ、微信消息通过第三方推送转发的程序,由qq-mipush进化而来。新版程序相比旧版有以下区别: 2 | 1.同时支持小米推送和FCM推送 3 | 2.加入对微信推送的支持 4 | 3.预计加入点开通知时拉起聊天的功能 5 | 4.预计加入通知栏回复功能 6 | 完整配置教程:https://my.toho.red/archives/8/ 7 | 8 | 4.5更新:本程序将逐步向docker转移,本仓库将同步更新,docker版请移步https://github.com/zhishixiang/tencent-push4docker查看 9 | 本项目的后续计划:https://my.toho.red/archives/57/ 10 | 11 | 2022.5.1我想说的话: 12 | 13 | 实在是没想到,第一次轻易接受别人的pr会导致这么严重的后果,接受的甚至还是根本没有测试的代码,改bug用的时间比我重写还要多。 14 | 15 | 直接回退吧,累了,懒得接受pr了。 16 | 17 | 本项目随缘更新了,想要持续更新的版本请移步https://github.com/QXAzusa/tencent-push -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | {"MiPush":"False","FCM":"False","KEY":"0000","WhiteList":[1077550597]} -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.1.1 2 | httpx==0.22.0 3 | requests==2.27.1 4 | aioflask==0.4.0 5 | --------------------------------------------------------------------------------