dongqian1893 2013-12-27 21:54
浏览 17
已采纳

GCM响应不正确,缺少},{

I am sending a GCM push message (less then 1000) with:

$Regids = mysql_query("SELECT regid FROM $tabel WHERE active = '1'");
$result_array = array();
while ($row = mysql_fetch_array($Regids)){
    $result_array[] = $row['regid'];
}

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

 $data = array(
    'registration_ids' => $result_array,
    'data' => array(
        'type' => 'New',
        'title' => 'LH',
        'msg' => ''.$msj.''
    )
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
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($data));

$result = curl_exec($ch);

curl_close($ch);

When I print the $result to check (and use for updating the database) it shows:

{"multicast_id":000,"success":274,"failure":75,"canonical_ids":13,"results":[{"message_id":"123"},{"message_id":"123"},{"error":"NotRegistered"},{"error":"NotRegistered"},{"message_id":"123"},{"message_id":"123"},{"registration_id":"456","message_id":"123"}]}

There is no },{ between every (canonical) registration_id and the next (success) message_id or error. (I shortened the response to make it readable)

So my update part fails

$result = json_decode($result);
for ($i = 0; $i < count($result->{'results'}); $i++) { 
    if ($result->{'results'}[$i]->{'message_id'}) {
        ...
    } elseif($result->{'results'}[$i]->{'error'}) {
        ...
    } elseif ($result->{'results'}[$i]->{'registration_id'}) {
        ...
    }
}

Does someone know what's wrong?

  • 写回答

1条回答 默认 最新

  • drgm51600 2013-12-27 22:32
    关注

    The format of the response you got is correct . A message for which you get a canonical registration id is still accepted by Google and is therefore successful , and that's why you get a message id in addition to the canonical registration id for that message . That's why there are no brackets after the canonical registration id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line