1 回答

TA貢獻1900條經(jīng)驗 獲得超5個贊
您可以在服務(wù)器端 PHP 中設(shè)置您的頻道 ID
PHP服務(wù)器端
<?php
function Notify($title,$body,$target,$chid)
{
define( 'API_ACCESS_KEY', 'enter here your API Key' );
$fcmMsg = array(
'title' => $title,
'body' => $body,
'channelId' => $chid,
);
$fcmFields = array(
'to' => $target, //tokens sending for notification
'notification' => $fcmMsg,
);
$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_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fcmFields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result . "\n\n";
}
?>
我Notify用4個參數(shù)定義函數(shù)title,body,target,chid來使用它只是調(diào)用函數(shù)并定義它的參數(shù),
您必須在客戶端(Android 部分)中添加您的 channelId,如果沒有 channelId,您將無法在 Android 8.0 及更高版本中收到通知
- 1 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報