我想使用
terminal
和.pem
文件发送呼叫通知。所有代码在我这边看起来都不错。终端抛出这个错误。
pushregistrytoken
从应用程序检索并在终端上尝试此命令。
curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/pushregistrytoken
这里我使用
http2
协议
资源:https://websitebeaver.com/callkit-swift-tutorial-super-easy
我正在使用终端发送第一次通知。
谢谢。
旧的证书和密码方式不再有效,您需要创建一个 AuthKey.p8 以及它的 authKey 并根据您的开发人员设置替换此处的条目,然后将以下代码包装在 File.sh 中并从终端执行它 $ bash pathToFile/File.sh
#!/bin/bash
deviceToken="tokenHere"
authKey="pathTo........./AuthKey.p8"
authKeyId="......."
teamId="........"
bundleId="........"
endpoint="https://api.sandbox.push.apple.com:2197"
apns_collapse_id="send_update"
read -r -d '' payload <<-'EOF'
{
"aps": {
"badge": 2,
"category": "mycategory",
"alert": {
"title": "my title",
"subtitle": "my subtitle",
"body": "my body text message 103"
}
},
"custom": {
"id": "1234"
}
}
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" \
--header "apns-collapse-id: $apns_collapse_id"\
--http2 \
--data "$payload" \
$endpoint/3/device/$deviceToken