Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我应该如何在服务器端实现GCM推送过程?_Php_Android_Google Cloud Messaging_Throttling - Fatal编程技术网

Php 我应该如何在服务器端实现GCM推送过程?

Php 我应该如何在服务器端实现GCM推送过程?,php,android,google-cloud-messaging,throttling,Php,Android,Google Cloud Messaging,Throttling,我目前正在为android开发GCM,并使用PHP实现服务器代码。现在,我的代码如下所示: $url = 'https://android.googleapis.com/gcm/send'; $registrationIDs = array('device1', 'device2');//device ids from database. $fields = array( 'registration_ids' => $registrationIDs,

我目前正在为android开发GCM,并使用PHP实现服务器代码。现在,我的代码如下所示:

$url = 'https://android.googleapis.com/gcm/send';
$registrationIDs = array('device1', 'device2');//device ids from database.

$fields = array(
                'registration_ids'  => $registrationIDs,
                'data'              => array( "message" => $message ),
                );

$headers = array( 
                    'Authorization: key=' . $apiKey,
                    'Content-Type: application/json'
                );

// Open connection
$ch = curl_init();

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

// Close connection
curl_close($ch);
当我执行时,结果如下:

{
  "multicast_id": 5407120473654582795,
  "success": 1,
  "failure": 1,
  "canonical_ids": 1,
  "results": [
    {
      "registration_id": "skjdfhksdfgksudghldshfgkdjfghdiugf",
      "message_id": "0:1354101888763222%14c0e050f9fd7ecd"
    },
    {
      "error": "MismatchSenderId"
    }
  ]
}
GCM页面上有注释:

  • 如果消息已创建,但结果返回了规范注册ID,则有必要将当前注册ID替换为规范注册ID
  • 如果返回的错误未注册,则有必要删除该注册ID,因为应用程序已从设备上卸载
我的问题是:

  • 根据服务器输出,我有1个规范结果。但是,我不确定它属于哪个设备如何确定它?
  • 根据问题(1),我的想法是,我可能能够一次发送一个设备到GCM。但是,这提出了另一个问题如果我有数百万台设备,可以吗?

  • 基于此页面上的信息

    它是数组中第一个需要将其regid替换为“skjdfhksdfgkssudghldshfgkdjfghdiugf”的元素。数组中的第二个元素是彻底失败

    数以百万计的设备不最多1000对

    在同一页上


    注册\u id包含接收消息的设备(注册id)列表的字符串数组。它必须至少包含1个注册ID,并且最多包含1000个注册ID。

    您可以在以下网站上阅读有关规范ID的更多信息:

    如果以后您尝试使用其他注册发送消息 ID,GCM将一如既往地处理请求,但它将包括 的注册ID字段中的规范注册ID 答复。请确保替换存储在计算机中的注册ID 具有此规范ID的服务器,最终您使用的ID将 停止工作

    您也可以在本节中阅读更多内容

    如果要发送到数百万台设备,则必须使用JSON以1000个注册ID为单位发送消息。Google docs提供了以下发送到六台设备的示例:

    { "data": {
        "score": "5x1",
        "time": "15:10"
      },
      "registration_ids": ["4", "8", "15", "16", "23", "42"]
    }