mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-24 03:42:43 -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.crt
|
||||||
push.key
|
push.key
|
||||||
|
token
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
36
apns.py
36
apns.py
|
@ -84,18 +84,30 @@ class Payload:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import courier
|
import courier
|
||||||
|
import base64
|
||||||
|
|
||||||
sock = courier.connect()
|
sock = courier.connect()
|
||||||
|
|
||||||
|
# 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()}))
|
payload = Payload(7, Fields({2: 0x01.to_bytes()}))
|
||||||
|
|
||||||
|
# Send the connect request (with or without the token)
|
||||||
sock.write(payload.to_bytes())
|
sock.write(payload.to_bytes())
|
||||||
print("recieved: ", Payload.from_stream(sock))
|
|
||||||
print("recieved: ", Payload.from_stream(sock))
|
# Read the response
|
||||||
sock.close()
|
resp = Payload.from_stream(sock)
|
||||||
# with socket.create_connection((COURIER_HOST, COURIER_PORT)) as sock:
|
# Check if the response is valid
|
||||||
# with context.wrap_socket(sock, server_hostname=COURIER_HOST) as ssock:
|
if resp.command != 8 or resp.fields.fields[1] != 0x00.to_bytes():
|
||||||
# payload = Payload(7, Fields({2: 0x01.to_bytes()}))
|
raise Exception("Failed to connect")
|
||||||
# #print(payload)
|
|
||||||
# #print(payload.to_bytes())
|
# If there's a new token, save it
|
||||||
# #print(Payload.from_bytes(payload.to_bytes()))
|
if 3 in resp.fields.fields:
|
||||||
# ssock.write(payload.to_bytes())
|
with open("token", "wb") as f:
|
||||||
# print("recieved: ", Payload.from_stream(ssock))
|
f.write(base64.b64encode(resp.fields.fields[3]))
|
||||||
# print("recieved: ", Payload.from_stream(ssock))
|
|
Loading…
Reference in a new issue