2017-08-14 67 views
2

我想爲OneSignal發送預定的消息,但不是使用他們的儀表板我想使用API​​來做到這一點,我沒有閱讀他們的文檔,但我找不到任何東西來修改它們的當前API這樣我就可以發送預定通知OneSignal - 發送預定的通知

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

回答

2

你可以找到這個文檔頁面上的計劃選項:https://documentation.onesignal.com/v3.0/reference#section-delivery

下面是可用的選項:

send_after(發送在以後的時間)

實例:

「星期四2015年9月24日14:00:00 GMT-0700(PDT)」

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

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

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

「星期四2015年9月24日14:00:00 GMT-0700(太平洋夏令時)」

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" 
); 
+0

謝謝您的幫助,我不不知道我錯過了選擇 – Nouf