如何向通知中心的特定用户发送推送通知?

How to Send Push Notification to a specific user on Notification Hub?

有什么方法可以向特定用户发送通知吗?我尝试使用 deviceToken。但是我找不到任何教程来展示我可以将通知发送到 devicetoken 的方法。

您将有一个设备令牌来发送推送。有几种方法可以获取设备令牌。下面的例子会对你有所帮助。

https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-aspnet-backend-windows-dotnet-wns-notification/

您可以使用 tags 来做到这一点。将唯一标签与每个用户相关联,然后向该标签发送通知。

Azure Notification Hubs Notify Users for iOS with .NET backend 是一个循序渐进的教程,让您了解如何使用标签。

How to use Notification Hubs from PHP 将在 PHP 中告诉您如何做到这一点。

另外,看看 and the sample它指的是什么。

准备好原型后,使用 Diagnosis guidelines 解决任何问题。

根据https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/#push-user上的描述:

When an authenticated user registers for push notifications, a user ID tag is automatically added to the registration. By using this tag, you can send push notifications to all devices registered by a specific user.

您可以创建一个关联到 table 的 EasyTable 脚本来存储经过身份验证的用户的 ID。您可以利用以下代码片段来实现这一点:

table.insert(function (context) {
    context.item.userId = context.user.id;
    return context.execute();
});

参考https://github.com/Azure/azure-content/blob/master/articles/app-service-mobile/app-service-mobile-node-backend-how-to-use-server-sdk.md#how-to-adjust-the-query-that-is-used-with-table-operations了解更多。

然后使用这个 PHP sample 发送通知用户 id:

$hub = new NotificationHub("<connectionString>", "<hubName>");
$message = '{"data":{"message":"Hello from PHP!"}}';
$notification = new Notification("gcm", $message);
$hub->sendNotification($notification, "_UserId:sid:<UserId>");