Script test push to IOS
Note that it requires the key.p8 which was generated in Apple Developer portal
#!/bin/bash
# To get curl with HTTP/2 and openssl with ECDSA: run 'brew install curl-openssl'
curl=/usr/bin/curl
openssl=/usr/local/opt/openssl/bin/openssl
deviceToken="ENTER HERE DEVICE TOKEN"
authKey="./key.p8"
authKeyId="5LDMJW5L9X"
teamId="MV75HK3DF3"
bundleId="com.iberia.popeyes"
endpoint="https://api.development.push.apple.com"
#endpoint="https://api.sandbox.push.apple.com:443"
#endpoint="https://api.push.apple.com:443"
read -r -d '' payload <<-'EOF'
{
"aps": {
"badge": 1,
"alert": {
"title": "Helloo",
"body": "Tudo certo?!!"
},
"sound":"default"
},
"_sid": "SFMC",
"_od" : "menu"
}
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