/**
* @param $receive //推送用户
* @param $title //推送标题
* @param $content //推送
* @param $m_txt
* @return bool|string
*/
public function send($receive, $title, $content, $m_txt)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$api_key = config(fcm.apikey);
//准备消息内容
$data = [
'title' => $title,
'body' => $content,
'url'=> $m_txt
];
$fields = array(
//群发使用registration_ids[为数组] 单个用户使用to
'to' =>$receive ,
// 'registration_ids' => $receive,
'data' => $data,
'time_to_live' => 60,
);
$headers = array(
'Authorization:key='.$api_key,
'Content-Type:application/json'
);
$json = json_encode($fields);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
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_TIMEOUT, 5); //请求超时时间这里设置为5s
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
return $result;
}