OneSignal - 发送预定通知
OneSignal - Send scheduled notification
我想为 OneSignal 发送预定消息,但我不想使用他们的仪表板,而是想使用 API 来执行此操作,我确实阅读了他们的文档,但我找不到任何可以修改他们的信息当前 API 所以我可以发送预定的通知
function sendMessage(){
$content = array(
"en" => $message,
);
$fields = array(
'app_id' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'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 NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj'));
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();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
您可以在此文档页面上找到计划选项:https://documentation.onesignal.com/v3.0/reference#section-delivery
以下是可用的选项:
send_after (Send at a later time)
Examples:
"Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
"September 24th 2015, 2:00:00 pm UTC-07:00"
"2015-09-24 14:00:00 GMT-0700"
"Sept 24 2015 14:00:00 GMT-0700"
"Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
delayed_option
Possible values are:
"timezone" (Deliver at a specific time-of-day in each users own
timezone)
"last-active" (Deliver at the predicted best time of day to each user).
delivery_time_of_day Use with delayed_option=timezone.
Example:
"9:00AM"
您可以将这些选项添加到代码的字段部分,如下所示:
$fields = array(
'app_id' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'contents' => $content,
'send_after' => "Sept 24 2017 14:00:00 GMT-0700"
);
我想为 OneSignal 发送预定消息,但我不想使用他们的仪表板,而是想使用 API 来执行此操作,我确实阅读了他们的文档,但我找不到任何可以修改他们的信息当前 API 所以我可以发送预定的通知
function sendMessage(){
$content = array(
"en" => $message,
);
$fields = array(
'app_id' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'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 NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj'));
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();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
您可以在此文档页面上找到计划选项:https://documentation.onesignal.com/v3.0/reference#section-delivery
以下是可用的选项:
send_after (Send at a later time)
Examples:
"Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
"September 24th 2015, 2:00:00 pm UTC-07:00"
"2015-09-24 14:00:00 GMT-0700"
"Sept 24 2015 14:00:00 GMT-0700"
"Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
delayed_option
Possible values are:
"timezone" (Deliver at a specific time-of-day in each users own timezone)
"last-active" (Deliver at the predicted best time of day to each user).
delivery_time_of_day Use with delayed_option=timezone.
Example:
"9:00AM"
您可以将这些选项添加到代码的字段部分,如下所示:
$fields = array(
'app_id' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'contents' => $content,
'send_after' => "Sept 24 2017 14:00:00 GMT-0700"
);