php 从传统FCM API迁移到HTTP v1

kx5bkwkv  于 2023-06-28  发布在  PHP
关注(0)|答案(1)|浏览(182)
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';,但没有收到通知。我需要生成新的服务器密钥还是需要旧密钥?

相关问题