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

huangapple go评论68阅读模式
英文:

I want to send call notification from terminal using .pem

问题

I want to send call notification using terminal and .pem file. all code looking good at my end. terminal throw this error.

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

pushregistrytoken retrieve from app and try this command on terminal.

curl -v -d '{ "aps": { "alert": "hello" } }' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/pushregistrytoken

here i use http2 protocol

Resource: https://websitebeaver.com/callkit-swift-tutorial-super-easy

i am working with terminal to send notification for first time.

Thanks.

英文:

I want to send call notification using terminal and .pem file. all code looking good at my end. terminal throw this error.

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

pushregistrytoken retrieve from app and try this command on terminal.

curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/pushregistrytoken

here i use http2 protocol

Resource : https://websitebeaver.com/callkit-swift-tutorial-super-easy

i am working with terminal to send notification for first time.

Thanks.

答案1

得分: 1

以下是您要翻译的内容:

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

注意:这是您提供的代码的翻译部分。

英文:

The old certificate and password way is no longer works ,you need to create an AuthKey.p8 along with it's authKey and replace the entries here according to your developer settings , then wrap the below code inside File.sh and execute it from terminal $ bash pathToFile/File.sh

#!/bin/bash

deviceToken=&quot;tokenHere&quot;
authKey=&quot;pathTo........./AuthKey.p8&quot;
authKeyId=&quot;.......&quot;
teamId=&quot;........&quot;
bundleId=&quot;........&quot;
endpoint=&quot;https://api.sandbox.push.apple.com:2197&quot;
apns_collapse_id=&quot;send_update&quot;

read -r -d &#39;&#39; payload &lt;&lt;-&#39;EOF&#39;
{
   &quot;aps&quot;: {
      &quot;badge&quot;: 2,
      &quot;category&quot;: &quot;mycategory&quot;,
      &quot;alert&quot;: {
         &quot;title&quot;: &quot;my title&quot;,
         &quot;subtitle&quot;: &quot;my subtitle&quot;,
         &quot;body&quot;: &quot;my body text message 103&quot;
      }
   },
   &quot;custom&quot;: {
      &quot;id&quot;: &quot;1234&quot;
   }
}

EOF

# --------------------------------------------------------------------------

base64() {
   openssl base64 -e -A | tr -- &#39;+/&#39; &#39;-_&#39; | tr -d =
}

sign() {
   printf &quot;$1&quot;| openssl dgst -binary -sha256 -sign &quot;$authKey&quot; | base64
}

time=$(date +%s)
header=$(printf &#39;{ &quot;alg&quot;: &quot;ES256&quot;, &quot;kid&quot;: &quot;%s&quot; }&#39; &quot;$authKeyId&quot; | base64)
claims=$(printf &#39;{ &quot;iss&quot;: &quot;%s&quot;, &quot;iat&quot;: %d }&#39; &quot;$teamId&quot; &quot;$time&quot; | base64)
jwt=&quot;$header.$claims.$(sign $header.$claims)&quot;

curl --verbose \
   --header &quot;content-type: application/json&quot; \
   --header &quot;authorization: bearer $jwt&quot; \
   --header &quot;apns-topic: $bundleId&quot; \
   --header &quot;apns-collapse-id: $apns_collapse_id&quot;\
   --http2 \
   --data &quot;$payload&quot; \
   $endpoint/3/device/$deviceToken

huangapple
  • 本文由 发表于 2023年5月17日 15:31:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定