2017-04-13 74 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);