【问题标题】:Ionic Push Notification on database Insertion数据库插入的离子推送通知
【发布时间】:2017-04-14 04:04:15
【问题描述】:

全部成交,

我正在研究接收推送通知的 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."}}

【问题讨论】:

  • 错误消息告诉您为什么会收到 401 JWT decode error occurred
  • 哦,太好了。谢谢。我意识到 API 密钥是错误的。非常感谢。刚刚用你的建议解决了问题

标签: node.js push-notification ionic2


【解决方案1】:
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);

【讨论】:

  • 什么是 IonicApplicationAPItoken,我在哪里可以找到它。
  • 当您在 Ionic Push Server 云中创建推送服务器应用程序时,您将获得它。但不幸的是,他们已经停止推送通知应用服务器或云。您可以使用其他免费服务。我用的是OneSignal
猜你喜欢
  • 2016-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
相关资源
最近更新 更多