2017-04-13 27 views
0

Deal All,數據庫插入時的Ionic Push Notification

我正在接收推送通知的Ionic2上工作。它工作正常。我想更進一步。我需要自動執行推送通知。我在mySQL上使用PHP。我也有NodeJS WebApi。 NodeJS或PHP有沒有可能發送Ionic Push通知?我已經遵循的NodeJS下面的教程,但我得到401未經授權錯誤:

ionic-push-server

以下是錯誤:

STATUS: 401 
HEADERS: {"date":"Thu, 13 Apr 2017 19:13:09 GMT","content-type":"application/json; charset=utf-8","content-length":"196","connection":"close","server":"openresty","via":"1.1 vegur","access-control-allow-credentials":"true","access-control-allow-methods":"HEAD,GET,POST,PATCH,PUT,DELETE,OPTIONS","access-control-allow-headers":"DNT,Authorization,X-CSRFToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type"} 
BODY: {"meta": {"version": "2.0.0-beta.0", "status": 401, "request_id": "00000000-1111-2222-3333-444444444444"}, "error": {"link": null, "type": "Unauthorized", "message": "JWT decode error occurred."}} 
+0

錯誤消息告訴您,爲什麼您會收到一個401,' JWT解碼錯誤發生了' – Gntem

+0

太好了。謝謝。我意識到API密鑰是錯誤的。非常感謝。剛剛解決了您的建議的問題 –

回答

0
var ionicPushServer = require('ionic-push-server'); 

    var credentials = { 
     IonicApplicationID : "IonicAppId", 
     IonicApplicationAPItoken : "IonicApplicationAPIToken" //You need to generate from app settings 
    }; 

    var notification = { 
     "tokens": ["your", "device", "tokens"], 
     "profile": "AppProfileNameInSmallLetters", 
     "send_to_all": true, 
     "notification": { 
     "title": "Hi", 
     "message": "Hello world!", 
     "android": { 
      "title": "Hey", 
      "message": "Hello Android!", 
      "payload": { 
      "category": "Star" 
       } 
     }, 
     "ios": { 
      "title": "Howdy", 
      "message": "Hello iOS!", 
      "payload": { 
      "category": "Star" 
       } 
     } 
     } 
    }; 

    ionicPushServer(credentials, notification);