Created
February 28, 2023 11:01
-
-
Save Zedd0202/46d5ac491160c9422f8cc90f327e3e6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TEAM_ID=Team ID | |
TOKEN_KEY_FILE_NAME=path to the private key file | |
AUTH_KEY_ID=your key identifier | |
TOPIC=App ID | |
DEVICE_TOKEN=device token for your app | |
APNS_HOST_NAME=api.sandbox.push.apple.com | |
read -r -d '' PAYLOAD <<'EOF' | |
{ | |
"aps": { | |
"badge": 1, | |
"alert": { | |
"title": "불꽃남자", | |
"subtitle": "정대만", | |
"body": "❤️" | |
} | |
} | |
} | |
EOF | |
JWT_ISSUE_TIME=$(date +%s) | |
JWT_HEADER=$(printf '{ "alg": "ES256", "kid": "%s" }' "${AUTH_KEY_ID}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =) | |
JWT_CLAIMS=$(printf '{ "iss": "%s", "iat": %d }' "${TEAM_ID}" "${JWT_ISSUE_TIME}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =) | |
JWT_HEADER_CLAIMS="${JWT_HEADER}.${JWT_CLAIMS}" | |
JWT_SIGNED_HEADER_CLAIMS=$(printf "${JWT_HEADER_CLAIMS}" | openssl dgst -binary -sha256 -sign "${TOKEN_KEY_FILE_NAME}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =) | |
AUTHENTICATION_TOKEN="${JWT_HEADER}.${JWT_CLAIMS}.${JWT_SIGNED_HEADER_CLAIMS}" | |
curl -v --header "apns-topic: $TOPIC" --header "apns-push-type: alert" --header "authorization: bearer $AUTHENTICATION_TOKEN" --data "${PAYLOAD}" --http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://zeddios.tistory.com/1384