gpt4 book ai didi

php - 如何在通知中心向特定用户发送推送通知?

转载 作者:行者123 更新时间:2023-11-29 00:44:51 27 4
gpt4 key购买 nike

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

最佳答案

根据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.

您可以创建与表关联的 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>");

关于php - 如何在通知中心向特定用户发送推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38749862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com