mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-23 11:22:42 -06:00
implement push tokens
This commit is contained in:
parent
b7df7a3b1e
commit
efa7fa6d99
2 changed files with 27 additions and 14 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# APNS keys
|
||||
# APNS
|
||||
push.crt
|
||||
push.key
|
||||
token
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
|
38
apns.py
38
apns.py
|
@ -84,18 +84,30 @@ class Payload:
|
|||
|
||||
if __name__ == "__main__":
|
||||
import courier
|
||||
import base64
|
||||
|
||||
sock = courier.connect()
|
||||
payload = Payload(7, Fields({2: 0x01.to_bytes()}))
|
||||
|
||||
# Try and read the token from the file
|
||||
try:
|
||||
with open("token", "r") as f:
|
||||
r = f.read()
|
||||
if r == "":
|
||||
raise FileNotFoundError
|
||||
payload = Payload(7, Fields({1: base64.b64decode(r), 2: 0x01.to_bytes()}))
|
||||
except FileNotFoundError:
|
||||
payload = Payload(7, Fields({2: 0x01.to_bytes()}))
|
||||
|
||||
# Send the connect request (with or without the token)
|
||||
sock.write(payload.to_bytes())
|
||||
print("recieved: ", Payload.from_stream(sock))
|
||||
print("recieved: ", Payload.from_stream(sock))
|
||||
sock.close()
|
||||
# with socket.create_connection((COURIER_HOST, COURIER_PORT)) as sock:
|
||||
# with context.wrap_socket(sock, server_hostname=COURIER_HOST) as ssock:
|
||||
# payload = Payload(7, Fields({2: 0x01.to_bytes()}))
|
||||
# #print(payload)
|
||||
# #print(payload.to_bytes())
|
||||
# #print(Payload.from_bytes(payload.to_bytes()))
|
||||
# ssock.write(payload.to_bytes())
|
||||
# print("recieved: ", Payload.from_stream(ssock))
|
||||
# print("recieved: ", Payload.from_stream(ssock))
|
||||
|
||||
# Read the response
|
||||
resp = Payload.from_stream(sock)
|
||||
# Check if the response is valid
|
||||
if resp.command != 8 or resp.fields.fields[1] != 0x00.to_bytes():
|
||||
raise Exception("Failed to connect")
|
||||
|
||||
# If there's a new token, save it
|
||||
if 3 in resp.fields.fields:
|
||||
with open("token", "wb") as f:
|
||||
f.write(base64.b64encode(resp.fields.fields[3]))
|
Loading…
Reference in a new issue