#!/bin/bash
deviceToken=9a901217b5cc22376d90994d6070effed9bbd35b0ed4df171aa070f730b73911
authKey="/Users/Ewenlong03/Downloads/ChengYu/AuthKey_9B2QA848M3.p8"
authKeyId=9B2QA848M3
teamId=WZ3C6S544H
bundleId=cn.beecloud.cyu
endpoint=https://api.development.push.apple.com
#// "https://api.push.apple.com"
read -r -d '' payload <<-'EOF'
{
"aps": {
"alert": {
"vip": 1
},
"content-available": 1
}
}
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
错误码
200 Success
400 Bad request
403 There was an error with the certificate.
405 The request used a bad :method value. Only POST requests are supported.
410 The device token is no longer active for the topic.
413 The notification payload was too large.
429 The server received too many requests for the same device token.
500 Internal server error
503 The server is shutting down and unavailable.