英文:
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.
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.
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="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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论