我正在使用一个信号API进行推送通知。我想知道如何发送带有value(Confirm = 1,Deny = 0)的按钮,以便可以从通知屏幕中发布它。我无法通过API发送该应用程序的操作按钮。我想将动作按钮的值发布到数据库中。请帮忙 这是我的代码。
function sendMessage(){
$heading=array(
"en" => 'TEST'
);
$content = array(
"en" => 'TEST.'
);
$hashes_array = array();
array_push($hashes_array, array(
"id" => "1",
"text" => "Confirm",
"icon" => "http://i.imgur.com/N8SN8ZS.png",
"url" => "https://yoursite.com"
));
array_push($hashes_array, array(
"id" => "0",
"text" => "Deny",
"icon" => "http://i.imgur.com/N8SN8ZS.png",
"url" => "https://yoursite.com"
));
$fields = array(
'app_id' => "xxxxxxx-xxxxxxx-45b8-97d4-02982b59c14f",
'include_player_ids' => array($GLOBALS['one_signal_id']),
'data' => array("Status" => 200),
'small_icon' => 'https://lh3.googleusercontent.com/TzYz9McRVy8fD_WnpKiCK5anw20So6eyPR9ti-LwTd_QIer8BpAg8cMkRoO4sUv2xCDw=w300-rw',
'large_icon' => 'https://lh3.googleusercontent.com/TzYz9McRVy8fD_WnpKiCK5anw20So6eyPR9ti-LwTd_QIer8BpAg8cMkRoO4sUv2xCDw',
'headings' => $heading,
'contents' => $content,
'web_buttons' => $hashes_array
);
$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 xxxxxxxxxxxxxxxxxxxxxx5NjktMjRkZWM0ZjFhMjZl'));
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();