添加msgpusher推送方式
This commit is contained in:
parent
f3613c9955
commit
825e32fec3
48
server.py
48
server.py
@ -12,24 +12,47 @@ import requests
|
|||||||
|
|
||||||
SERVER = "http://www.pushplus.plus/send"
|
SERVER = "http://www.pushplus.plus/send"
|
||||||
TOKEN = "ff328cba923a4225bc4acd0086a9014c"
|
TOKEN = "ff328cba923a4225bc4acd0086a9014c"
|
||||||
# SERVER = "https://msgpusher.com/push/test111"
|
# SERVER = "http://push.nmhd.eu.org:12722/push/murmur"
|
||||||
# TOKEN = "tt"
|
# TOKEN = "tt"
|
||||||
|
|
||||||
def s2wx(title,content):
|
def pp2wx(title,content,description):
|
||||||
"""发送至微信.
|
"""通过pushplus发送至微信,有频次限制.
|
||||||
title:标题
|
title:标题
|
||||||
content:内容"""
|
content:内容"""
|
||||||
|
|
||||||
ppmsg = {"token":TOKEN,
|
ppmsg = {"token":TOKEN,
|
||||||
"template":"json",
|
"template":"json",
|
||||||
"channel":"wechat",
|
"channel":"wechat",
|
||||||
"description": content,
|
"description": description,
|
||||||
}
|
}
|
||||||
ppmsg["title"] = title
|
ppmsg["title"] = title
|
||||||
ppmsg["content"] = content
|
ppmsg["content"] = content
|
||||||
# ppmsg["description"]= content
|
# ppmsg["description"]= content
|
||||||
requests.post(SERVER, json=ppmsg)
|
requests.post(SERVER, json=ppmsg)
|
||||||
|
|
||||||
|
def s2wx(title,description, content):
|
||||||
|
"""通过自建msgpusher发送至微信
|
||||||
|
当前title值无效
|
||||||
|
"""
|
||||||
|
|
||||||
|
# GET 方式
|
||||||
|
# res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}"
|
||||||
|
# f"&description={description}&content={content}&token={TOKEN}")
|
||||||
|
|
||||||
|
# POST 方式
|
||||||
|
res = requests.post("http://push.nmhd.eu.org:12722/push/murmur", json={
|
||||||
|
"title": title,
|
||||||
|
"description": description,
|
||||||
|
"content": content,
|
||||||
|
"token": "tt"
|
||||||
|
})
|
||||||
|
res = res.json()
|
||||||
|
if res["success"]:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return res["message"]
|
||||||
|
|
||||||
|
|
||||||
cache = defaultdict(list)
|
cache = defaultdict(list)
|
||||||
offs = 0 # 偏移量
|
offs = 0 # 偏移量
|
||||||
|
|
||||||
@ -75,8 +98,12 @@ def update_pairs(addr, ccid, clear=0):
|
|||||||
if ccid and not clear:
|
if ccid and not clear:
|
||||||
# 添加或更新客户端
|
# 添加或更新客户端
|
||||||
if ccid not in p:
|
if ccid not in p:
|
||||||
t = "终端信息:\nCCID:" + ccid.decode() + "\n地址:" + str(addr.getpeername())
|
t = f"""
|
||||||
s2wx("天通终端上线",t)
|
### **终端信息:**
|
||||||
|
CCID:{ccid.decode()}
|
||||||
|
地址:{str(addr.getpeername())}
|
||||||
|
"""
|
||||||
|
s2wx("","天通终端上线",t)
|
||||||
p[ccid] = addr
|
p[ccid] = addr
|
||||||
pp[addr] = ccid
|
pp[addr] = ccid
|
||||||
else:
|
else:
|
||||||
@ -273,7 +300,8 @@ def tt_decode(addr, data):
|
|||||||
class MyServer(socketserver.BaseRequestHandler):
|
class MyServer(socketserver.BaseRequestHandler):
|
||||||
def handle(self): # 回调
|
def handle(self): # 回调
|
||||||
add_timestamp()
|
add_timestamp()
|
||||||
print("终端", self.client_address, "已上线,等待上报心跳注册ccid。")
|
print("客户端", self.client_address, "已上线,等待上报心跳注册ccid。")
|
||||||
|
s2wx("天通消息","TCP客户端上线",str(self.client_address) + "已上线,等待上报心跳注册ccid。")
|
||||||
conn = self.request
|
conn = self.request
|
||||||
# print(type(conn),conn.fd)
|
# print(type(conn),conn.fd)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user