android - Azure -> Node.js 中的 Easy api -> 如何发送 Android 推送通知?

标签 android node.js api azure push-notification

我们正在为我们的移动应用程序使用 azure easy API (node.js)。我们已经设置了通知中心并对其进行了测试 - 它们似乎都在工作。但是,我们不确定如何在简单的 API 中调用这些通知中心 - 我们遵循了 Microsoft 提供的整个文档(例如: http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-nodejs-how-to-use-notification-hubs/ )并尝试了多种方法。 有人可以指出如何专门从 Easy API 发送推送通知的示例/代码 fragment 吗?

谢谢 桑卡

最佳答案

针对您的情况,您可以按照以下步骤来实现您的目的。

  1. 通知中心设置完毕后,请转到“设置”菜单 您的应用程序服务,然后单击 Easy API 选项。单击+ 添加按钮并填写表格。 enter image description here
  2. 单击 API,然后单击“编辑脚本”。这将打开 Visual Studio Online。这将允许您在线编辑脚本。 enter image description here
  3. 编辑包含以下内容的 notification.js 文件:

    var azure = require('azure-sb');
    module.exports = {
        "post": function (req, res, next) {        
            var hubname = 'yourhubname';
            var connectionstring = 'yourconnectingstring';
            var notificationHubService = azure.createNotificationHubService(hubname, connectionstring);
            var payload = {
               data: {
                message: 'Hello!'
              }
            };
            notificationHubService.gcm.send(null, payload, function(error) {
              if(!error) {
                res.status(200).send('succ');
              }
            });
        }
    };
    

    注意:替换上面您自己的集线器名称和连接字符串。

  4. 通过 Kudu 安装 azure-sb 模块。返回 Azure 门户,选择您的 App Servcie,然后选择 Tools,然后选择 Kudu。单击“调试”控制台的 PowerShell 版本。 将目录更改为 site/wwwroot,然后在控制台中键入以下内容:

    npm install --save azure-sb

  5. 通过 Postman 测试您的简单 API: enter image description here

    最终,您的客户端设备将收到通知:

enter image description here

帮助它有帮助。如有任何进一步的疑问,请随时告诉我。

关于android - Azure -> Node.js 中的 Easy api -> 如何发送 Android 推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40154099/

相关文章:

android - 在 Android 中使用本地套接字将实时视频录制保存到 sd 卡 - 视频无法播放

JSON 和 Cygwin - 如何解析、获取字段等

android - Android 中的 MVC 架构

android - LinearLayout.LayoutParams如何使用dip...?

node.js - Azure 网站 node.js http 请求失败

node.js - 有没有人见过 javascript/nodejs 的单纯形库

javascript - 在 NodeJS 中导出 API 对象

Java 云 API

android - 如何在Android中命名协程?

node.js - 需要建议 : Latest version of Node. js 与使用 Synaptic 包管理器?