谷歌云消息传递的注册ID到期消息、谷歌云、ID

2023-09-06 02:57:08 作者:动我女人者,全撂倒

我使用谷歌云消息传递我的Andr​​oid应用程序,我试图在注册ID到期理解。从这个的文章中,我能够理解,谷歌倾向于刷新ID在一段时间。我很好奇,我的申请将如何知道什么时候该ID被刷新?如果谷歌决定将刷新ID和我的服务器,直到将消息发送到老ID我不认为该消息将被发送。所以,我会要尝试并注册每一次,看看ID是一样的吗?

另外,根据相同的后说的ID会得到刷新时,应用程序的版本的变化,但在通过清单中的注册ID改变版本没有改变。那么,什么是对努力的版本再次更改注册点?

修改  这里是服务器端。确切位置在哪里将规范ID存储?

服务器端code:

 < PHP
//消息要发送
$消息= $ _ POST ['消息'];

//设置POST变量
$ URL ='https://android.googleapis.com/gcm/send';

$领域=阵列(
registration_ids'=>数组($ _ POST ['registrationIDs']),
'数据'=>阵列(信息=> $消息)
);

$标题=阵列(
授权:键='。 $ _ POST ['apiKey'],
内容类型:应用程序/ JSON
);

//打开连接
$ CH = curl_init();

//设置URL,POST数瓦尔,POST数据
curl_setopt($ CH,CURLOPT_URL,$网址);

curl_setopt($ CH,CURLOPT_POST,真正的);
curl_setopt($ CH,CURLOPT_HTTPHEADER,$头);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);

curl_setopt($ CH,CURLOPT_POSTFIELDS,json_en code($域));

//执行后
$结果= curl_exec($ CH);

//关闭连接
curl_close($ CH);

回声$结果;

?>
 

解决方案   

我想,当注册ID到期理解

GCM服务器通常刷新(所以你的旧注册ID已过期)注册的ID。如果正好出现这种情况是不记录任何地方。但是,您将会收到通知时,发生这种情况。

我们怎么通知?

  谷歌云加入EOS公链网络竞选EOS节点

当你发送通知,该通知已过期的注册ID,   为第一时间的消息(通知)将交付,但你   将获得的新注册ID名称为规范的ID 。 这意味着,   您发送该消息的注册ID已被更改为这个   规范的ID,所以改变它在你的服务器端,以及

  

如果谷歌决定将刷新ID和我的服务器,直到发送   消息到老ID我不认为该消息将被发送

就像我说的,这将被发送的第一时间,即使到期后。

  

另外,同样的帖子里说的ID会得到刷新时,应用程序   版本更改

我不认为这种情况是肯定的。但是,即使它发生(注册ID的变化)的相同的情况下,如上所述,因此,所有你需要的是照顾在规范的id

修改

  $结果= curl_exec($ CH);
$结果= json_de code($结果);
$ canonical_ids_count = $ result-> canonical_ids;
如果($ canonical_ids_count){
    //通过更换注册ID更新数据库
    //规范ID(新注册ID)
}
 

I am using Google Cloud Messaging for my Android application and I am trying to understand when the registration id expires. From this post I was able to understand that Google tends to refresh the ID at some time. I am curious how my application will know when the id gets refreshed? If Google decides to refresh the ID and my server is till sending the message to the old ID I dont think the message will get sent. So would I have to try and register every time and see if the ids are same?

Also the same post says that the id would get refreshed when the app version changes, but on changing the version through the manifest the registration id did not change. So what is the point on trying to register again of the version changes?

EDIT Here is the server side. Where exactly would the canonical id be stored?

Server side code:

<?php
// Message to be sent
$message = $_POST['message'];
 
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
 
$fields = array(
                'registration_ids'  => array($_POST['registrationIDs']),
                'data'              => array( "message" => $message ),
                );
 
$headers = array( 
                    'Authorization: key=' . $_POST['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 ) );
 
// Execute post
$result = curl_exec($ch);
 
// Close connection
curl_close($ch);
 
echo $result;
 
?>

解决方案

I am trying to understand when the registration id expires

GCM server usually refreshes(So your old registration id is expired) the registration ids. When exactly this happens is not documented anywhere. But you will be notified when this happens.

How are we notified?

When you send a notification to a registration id which is expired, for the 1st time the message(notification) will be delivered but you will get a new registration id with the name canonical id. Which mean, the registration id you sent the message to has been changed to this canonical id, so change it on your server side as well.

If Google decides to refresh the ID and my server is till sending the message to the old ID I dont think the message will get sent

Like I said, it will be sent for the 1st time, even after expiry.

Also the same post says that the id would get refreshed when the app version changes

I don't think this happens for sure. But even if it happens(registration id changes) its the same scenario as explained above, so all you need is to take care of the canonical id.

EDIT

$result = curl_exec($ch);
$result = json_decode($result);
$canonical_ids_count = $result->canonical_ids;
if($canonical_ids_count){
    //update your DB by replacing the registration id with 
    //the canonical id(new registration id)
}