无法连接node-apn

时间:2012-11-30 13:52:01

标签: node.js apn-node

我试图建立与APN的连接。它只是赢得了连接。我得到的变化:

  apn Socket error occurred +609ms { [Error: socket hang up] code: 'ECONNRESET' }

apn Connection error occurred before TLS Handshake +0ms

这是Passbook通行证。不是应用程序。我使用的是Passbook证书。

我的代码是:

var apns = require('apn');

var root = process.cwd();

var fs = require('fs');

var options = {
    cert: root + '/certs/new/cert.pem',                 /* Certificate file path */
    certData: null,                   /* String or Buffer containing certificate data, if supplied uses this instead of cert file path */
    key:  root + '/certs/new/key.pem',                  /* Key file path */
    keyData: null,                    /* String or Buffer containing key data, as certData */
    passphrase: 'secret',                 /* A passphrase for the Key file */
    ca: null,                         /* String or Buffer of CA data to use for the TLS connection */
    gateway: 'gateway.sandbox.push.apple.com',/* gateway address */
    port: 2195,                       /* gateway port */
    enhanced: true,                   /* enable enhanced format */
    errorCallback: undefined,         /* Callback when error occurs function(err,notification) */
    cacheLength: 100                  /* Number of notifications to cache for error purposes */
};

var apnsConnection = new apns.Connection(options);

var myDevice = new apns.Device('token');

var note = new apns.Notification();

note.payload = {};
note.device = myDevice;

apnsConnection.sendNotification(note);

3 个答案:

答案 0 :(得分:1)

似乎我混淆了我的证书。我敢肯定我曾尝试过早更换它们,但显然没有。

<小时/> 证书:您的应用证书。
密钥:Apple的WWDR

答案 1 :(得分:0)

你是代理人吗?这可能是问题(至少在我的情况下通常是这样)

答案 2 :(得分:0)

尝试以下结构:手动阅读.cert.key文件,并将它们分别设置为certDatakeyData属性。以下是核心:

var key = root + '/certs/new/key.pem'
var cert = root + '/certs/new/cert.pem';

var certData = fs.readFileSync(cert, encoding='ascii');
var keyData = fs.readFileSync(key, encoding='ascii');

var apnsConnection = new apns.Connection({
    certData: certData,
    keyData: keyData,
    gateway: 'gateway.sandbox.push.apple.com',
    port: 2195,
    ... /* other configs of course */
});