私は以下のコードを使用してプッシュ通知を正常に送信していますが、5-3回または1回のプッシュ通知が1つは送信する必要があります(すべての時間)。これは私のPHPはそれのように見えるものである - それは、プッシュ通知を送信するためにPHPを使用するためのストレートonesignal
例の外にある:OneSignalプッシュ通知は、一度だけ呼び出されたときに5回発生する - PHP/iOS
<?
$contentpost = "";
$appid = "";
$playerIds = "";
//error_log(print_r($_POST['app_id'], true)." ()*&*()*&()*&)(*&(*&)(*&()&*()*&()");
foreach ($_POST as $key => $value) {
if($key == 'app_id') {
$appid = $value;
}
if($key == 'content') {
$contentpost = $value;
}
if($key == 'include_player_ids') {
$playerIds = $value;
}
error_log($key." ".$value);
}
function sendMessage($contentr, $appidd, $players){
$content = array(
"en" => $contentr
);
$fields = array(
'app_id' => $appidd,
'include_player_ids' => array($players),
'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 xxxxxx'));
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;
}
$response = sendMessage($contentpost, $appid, $playerIds);
$return["allresponses"] = $response;
$return = json_encode($return);
//print("\n\nJSON received:\n");
print($return);
?>
上記のコードを実行すると、私は5、3を得る、または1つのプッシュ通知のいずれか私の電話に送った。私は常にそれが1つである必要があります。
更新 私はこの機能を取り除き、それを1つの連続したスクリプトにしてしまい、それは役に立たなかった。 ...スクリプトの下部に
error_log("running more than once");
、それはスクリプト全体を印刷することにより、複数回実行されていることを確認します:また、私は入れ
[07-Aug-2017 04:15:11 Europe/Berlin] running more than once
[07-Aug-2017 04:15:11 Europe/Berlin] "{\"id\":\"f7602a22-770c-491c-84c4-ba8cb89c773a\",\"recipients\":1}"
[07-Aug-2017 04:15:11 Europe/Berlin] running more than once
[07-Aug-2017 04:15:11 Europe/Berlin] "{\"id\":\"c3b60d5d-0045-422c-8fea-f3dbfc312480\",\"recipients\":1}"
[07-Aug-2017 04:15:11 Europe/Berlin] running more than once
[07-Aug-2017 04:15:11 Europe/Berlin] "{\"id\":\"802a1e0c-33ba-48b2-95f8-36b07d3404e5\",\"recipients\":1}"
[07-Aug-2017 04:15:11 Europe/Berlin] running more than once
[07-Aug-2017 04:15:11 Europe/Berlin] "{\"id\":\"928d3a29-29d0-4c78-a740-bc4559018c25\",\"recipients\":1}"
[07-Aug-2017 04:15:11 Europe/Berlin] running more than once
[07-Aug-2017 04:15:11 Europe/Berlin] "{\"id\":\"964e1dbc-41b4-40be-8edc-548c3fe74c5e\",\"recipients\":1}"
またていることがわかりますスクリプトは複数のプッシュ通知を作成しています。