gpt4 book ai didi

php - 使用 PHP 进行博览会推送通知

转载 作者:行者123 更新时间:2023-12-03 18:37:25 28 4
gpt4 key购买 nike

我正在尝试使用 PHP 向我的 native 应用程序发送推送通知,
下面的代码也发送了所有注册了他们的 token 的用户,虽然 token 是针对特定设备的,但它会立即发送大量通知,但它不断向所有人推送通知

$key = "ExponentPushToken[0GAEokJazChx21MOxeC1l2]";
$title = "title";
$interestDetails = ['https://exp.host/--/api/v2/push/send',$key];

try{

$expo = \ExponentPhpSDK\Expo::normalSetup();

// Subscribe the recipient to the server
$expo->subscribe($interestDetails[0], $interestDetails[1]);

// Build the notification data

$notification = ['title' => $title,'body' => $msg];

// Notify an interest with a notification
$expo->notify($notification);

$status = 'success';
}catch(Exception $e){



}


?>

我尝试更改我的代码如下
<?php

$key = "ExponentPushToken[0GAEokJazChx21MOxeC1l2]";
$title = "title";


try{

$expo = \ExponentPhpSDK\Expo::normalSetup();



// Build the notification data

$notification = ['to' => $key,'title' => $title,'body' => $msg];

// Notify an interest with a notification
$expo->notify('https://exp.host/--/api/v2/push/send',$notification);

$status = 'success';
}catch(Exception $e){
echo $e;
}




echo $status;


?>

它确实发送给特定用户,但仍然一次发送大量通知?

最佳答案

试试这个

$key = "ExponentPushToken[0GAEokJazChx21MOxeC1l2]";
$userId = 'userId from your database';
$notification = ['title' => $title,'body' => $msg];
try{

$expo = \ExponentPhpSDK\Expo::normalSetup();
$expo->notify($userId,$notification);//$userId from database
$status = 'success';
}catch(Exception $e){
$expo->subscribe($userId, $key); //$userId from database
$expo->notify($userId,$notification);
$status = 'new subscribtion';
}

echo $status;
?>

关于php - 使用 PHP 进行博览会推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52952898/

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