mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-24 11:52:27 -06:00
latest changes
This commit is contained in:
parent
8f5e64e4b1
commit
e7a6cba72c
2 changed files with 10 additions and 5 deletions
8
apns.py
8
apns.py
|
@ -84,6 +84,7 @@ class Payload:
|
||||||
return f"{COMMANDS[self.command]}: {self.fields}"
|
return f"{COMMANDS[self.command]}: {self.fields}"
|
||||||
|
|
||||||
import courier
|
import courier
|
||||||
|
from hashlib import sha1
|
||||||
|
|
||||||
class APNSConnection():
|
class APNSConnection():
|
||||||
def __init__(self, token: bytes=None, private_key=None, cert=None):
|
def __init__(self, token: bytes=None, private_key=None, cert=None):
|
||||||
|
@ -108,6 +109,13 @@ class APNSConnection():
|
||||||
if 3 in resp.fields.fields:
|
if 3 in resp.fields.fields:
|
||||||
self.token = resp.fields.fields[3]
|
self.token = resp.fields.fields[3]
|
||||||
|
|
||||||
|
def filter(self, topics: list[str]):
|
||||||
|
payload = Payload(9, Fields({1: self.token, 2: b"".join([sha1(topic.encode()).digest() for topic in topics])}))
|
||||||
|
|
||||||
|
self.sock.write(payload.to_bytes())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import courier
|
import courier
|
||||||
import base64
|
import base64
|
||||||
|
|
7
demo.py
7
demo.py
|
@ -8,11 +8,8 @@ print(f"Push Token 1: {b64encode(conn1.token).decode()}")
|
||||||
conn2 = apns.APNSConnection()
|
conn2 = apns.APNSConnection()
|
||||||
print(f"Push Token 2: {b64encode(conn2.token).decode()}")
|
print(f"Push Token 2: {b64encode(conn2.token).decode()}")
|
||||||
|
|
||||||
# Create a topic filter payload with SHA1 hash of the topic
|
conn1.filter(["com.apple.madrid"])
|
||||||
payload = apns.Payload(9, apns.Fields({1: conn2.token, 2: sha1(b"com.apple.madrid").digest()}))
|
conn2.filter(["com.apple.madrid"])
|
||||||
# Send the payload
|
|
||||||
#conn1.sock.write(payload.to_bytes())
|
|
||||||
conn2.sock.write(payload.to_bytes())
|
|
||||||
|
|
||||||
#print(sha1(b"com.apple.madrid").digest())
|
#print(sha1(b"com.apple.madrid").digest())
|
||||||
# Send a notification
|
# Send a notification
|
||||||
|
|
Loading…
Reference in a new issue