我在项目中集成了推送通知。以下是我发送通知的代码:
define( 'API_ACCESS_KEY', 'Access_key' );
$data = array("to" => 'token',
"notification" => array( "title" => 'title', "body" => 'message', "icon" => '/account/images/test.png', "click_action" => 'redirect_url', ));
$data_string = json_encode($data);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);
curl_close ($ch);
此代码工作正常,但问题是图像未显示在通知中。我不知道为什么。问题出在哪里,如何在通知中显示图像?
答案 0 :(得分:2)
我发现了错误,我将图标网址设为http://www.example.com,而图标网址始终需要https://www.example.com这样的安全网址。由于网址不安全,它不会在通知中显示图标。