-
-
Save dmi3j/d10b6473592dfbc40240432ce0124d0e to your computer and use it in GitHub Desktop.
push notification curl
This file contains hidden or 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 | |
# to execute it first chmod +x push.sh | |
deviceToken=<device token id from device did receive token> | |
authKey="./AuthKey_<auth_key>.p8" | |
authKeyId=<auth_key> | |
teamId=<team id> | |
bundleId=<bundle id> | |
endpoint=https://api.development.push.apple.com | |
read -r -d '' payload <<-'EOF' | |
{ | |
"aps": { | |
"badge": 2, | |
"sound" : "default", | |
"category": "mycategory", | |
"alert": { | |
"title": "my title bla", | |
"subtitle": "my subtitle", | |
"body": "my body text message" | |
} | |
}, | |
"custom": { | |
"mykey": "myvalue" | |
} | |
} | |
EOF | |
# -------------------------------------------------------------------------- | |
base64() { | |
openssl base64 -e -A | tr -- '+/' '-_' | tr -d = | |
} | |
sign() { | |
printf "$1"| openssl dgst -binary -sha256 -sign "$authKey" | base64 | |
} | |
time=$(date +%s) | |
header=$(printf '{ "alg": "ES256", "kid": "%s" }' "$authKeyId" | base64) | |
claims=$(printf '{ "iss": "%s", "iat": %d }' "$teamId" "$time" | base64) | |
jwt="$header.$claims.$(sign $header.$claims)" | |
curl --verbose \ | |
--header "content-type: application/json" \ | |
--header "authorization: bearer $jwt" \ | |
--header "apns-topic: $bundleId" \ | |
--data "$payload" \ | |
$endpoint/3/device/$deviceToken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment