如何从服务器端注册设备到Azure通知中心(使用NodeJS sdk)?
我正在开发一个Windows Phone 8.1应用程序(RT),我正尝试使用Azure通知中心推送通知。 我可以用客户端SDK提供。 但是我想从服务器端进行设备注册,标记等。 我在http://blogs.msdn.com/b/azuremobile/archive/2014/04/08/push-notifications-using-notification-hub-and-net-backend.aspx上看到了一个很好的.Net后端指南。 我在后端服务器端使用NodeJS。 任何人都可以帮助我在相同的示例代码左右。
- 我想从服务器端(iPhone,Android和Windows Phone)注册设备,实际上我有通过API调用从设备发送的服务端可用的设备令牌。
- 我想要为每个设备更新多个标签不时。
- 我想在用户请求时取消注册设备。
- 我想发送推送通知到特定的标签,使用模板。
注册设备令牌并在node.js中使用通知中心发送通知的步骤如下:
- 创build一个注册ID
- 创build注册
- 发送通知
这是服务器端代码,一旦收到设备令牌。 请注意,注册ID,设备令牌,标记和callback函数是notificationHubService.apns.send调用的必需参数。
这里是代码片段:
var azure = require('azure'); var notificationHubService = azure.createNotificationHubService('<Hub Name>','<Connection String>'); var payload={ alert: 'Hello!' }; notificationHubService.createRegistrationId(function(error, registrationId, response){ if(!error){ console.log(response); console.log(registrationId); //RegistrationDescription registration = null; //registration.RegistrationId = registrationId; //registration.DeviceToken = req.body.token; notificationHubService.apns.createOrUpdateNativeRegistration(registrationId, req.body.token, req.token.upn, function(error, response){ if(!error){ console.log('Inside : createOrUpdateNativeRegistration' + response); notificationHubService.apns.send(null, payload, function(error){ if(!error){ // notification sent console.log('Success: Inside the notification send call to Hub.'); } }); } else{ console.log('Error in registering the device with Hub' + error); } }); } else{ console.log('Error in generating the registration Id' + error); } });
看看服务器端的开源SDK 。 我从来没有尝试过,但应该是可以的,因为任何SDK只是REST API的包装。
- Node.js + Express只能在testing服务器上的端口3000上运行
- 使用nodejs将数据从Rfid rc522发送到azureiot集线器
- 我可以通过复制文件在Azure节点应用程序服务器上部署node.js吗?
- Windows Azure节点JS WEBSOCKET HandShake失败503错误
- 连接到Azure移动服务上托pipe的Socket.IO服务器返回错误
- 上传,然后下载一个大的文件,与Windows Azure,blob存储和nodejs
- 使用docker镜像的Azure Linux应用程序服务中的Mongo连接错误
- Microsoft Azure免费网站问题(NodeJS服务器)
- 如何解决Azure中的500.1002错误?