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