我有Android应用,它正在使用Azure IoT中心。 Azure上有几个表,其中一个表存储我的应用程序的注册用户的凭据。该表有一列名为" userId"和记录在这里是独一无二的。
我还有node.js脚本,该脚本将处理其中一个表中的数据,并通过GCM根据该数据发送推送通知。
function sendPush(userId, pushText)
{
var payload = pushText;
push.gcm.send(null, payload, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse, payload);
request.respond();
},
error: function (pushResponse) {
console.log("Error Sending push:", pushResponse);
}
});
}
我知道要使用Google Cloud Messaging进行有针对性的推送通知,您必须获得具有InstanceID类的令牌。 但我可以以某种方式使用" userId"列记录成为该令牌以使我的推送通知成为目标?
答案 0 :(得分:1)
一般来说,您可以利用Tags
param作为标记标识符来将通知推送到指定的设备。有关详情,请参阅Sending push notifications with Azure Notification Hubs and Node.js。
如果您的要求符合https://msdn.microsoft.com/en-us/library/azure/dn743807.aspx
中列出的正确方案,您可以在后端应用程序中注册标签在后端nodejs应用程序中,您可以尝试使用以下代码注册标记:
var notificationHubService = azure.createNotificationHubService('<nb-name>', '<nb-keys>');
notificationHubService.createRegistrationId(function(err,registerId){
notificationHubService.gcm.createNativeRegistration(registerId,"identifier-tags",function(err,response){
console.log(response)
})
})
然后您可以尝试使用send
函数中的标记。
如有任何疑问,请随时告诉我。