mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-10-30 08:27:52 +00: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}"
|
||||
|
||||
import courier
|
||||
from hashlib import sha1
|
||||
|
||||
class APNSConnection():
|
||||
def __init__(self, token: bytes=None, private_key=None, cert=None):
|
||||
|
@ -108,6 +109,13 @@ class APNSConnection():
|
|||
if 3 in resp.fields.fields:
|
||||
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__":
|
||||
import courier
|
||||
import base64
|
||||
|
|
7
demo.py
7
demo.py
|
@ -8,11 +8,8 @@ print(f"Push Token 1: {b64encode(conn1.token).decode()}")
|
|||
conn2 = apns.APNSConnection()
|
||||
print(f"Push Token 2: {b64encode(conn2.token).decode()}")
|
||||
|
||||
# Create a topic filter payload with SHA1 hash of the topic
|
||||
payload = apns.Payload(9, apns.Fields({1: conn2.token, 2: sha1(b"com.apple.madrid").digest()}))
|
||||
# Send the payload
|
||||
#conn1.sock.write(payload.to_bytes())
|
||||
conn2.sock.write(payload.to_bytes())
|
||||
conn1.filter(["com.apple.madrid"])
|
||||
conn2.filter(["com.apple.madrid"])
|
||||
|
||||
#print(sha1(b"com.apple.madrid").digest())
|
||||
# Send a notification
|
||||
|
|
Loading…
Reference in a new issue