gpt4 book ai didi

php - 谷歌云消息错误 500(内部服务器错误)

转载 作者:行者123 更新时间:2023-11-29 20:26:28 24 4
gpt4 key购买 nike

来自 PHP 的 Google 云消息传递调用。我搜索了很多错误代码,很多人都说在卸载应用程序的情况下你会得到这个错误。但在我的例子中,应用程序没有被卸载。

我正在尝试从 php 发送推送通知。

我的 php 代码看起来像 -

include "../db_con.php";
// Replace with the real server API key from Google APIs
$apiKey = "xxx";

// Message to be sent
$message = "GET DEVICE INFO NOW";

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


if(isset($_REQUEST['imei_no']) && $_REQUEST['imei_no']!='')
{
$sql = "SELECT gcmId FROM device_tracker_device_master_tbl WHERE deviceId = ". $_REQUEST["imei_no"] ."";
$result = mysql_query($sql);

if (mysql_num_rows($result)>0)
{
while($row = mysql_fetch_assoc($result))
{
// Replace with the real client registration IDs
$registrationIDs = array( $row["gcmId"] );

$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'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);
//curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);
// print the result if you really need to print else neglate thi
echo $result;
//print_r($result);
//var_dump($result);
}
}
else
{
echo "Sorry no device found with this IMEI !!";
}
}

错误看起来像 -

enter image description here

最佳答案

感谢@e4c5,我找到了解决方案

在我的服务器中没有安装 CURL 我安装它使用

sudo apt-get install php5-curl

然后重述 apache2 现在一切正常。

sudo /etc/init.d/apache2 restart

关于php - 谷歌云消息错误 500(内部服务器错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32453214/

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