如何将 aps.cer 文件用于带有 Node.js 的 APN(推送通知)?

How to use aps.cer file for APN (Push notification) with Node.js?

我在 node.js 发送推送通知时遇到问题,我想是因为我在我的苹果开发者帐户中生成的 APN 证书有问题。我从 Node.js 收到此错误。

VError: Failed to generate token: error:0906D06C:PEM routines:PEM_read_bio:no start line

我不确定我是否在苹果开发者帐户中生成了正确的文件。请参阅下面的屏幕截图,当我单击下载时,这会给我一个 "aps.cer" 文件,这是我放入 node.js 项目并与 node-app 模块一起使用的文件。这是我在我的代码中设置它的方式:

let options = {
        token: {
            key: "aps.cer",
            keyId: "singlemeout.Single-Me-Out",
            teamId: "Team Name"
        },
        production: false
    };

这是我的证书的屏幕截图。

您正在为 node-apn 提供基于令牌的配置,同时您正在使用证书。

如果您想继续使用证书:

  • 证书应为 PEM 格式。

    您可以这样进行转换:

    openssl x509 -inform DER -in aps.cer -out certificate.pem
    
  • 您需要提供密钥,可以将其添加到证书中,也可以将其作为单独的文件提供

  • 您需要在配置对象中使用 certkey 和/或 pfx 属性,而不是 token.key

    let options = {
            cert: "certificate.pem",
            key: "privatekey.pem"
        };
    

或者,您可以切换到使用令牌。

有关完整详细信息,请参阅 https://github.com/node-apn/node-apn/blob/master/doc/provider.markdown

另外你的production属性与使用的证书不一致