1 回答
TA贡献1900条经验 获得超5个赞
您可以在服务器端 PHP 中设置您的频道 ID
PHP服务器端
<?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个参数定义函数title,body,target,chid来使用它只是调用函数并定义它的参数,
您必须在客户端(Android 部分)中添加您的 channelId,如果没有 channelId,您将无法在 Android 8.0 及更高版本中收到通知
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报