gpt4 book ai didi

php - Curl 在 Codeigniter 中失败 : OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to fcm. googleapis.com:443

转载 作者:可可西里 更新时间:2023-11-01 12:38:34 37 4
gpt4 key购买 nike

我将 Fire-base 通知 CRUL 代码与 Codeigniter 集成在一起。有时我会收到错误,但并非总是如此。

我已经将下面的代码集成到 Controller 中

Controller 代码

$newDate=Date('m-d-Y H:i:s');

$test_str=$user->us_name. ' Clocked at '.$newDate;
$res = array();

$res['data']['title'] = $user->us_name.' - Clocked In';
$res['data']['is_background'] = "TRUE";
$res['data']['message'] = $test_str;
$res['data']['image'] = 'http://api.androidhive.info/images/minion.jpg';
$res['data']['payload'] = 'individual';
$res['data']['timestamp'] = date('Y-m-d G:i:s');
$res['data']['act_tab'] = 0;


$cur_id1=$this->db->query("Select token from devices")->result();

foreach($cur_id1 as $cur_id) {

$fields = array('to' => $cur_id->token,'data' => $res);
$this->notif_model->sendPushNotification($fields);
}

模型代码

function sendPushNotification($fields) {


// Set POST variables
$url = 'https://fcm.googleapis.com/fcm/send';

$headers = array(
'Authorization: key=MyServerKey',
'Content-Type: application/json'
);
// 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);

// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}

// Close connection
curl_close($ch);

return $result;
}

运行时有时会出现错误

Curl failed: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to fcm.googleapis.com:443

最佳答案

尝试添加curl_setopt($ch, CURLOPT_SSLVERSION, 3);

关于php - Curl 在 Codeigniter 中失败 : OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to fcm. googleapis.com:443,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49423326/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com