我想使用 .pem 从终端发送呼叫通知

问题描述 投票:0回答:1

我想使用

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

我正在使用终端发送第一次通知。

谢谢。

swift terminal apple-push-notifications callkit
1个回答
0
投票

旧的证书和密码方式不再有效,您需要创建一个 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

© www.soinside.com 2019 - 2024. All rights reserved.