0

您能否仅使用单个 .pem 和密码短语与 apnagent 连接?或者我也需要一个单独的密钥 .pem 吗?

我对不同的证书文件及其用途有点无知,所以我不确定我的错误是试图只使用 .pem 文件和密码,还是我犯了其他错误。

当我运行以下代码时,我没有收到错误或成功响应。只有我的“等待事件......”

'use strict'
const apnagent = require('apnagent')
const join = require('path').join
const certFile = join(__dirname,'/../certs/mint-APN-dev.pem')
const deviceToken = '<token>'
const passphrase = '<passphrase>'

let agent = module.exports = new apnagent.Agent()
agent
    .set('cert file',certFile)
    .set('passphrase',passphrase)
    .enable('sandbox')

agent.connect(function (err) {

    if (err && err.name === 'GatewayAuthorizationError') {
        console.log('Authentication Error: %s', err.message)
        process.exit(1)
    }


    else if (err) {
        throw err
    }


    var env = agent.enabled('sandbox')
        ? 'sandbox'
        : 'production'

    console.log('apnagent [%s] gateway connected', env)
})

// keep it running for a bit to give it time to succeed or fail
let id = setInterval(function() {
    console.log('Waiting for events...')
    count++
    if (count > 18) clearInterval(id)
}, 5000)
4

1 回答 1

0

没关系。经过更多测试后,我回答了自己的问题。使用 .pem 文件,您必须同时拥有密钥和证书。但是对于 .p12 文件,您只能拥有一个文件

于 2016-08-08T19:15:57.170 回答