APNS SHELL SAMPLE

apns-push.sh

Get curl with HTTP/2 and openssl with ECDSA: ‘brew install curl openssl’
curl=/usr/bin/curl
openssl=/usr/bin/openssl
————————————————————————–
HostDevelopment = “https://api.development.push.apple.com”
HostProduction = “https://api.push.apple.com”
deviceToken=A4A9C1DACC0D0B858EC81EBCD2D01BA06FA4F9C213C3AE8A60242C1BFCC0D854
authKey=”./AuthKey_G9PBT4SCXY.p8″
authKeyId=G9PBT4SCXY
teamId=88JGVVK94C
bundleId=com.eziagent.yiju
endpoint=https://api.development.push.apple.com
read -r -d ” payload <<-‘EOF’
{
“aps”: {
“badge”: 2,
“category”: “mycategory”,
“alert”: {
“title”: “my title”,
“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)”
jwt=”eyJhbGciOiJFUzI1NiIsImtpZCI6Ikc5UEJUNFNDWFkifQ.eyJpc3MiOiI4OEpHVlZLOTRDIiwiaWF0IjoxNTY4NzY2NzE1fQ.ALK89Vj1_IKqScmArkqSvJLL_RJfDQsMB_FnWMt31BKzf8Hbs0zkccG7AX3OWU9iMCkM8KKrpnvOOzgnG7tO8Q”
$curl –verbose \
–header “content-type: application/json” \
–header “authorization: bearer $jwt” \
–header “apns-topic: $bundleId” \
–data “$payload” \
$endpoint/3/device/$deviceToken
echo “Private Key:”
echo $jwt
echo “Header: “
echo $header
echo “Body: “
echo $claims

Leave a Comment

Your email address will not be published.