我可以连接到服务器,但无法读取 gcm 服务器发送的确认消息。我想知道如何检索 gcm 服务器发送的 XML。这是我的代码:
<?php
require 'jaxl/jaxl.php';
$sender = 'sender id';
$client = new \JAXL(array(
 'jid'=>$sender,
 'pass'=>'pass',
 'auth_type'=>'PLAIN',
 'host' => 'gcm.googleapis.com',
 'port' => '5235',
 'force_tls' => true,
 'strict' => FALSE,
 'ssl' => TRUE,
 'log_level' => JAXL_DEBUG,
 'log_path'=> 'ex.txt'
  )); 
  $client->add_cb('on_message_stanza', function($msg) {
 echo 'now what!!';
 });
 $client->add_cb('on_auth_success', function() {
 echo 'it should';
 global $client;
 global $sender;
 $namespace = 'google:mobile:data';
 $arr=array("hello"=>"world");
 $json_data=json_encode($arr,JSON_UNESCAPED_SLASHES);
 $arr = array('to'=>'server','message_id'=>'123','data'=>$arr);
 $json = json_encode($arr);
 $xml = new JAXLXml('gcm',$namespace,array(),$json);
 $msg = new JAXLXml('message','',array('id'=>'123'),'');
 $msg->cnode($xml);
 $client->send($msg);
  }); 
 $client->add_cb('on_error_message',function()
 {
 global $client;
 echo 'error<br/>';
 _info('got on_error_message cb jid'.$client->full_jid->to_string());
 });
在回调“on_auth_success”中,我正在向 gcm 服务器发送一条指向我的服务器 ID 的消息,它正在发送一个否定的确认“nack”,我可以在日志中看到,但我不知道如何在 php 中接收它代码。gcm 根据日志收到的 XML 是:
 <message>
 <data:gcm xmlns:data="google:mobile:data">{"message_id":"123","from":"someid",
 "error_description":"","error":"BAD_REGISTRATION",
 "message_type":"nack"}</data:gcm></message>