编程语言
首页 > 编程语言> > php – OneSignal在Web推送通知中设置自定义标题消息

php – OneSignal在Web推送通知中设置自定义标题消息

作者:互联网

我已经在我的网络应用程序中集成了单信号,通知工作正常,但如果考虑推送通知标题中的网页标题.

我需要在推送通知中设置自定义标题.

enter image description here

我需要设置自定义消息来代替“仪表板”

这是我的代码:

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

解决方法:

在您的fields数组中设置标题

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

标签:php,web,onesignal
来源: https://codeday.me/bug/20190527/1162958.html