有人请帮助我使用存储在 onesignal 变量中的多个玩家 ID。
我有一个名为 $onesigId 的变量,它包含以下值字符串:“2”、“3”、“77”、“99”。在我的 onesignal 发送函数中,我将它设为这样的数组: $onesigId = array($onesigId); 但是当我发送通知时,结果显示如下:
JSON sent: {"app_id":"my_app_id","headings":{"en":"Amazing Features"},"include_external_user_ids":["\"2\",\"3\",\"77\",\"99\""],"data":{"foo":"bar"},"url":"https:\/\/testurl.com\/help","contents":{"en":"My testing message"}} JSON received: {"allresponses":"{\"id\":\"\",\"recipients\":0,\"errors\":[\"All included players are not subscribed\"]}"}
下面是我的代码:
$userids = array();
$tu = 2;
$on=1;
$sql = $db -> prepare('SELECT id FROM users WHERE regTarget=? AND is_active=?');
$sql -> bind_param('ii', $tu, $on);
$sql -> execute();
$result = $sql->get_result();
while($row = mysqli_fetch_assoc($result) ){
$userids[]= $row['id'];
}
$str = '"' . implode ( '","', $userids ) . '"';
//echo $str;
//SEND ONESIGNAL PUSH
$onesigTitle = "$subject";
$onesigMessage = "$message.";
$onesigId = "$str";
$onesignalUrl = "$link";
function sendMessage(){
global $onesigTitle;
global $onesigMessage;
global $onesignalUrl;
global $onesigId;
$onesigId = array($onesigId);
$content = array(
"en" => $onesigMessage
);
$fields = array(
'app_id' => "my_app_id",
'headings' => array("en" => $onesigTitle),
'include_external_user_ids' => $onesigId,
'data' => array("foo" => "bar"),
'url' => $onesignalUrl,
'contents' => $content
);
}
请注意,所有其他变量都按预期工作,只有 $onesigId 行为不当。当我只添加一个 id 时,它发送成功。我想知道为什么 array("2","3","77", "99") 变成了 "\"2\",\"3\",\"77\",\"99\ “”在响应中以及如何修复它。
对你的帮助表示感谢。
动漫人物