1
なぜcurl_exec()が私のWebサービスで配列を返すのですか?なぜ私のWebサービスでcurl_exec()が応答を返していますか?
Firebaseでプッシュ通知を送信するためのWebサービスを作成しました。たとえ私がそれを尋ねなかったとしても、通知の結果にサーバーの応答が来ていることを除いて、何も完全にうまくいっています。
$this->send_notification($request->provider_id,'provider',0);
それから私は、Webアプリケーションのクライアント側部分の成功メッセージを印刷:
$response_array = array(
'success' => true,
'request_id' => $requests->id,
'current_provider' => $request->provider_id,
'address' => $requests->s_address,
'latitude' => $requests->s_latitude,
'longitude' => $requests->s_longitude,
);
$response = response()->json($response_array, 200);
return $response;
でも私ならばここで
public function send_notification($recipient_id,$recipient_type,$request_status)
{
$url = "https://fcm.googleapis.com/fcm/send";
$token = $user_device_token;
$notification = array(
'title' => $title,
'text' => $body,
'sound' => 'default',
'badge' => '1'
);
$arrayToSend = array(
'to' => $token,
'notification' => $notification,
'priority' => 'high'
);
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key=' . $server_key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//Send the request
error_reporting(E_ERROR);
$response_notification = curl_exec($ch);
if ($response_notification === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
return $response_notification;
}
は私がsend_notification()関数を呼び出す方法です応答に添付されたcurl_exec($ ch)の呼び出し時に通知応答が生成されました。
最初の行は、私はしたくないと私は期待していないですものです。
ありがとうございました! – 118218