数据库插入的离子推送通知

时间:2017-04-13 19:29:12

标签: node.js push-notification ionic2

全部交易,

我正在处理接收推送通知的Ionic2。它工作正常。我想更进一步。我需要自动化推送通知。我正在使用PHP和mySQL。我也有NodeJS WebApi。在NodeJS或PHP中是否有可能发送Ionic Push通知?我在NodeJS中遵循了以下教程,但我得到401 Unauthorized错误:

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."}}

1 个答案:

答案 0 :(得分: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);