Javascript 使用Cordova向特定用户发送OneSignal通知
我不能通过PHP中的RESTAPI向特定用户发送通知。 我从OneSignal中的所有用户处获取播放器ID的值 PHP代码Javascript 使用Cordova向特定用户发送OneSignal通知,javascript,cordova,onesignal,Javascript,Cordova,Onesignal,我不能通过PHP中的RESTAPI向特定用户发送通知。 我从OneSignal中的所有用户处获取播放器ID的值 PHP代码 <?php $content = array( "en" => "messaggio test" ); $fields = array( 'app_id' => "xxxxxxxx", 'included_segments' => array("All"), 'data' => array("foo" => "bar"), 'fi
<?php
$content = array(
"en" => "messaggio test"
);
$fields = array(
'app_id' => "xxxxxxxx",
'included_segments' => array("All"),
'data' => array("foo" => "bar"),
'filters' => array(array('field' => 'tag', 'key' =>
'userId', 'relation' => '=', 'value' => 'xxxxxxxxxxx')),
'contents' => $content
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic xxxxxxxxxxxxxxx'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
?>
此代码通过向所有设备发送通知而不是向单个用户发送通知来运行良好。
window.plugins.OneSignal.getIds(函数(ids)){
var device_id=ids.userId;
});代码>
window.plugins.OneSignal
.startInit("xxxxxxxxxxx")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
window.plugins.OneSignal.setSubscription(true);