OneSignal - 发送预定通知

时间:2017-08-14 08:43:12

标签: api push-notification onesignal

我想为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");

1 个答案:

答案 0 :(得分:8)

您可以在此文档页面上找到计划选项:https://documentation.onesignal.com/v3.0/reference#section-delivery

以下是可用的选项:

  

send_after (稍后发送)

     

示例:

     

" Thu Sep 24 2015 14:00:00 GMT-0700(PDT)"

     

" 2015年9月24日,下午2:00:00 UTC-07:00"

     

" 2015-09-24 14:00:00 GMT-0700"

     

" 2015年9月24日14:00:00 GMT-0700"

     

" Thu Sep 24 2015 14:00:00 GMT-0700(Pacific Daylight Time)"

     

delayed_option

     

可能的值是:

     

"时区" (在每个用户拥有的特定时间发送   时区)

     

"一个活动" (按每个用户预测的最佳时间交付)。

     

delivery_time_of_day 与delayed_option = timezone一起使用。

     

示例:

     

" 9:00 AM"

您可以将这些选项添加到代码的字段部分,如下所示:

$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"
);