5

APNに接続しようとしています。単に接続されません。私は次のバリエーションを取得します:

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

apn Connection error occurred before TLS Handshake +0ms

通帳パス用です。アプリではありません。通帳証明書を使用しています。

私のコードは次のとおりです。

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);
4

3 に答える 3

1

証明書を混同したようです。私は以前にそれらを交換しようとしたと確信していますが、明らかにしませんでした。


cert:アプリの証明書。
キー:AppleのWWDR

于 2012-12-01T13:58:11.493 に答える
0

あなたはプロキシの後ろにいますか?それが問題になる可能性があります(少なくとも私の場合はよくあります)

于 2012-11-30T13:55:03.820 に答える
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 */
});
于 2012-11-30T15:11:35.527 に答える