i have integrated one-signal in my web application, notifications are working fine but if considering web page title in push notification title.
i need to set it custom title in my push notification.
i need to set custom message in place of "Dashboard"
Here is my code:
$content = array(
"en" => 'Hello Hii..!!'
);
$fields = array(
'app_id' => 'APP_ID',
'include_player_ids' => ['ids'],
'data' => array("foo" => "bar"),
'url' => 'URL',
'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 AuthorizationKey';
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;
set heading in your fields array
$content = array(
"en" => 'Your message..!!'
);
$heading = array(
"en" => "Your custom title message"
);
$fields = array(
'app_id' => 'YOUR_APP_ID',
'include_player_ids' => [ids],
'data' => array("foo" => "bar"),
'url' => 'http://www.yoursite.com',
'contents' => $content,
'headings' => $heading
);
Use this one as mention bellow
public function sendPush($players_id,$massage,$data,$heading){
// $players_id your device id where you want to push
$data1[]=$players_id;
//message for your push
$content = array(
"en" => $massage
);
// if you want to send data in for of JSON or some values
$data_response=array(
"value" => $data
);
//you can add heading through this
$heading = array( "en" => $heading);
// print_r($cat_data);
$fields = array(
'app_id' => 'YOUR_APP_ID',
'include_player_ids' => $data1,
'contents' => $content,
'headings' => $heading,
'data' =>$data_response
);
$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 YOUR_REST_API_KEY'));
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With