如何从服务器端注册设备到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中使用通知中心发送通知的步骤如下:

  1. 创build一个注册ID
  2. 创build注册
  3. 发送通知

这是服务器端代码,一旦收到设备令牌。 请注意,注册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的包装。