curlを使用してlaravelでFCMを使用しようとしていますが、エラーが発生しています。最初に私は、私のcotrollerのいずれかに1つのPHPコードを書かれている:Laravel 5.2 curl_init()throwing error "未定義関数への呼び出し"
$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 php-curlとapache restartをインストールしても、まだエラーが出ます。私は何をする必要があるのかを知りたいだけです。
あなたは 'sudo apt-get install curl'でもあなたの操作とバージョンを教えてくれましたか? – Qazi
いいえ私はこのsudoを試していないapt-get curlをインストールするubuntu 14.04を使用しています。それはカールが既にインストールされていると言います。 –