我正在尝试使用curl在laravel中使用FCM,但是我遇到了错误。首先,我在我的控制器中编写了一个php代码:
$first_name = $request->input('first_name');
//FCM api URL
$url = 'https://fcm.googleapis.com/fcm/send';
//api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
$server_key = 'AIzaSyA1RyuAGGPASh_flFCwiyd9ZHEMYlhQOho';
$target = "r_token";
$fields = array();
$fields['data'] = $first_name;
if(is_array($target)){
$fields['registration_ids'] = $target;
}else{
$fields['to'] = $target;
}
//header with content_type api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
return $result;
我正在尝试在我的控制器中使用laravel 5.2运行此代码,但是我遇到了这个错误:
FatalErrorException in WebKyoController.php line 52:
Call to undefined function App\Http\Controllers\curl_init()
我尝试过:sudo apt-get install php-curl 和 apache restart,但仍然出现错误。我想知道我需要做什么。
sudo apt-get install curl
吗?请告诉我你的操作系统和版本。 - Qazi