powershell - 如何在arm模板中配置APNS.Certificate

标签 powershell azure azure-powershell azure-notificationhub azure-rm-template

我正在使用以下 azuredeploy.json 文件在 Azure 云上设置通知中心。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "Gcm.GoogleApiKey": {
            "type": "string",
            "metadata": {
                "description": "Google Cloud Messaging API Key"
            },
            "defaultValue": "AIzaSyAyp9MernKgMS3wFNM3yNWByiP-TaGrqEg"
        },
        "APNS.Certificate": {
            "type": "string",
            "metadata": {
                "description": "A certificate (in base 64 format) provided by Apple on the iOS Provisioning Portal"
            },
            "defaultValue": ""
        },
        "APNS.certificateKey": {
            "type": "string",
            "metadata": {
                "description": "The Certificate Key provided by the iOS Provisioning Portal when registering the application"
            },
            "defaultValue": "ce469bf21dfa7b9d595d4999bfaca8a94ea47e46"
        },
        "APNS.endpoint": {
            "type": "string",
            "metadata": {
                "description": "The APNS endpoint to which our service connects. This is one of two values: gateway.sandbox.push.apple.com for the sandbox endpoint or gateway.push.apple.com, for the production endpoint. Any other value is invalid."
            },
            "allowedValues": [
                "gateway.sandbox.push.apple.com",
                "gateway.push.apple.com"
            ],
            "defaultValue": "gateway.push.apple.com"
        }
    },
    "variables": {
        "hubVersion": "[providers('Microsoft.NotificationHubs', 'namespaces').apiVersions[0]]",
        "notificationHubNamespace": "[concat('hubv2', uniqueString(resourceGroup().id))]",
        "notificationHubName": "notificationhub"
    },
    "resources": [
        {
            "name": "[variables('NotificationHubNamespace')]",
            "location": "[resourceGroup().location]",
            "type": "Microsoft.NotificationHubs/namespaces",
            "apiVersion": "[variables('hubVersion')]",
            "comments": "Notification hub namespace",
            "properties": {
                "namespaceType": "NotificationHub"
            },
            "resources": [
                {
                    "name": "[concat(variables('NotificationHubNamespace'),'/',variables('NotificationHubName'))]",
                    "location": "[resourceGroup().location]",
                    "type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
                    "apiVersion": "[variables('hubVersion')]",
                    "properties": {
                        "GcmCredential": {
                            "properties": {
                                "googleApiKey": "[parameters('Gcm.GoogleApiKey')]",
                                "gcmEndpoint": "https://android.googleapis.com/gcm/send"
                            }
                        }
                    },
                    "dependsOn": [
                        "[variables('NotificationHubNamespace')]"
                    ]
                }
            ]
        }
    ],
    "outputs": {
    }
}

现在我尝试使用以下代码片段设置苹果推送通知服务:

"apnsCredential": {
              "properties": {
                "apnsCertificate": "[parameters('APNS.Certificate')]",
                "certificateKey": "[parameters('APNS.certificateKey')]",
                "endpoint": " gateway.sandbox.push.apple.com or gateway.push.apple.com",
              }
            }

通过上述更改,我使用 powershell 命令提示符执行了 Deploy-AzureResourceGroup.ps1,执行时出现错误,并显示消息“错误请求”

谁能帮我解决这个问题。

最佳答案

添加正确的 APNS.Certificate 和 APNS.certificateKey。 它无法尝试验证您的详细信息,因此提出了错误的请求。 您需要一个 Base 64 格式的 APNS.Certificate。

APNS.证书:

这是 Base 64 字符串格式的 Apple 推送通知证书。

您可以使用 PowerShell 像这样转换证书(然后从输出文件“MyPushCert.txt”复制 key 并使用它。):

$fileContentBytes = get-content ‘Apple_Certificate.p12’ -Encoding Byte

[System.Convert]::ToBase64String($fileContentBytes) | Out-File ‘MyPushCert.txt’

APNS.certificateKey:

这是您导出证书时指定的密码。(您在创建证书时在 Apple 上创建的密码。)

关于powershell - 如何在arm模板中配置APNS.Certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40842783/

相关文章:

azure - keyVaultClient - 获取 secret

Azure 管理证书不起作用

azure-powershell - 使用 Powershell 从捕获的图像创建 ARM VM 时如何包含 "Plan information"?

PowerShell:带有 PID 的 AppActivate 不起作用

azure - 无法通过 Bicep 部署具有生命周期管理规则的 Azure 存储帐户

powershell - 检查大型 csv 文件是否匹配 ID 需要很长时间

azure - 在 Docker Swarm 中挂载 Azure 存储

azure - 如何检索 azure oms 工作区 ID 和 key ?

powershell - 无法将参数绑定(bind)到参数 'InputObject',因为它为空

Powershell - 与可执行文件的命令行提示交互?