首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法连接node-apn

无法连接node-apn
EN

Stack Overflow用户
提问于 2012-11-30 21:52:01
回答 3查看 5.2K关注 0票数 5

我在试着连接APNs。它根本无法连接。我得到了以下的变体:

代码语言:javascript
复制
  apn Socket error occurred +609ms { [Error: socket hang up] code: 'ECONNRESET' }

代码语言:javascript
复制
apn Connection error occurred before TLS Handshake +0ms

这是一张通行证。不是一个应用程序。我用的是存折证书。

我的代码是:

代码语言:javascript
复制
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);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-01 21:58:11

看起来我把我的证书弄混了。我确定我之前试过交换它们,但显然没有。

证书:您的应用程序证书。

key:苹果的WWDR

票数 1
EN

Stack Overflow用户

发布于 2012-11-30 21:55:04

你在代理背后吗?这可能就是问题所在(至少在我的案例中经常是这样)

票数 0
EN

Stack Overflow用户

发布于 2012-11-30 23:11:36

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

代码语言:javascript
复制
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 */
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13646591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档