Anonymous
Переход с устаревших API FCM на HTTP v1
Сообщение
Anonymous » 07 дек 2024, 14:18
Код: Выделить всё
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/ ... sages:send ';, но уведомление не приходит. Нужно ли мне генерировать новый ключ сервера или требуется старый?
Подробнее здесь:
https://stackoverflow.com/questions/765 ... to-http-v1
1733570330
Anonymous
[code]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'); } [/code] Я использую старый $server_key и обновил только $path_to_fcm = 'https://fcm.googleapis.com/v1/projects/projects/messages:send';, но уведомление не приходит. Нужно ли мне генерировать новый ключ сервера или требуется старый? Подробнее здесь: [url]https://stackoverflow.com/questions/76540440/migrate-from-legacy-fcm-apis-to-http-v1[/url]