我正在尝试使用OneSignal设置基于位置的推送通知,但是我没有收到通知。我收到了错误消息All included players are not subscribed
。我不知道问题出在哪里,请问有什么想法吗?
在OneSignal的“所有用户”列表中,未接收到通知的用户设置了预期的纬度和经度坐标的“位置点”,并已订阅。我可以发送没有位置信息的通知,因此发送和接收通知的过程有效。
我已将此行添加到我的AndroidManifest.xml文件中:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
我在我的.run
函数中也有这行代码:
window.plugins.OneSignal.promptLocation();
我用PHP向OneSignal发送请求的代码:
$content = $_GET['content'];
$lat = $_GET['lat'];
$long = $_GET['long'];
$radius = $_GET['radius'];
$response = sendMessage($content, $lat, $long, $radius);
function sendMessage($message, $lat, $long, $radius){
$content = array(
"en" => $message
);
$fields = array(
'app_id' => "aaaaaa-eeee-yyyyy-xxxx-zzzz",
'filters' => array(array("field" => "location", "radius" => $radius, "lat" => $lat, "long" => $long)),
//'filters' => array(array("field" => "location", "radius" => "1000", "lat" => "55.819329", "long" => "-4.1696119")),
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'contents' => $content
);
$fields = json_encode($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 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'));
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);
return $response;
}
请求:
{content: "test", lat: "55.8653169", long: "-4.1696119", radius: "1000"}
响应:
{allresponses: "{"id":"","recipients":0,"errors":["All included players are not subscribed"]}"}