public function fcm_command($token,$command){
$path_to_fcm = 'https://fcm.googleapis.com/v1/projects/projects/messages:send';
//Taglock Server Key
$server_key = "";
$headers = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$fields = array('to'=>$token,'data'=>array('command'=>$command));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$res = curl_exec($curl_session);
curl_close($curl_session);
return array('status'=>REST_Controller::HTTP_OK,'message'=> 'Command sent to device');
}
我使用旧的$server_key,只更新了$path_to_fcm = 'https://fcm.googleapis.com/v1/projects/projects/messages:send';
,但没有收到通知。我需要生成新的服务器密钥还是需要旧密钥?
1条答案
按热度按时间r7knjye21#
v1 API的身份验证/授权不再使用服务器密钥。我建议您阅读authorizing send requests上的文档,以找到您当前的选项,并查看: