2023-04-05 20:01:07 -05:00
|
|
|
import apns
|
|
|
|
from base64 import b64decode, b64encode
|
2023-04-05 20:21:14 -05:00
|
|
|
from hashlib import sha1
|
2023-04-05 20:01:07 -05:00
|
|
|
|
2023-04-05 20:04:41 -05:00
|
|
|
conn1 = apns.APNSConnection()
|
2023-04-06 12:19:13 -05:00
|
|
|
conn1.connect()
|
2023-04-05 20:04:41 -05:00
|
|
|
print(f"Push Token 1: {b64encode(conn1.token).decode()}")
|
|
|
|
|
2023-04-05 20:21:14 -05:00
|
|
|
conn2 = apns.APNSConnection()
|
2023-04-06 12:19:13 -05:00
|
|
|
conn2.connect()
|
2023-04-05 20:21:14 -05:00
|
|
|
print(f"Push Token 2: {b64encode(conn2.token).decode()}")
|
|
|
|
|
2023-04-06 09:38:29 -05:00
|
|
|
conn1.filter(["com.apple.madrid"])
|
|
|
|
conn2.filter(["com.apple.madrid"])
|
2023-04-05 20:21:14 -05:00
|
|
|
|
2023-04-07 00:48:07 -05:00
|
|
|
conn1.send_message(conn2.token, "com.apple.madrid", "\{'hello': 'world'\}")
|
|
|
|
|
|
|
|
#print(conn1.expect_message())
|
|
|
|
#print(conn2.expect_message())
|
2023-04-06 12:19:13 -05:00
|
|
|
# #print(sha1(b"com.apple.madrid").digest())
|
|
|
|
# # Send a notification
|
|
|
|
# # expiry timestamp in UNIX epoch
|
|
|
|
# expiry = 1680761868
|
|
|
|
# expiry = expiry.to_bytes(4, "big")
|
2023-04-05 20:21:14 -05:00
|
|
|
|
2023-04-06 12:19:13 -05:00
|
|
|
# # Current time in UNIX nano epoch
|
|
|
|
# import time
|
|
|
|
# now = int(time.time() * 1000).to_bytes(8, "big")
|
2023-04-05 20:29:05 -05:00
|
|
|
|
2023-04-06 12:19:13 -05:00
|
|
|
# payload = apns.Payload(0x0a, apns.Fields({1: sha1(b"com.apple.madrid").digest(), 2: conn2.token, 3: b"Hello World!", 4: 0x00.to_bytes(), 5: expiry, 6: now, 7: 0x00.to_bytes()}))
|
|
|
|
# conn1.sock.write(payload.to_bytes())
|
2023-04-05 20:21:14 -05:00
|
|
|
|
2023-04-06 12:19:13 -05:00
|
|
|
# print("Waiting for response...")
|
2023-04-05 20:21:14 -05:00
|
|
|
|
2023-04-06 12:19:13 -05:00
|
|
|
# # Check if the notification was sent
|
|
|
|
# resp = apns.Payload.from_stream(conn1.sock)
|
|
|
|
# print(resp)
|
2023-04-05 20:29:05 -05:00
|
|
|
|
2023-04-06 12:19:13 -05:00
|
|
|
# # Read the message from the other connection
|
|
|
|
# resp = apns.Payload.from_stream(conn2.sock)
|
|
|
|
# print(resp)
|