如何让它们在谷歌云消息服务器注册的设备列表 [英] how to get the list of devices which are registered in Google Cloud Messaging server

查看:437
本文介绍了如何让它们在谷歌云消息服务器注册的设备列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读取样本code为我的服务器后:

  //从谷歌API的真正的浏览器的API密钥替换
$ apiKey =123456;//与真正的客户端注册ID替换
$ registrationIDs =阵列(123,456);//要发送的消息
$消息=X;//设置POST变量
$ URL ='https://android.googleapis.com/gcm/send';$栏=阵列(
             registration_ids'=> $ registrationIDs,
             '数据'=>阵列(信息=> $消息)
              );$头=阵列(
                 授权:键='。 $ 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);

它需要知道从服务器registration_ids推信息

如何从我的个人服务器获得GCM服务器注册设备(registration_ids)的列表。

如何发送广播消息在GCM注册的所有设备。

感谢的!


解决方案

  

如何从我的个人服务器获得GCM服务器注册设备(registration_ids)名单


您没有。正如你提到的,你必须从设备的注册ID发送到您的服务器,通过某种方式或其他(如Web服务)。


  

如何发送广播消息在GCM注册的所有设备。


有是这样做的没有内置的手段,总之你可以通过注册ID发送消息给所有注册的设备的。

after reading the sample code for my server:

// Replace with real BROWSER API key from Google APIs
$apiKey = "123456";

// Replace with real client registration IDs 
$registrationIDs = array( "123", "456" );

// Message to be sent
$message = "x";

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

$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 ) );

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

// Close connection
curl_close($ch);

it is required to know the registration_ids from the server to push information.

how to get the list of registered devices (registration_ids) in GCM server from my personal server.

how to send a broadcast message to all devices registered in GCM.

Thank's !

解决方案

how to get the list of registered devices (registration_ids) in GCM server from my personal server

You don't. As you noted, you have to send the registration ID from the device to your server, by one means or another (e.g., Web service).

how to send a broadcast message to all devices registered in GCM

There is no built-in means of doing this, short of you sending a message to all of your registered devices by their registration IDs.

这篇关于如何让它们在谷歌云消息服务器注册的设备列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆