2014-05-21 31 views
5

我使用apn將推送通知從node.js應用程序發送到Apple。發送推送通知後,應用程序卡住'輸入PEM密碼短語'

我的代碼:

// send to development**** 
    var dev_cert_path = path.join(__dirname, '..', 'cert.pem'); 
    var dev_key_path = path.join(__dirname, '..', 'key.pem'); 
    var devOptions = { "gateway": "gateway.sandbox.push.apple.com" , "cert": dev_cert_path, "key": dev_key_path, "passphrase":'XXXXX'}; 


    var devApnConnection = new apn.Connection(devOptions) 
    , devMyDevice = new apn.Device(token) 
    , devNote = new apn.Notification(); 

    devNote.expiry = Math.floor(Date.now()/1000) + 3600; // Expires 1 hour from now. 
    devNote.badge = 3; 
    devNote.sound = "xxx.aiff"; 
    devNote.alert = message; 
    devNote.payload = {'messageFrom': ''}; 
    devApnConnection.pushNotification(devNote, devMyDevice); 
    var options = { 
    "batchFeedback": true, 
    "interval": 1 
    }; 

    var devFeedback = new apn.Feedback(options); 
     devFeedback.on("feedback", function(devices) { 
      devices.forEach(function(item) { 
       logger.debug("device error : " + item.device); 
       // Do something with item.device and item.time; 
      }); 
    }); 

    devApnConnection.on('transmitted', function(res){ 
     logger.debug("sent this message:"+JSON.stringify(devNote)+ " to this device: " + devMyDevice); 
    }); 

    devApnConnection.on('error', function(res){ 
     logger.error("sending message failed to this device: " + devMyDevice + " data: " + JSON.stringify(res)); 
    }); 


} 
catch(e) 
    {logger.error("Push notification error: ",e.message);} 

我的問題:

當發送到node.js的請求時,它發送一個推送通知,但我在終端越來越多Enter PEM pass phrase:

/projects/my_app$ node app.js 

POST /requests 200 14ms 
Enter PEM pass phrase: 
Enter PEM pass phrase: 
Enter PEM pass phrase: 
Enter PEM pass phrase: 
Enter PEM pass phrase: 
Enter PEM pass phrase: 

所以我的應用程序被卡住直到重新啓動節點... 有什麼想法?

編輯:

我試圖從文件中刪除密碼:

openssl rsa -in key.pem -out nopassword.pem 

但我仍然得到這個在控制檯應用程序 - 但是當按下回車鍵,停止拍攝此消息,直到下一個請求(在刪除通行證之前,它顯示許多消息,直到重新啓動應用程序,還單擊輸入時,或通行短語)...

回答

6

我發現問題...

我必須將證書,密鑰和密碼添加到反饋選項。

var options = { 
    "batchFeedback": true, 
    "interval": 300 
}; 

var devFeedback = new apn.Feedback(options); 
     devFeedback.on("feedback", function(devices) { 
      devices.forEach(function(item) { 
       logger.debug("device error : " + item.device); 
       // Do something with item.device and item.time; 
      }); 
}); 

的選項應該是:

+1

對我不起作用 –

+0

還在繼續'輸入PEM密碼短語:'?分享你的代碼。 – user2503775

0

看起來你把生成私鑰& CSR時輸入密碼的挑戰。只要你知道密碼,使用openssl將它剝離出一個你需要使用的新文件。

openssl rsa -in private.key -out private-wo.key -passin pass:<PASSWORD>