gpt4 book ai didi

php - GCM 丢弃消息

转载 作者:太空狗 更新时间:2023-10-29 14:25:40 26 4
gpt4 key购买 nike

我有一个 gcm 在这里工作的演示:http://leobee.com/android/push/login/gcm/updateusers.php

如果刷新页面,您将看到一个新的随机数。 4 次页面刷新中只有 1 次向 gcm 发送消息。这是正常现象还是我可以使用的代码需要一些时间?

页面没有被缓存。

代码:

<?php


require_once '../include/DB_Functions.php';


// get database access
$db = new DB_Functions();

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//api key
$apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$result;

//array for phones connected to this service
$registrationIDs = array();


$randomNum=rand(10,100);


echo "this is updateusers".$randomNum;
$_POST['message']="updateusers".$randomNum;
if (isset($_POST['message']) && $_POST['message'] != ''){

echo "<br>if (isset) updateusers".$randomNum;
// Message to be sent
$id= ''.mysql_real_escape_string(htmlentities($_POST['server_id'])).'';
$new_message= ''.mysql_real_escape_string(htmlentities($_POST['message'])).'';


// get client registration IDs
$query ="SELECT * FROM GoogleCloudMsg";

$queryresult=mysql_query($query);

while($row=mysql_fetch_assoc($queryresult)){
echo "<br>While loop updateusers".$randomNum;
$regId=$row['GCMPhoneRegisteredId'];

array_push($registrationIDs,$regId);

}



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

$fields;

if(!$id || $id==""){

$fields =
array(
'registration_ids' => $registrationIDs,
'data' => array("message" => $new_message),
'delay_while_idle'=> false,
'collapse_key'=>"".$randomNum.""
);

echo "<br> id is blank updateusers".$randomNum;

}else{

$fields =
array(
'registration_ids' => $registrationIDs,
'data' => array("message" =>$new_message,"server_id"=>$id),
'delay_while_idle' => 'false',
'collapse_key'=>"".$randomNum.""
);

echo "<br>id exists updateusers".$randomNum;

}
$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);
echo $result;

}

echo "<br>mysql close updateusers".$randomNum;
mysql_close();


?>

最佳答案

有两种方法可以解决这个问题。

  1. 生成并安装 CA 证书。

  2. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

不验证主机。

关于php - GCM 丢弃消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12877140/

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