我正在开发 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)注册设备,实际上我在服务端有可用的设备 token ,该 token 是通过 API 调用从设备发送的。
- 我想不时更新每个设备的多个标签。
- 我想在用户请求时取消注册设备。
- 我想使用模板向特定标签发送推送通知。
最佳答案
注册设备 token 并使用node.js中的通知中心发送通知的步骤如下:
- 创建注册 ID
- 创建注册
- 发送通知
收到设备 token 后,这是服务器端代码。请注意,注册 ID、设备 token 、标签和回调函数是 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);
}
});
关于node.js - 如何从服务器端(使用 NodeJS sdk)将设备注册到 Azure 通知中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27033194/