I can connect to the server but cannot read the acknowledgements messages sent by the gcm server. I want to know how to retrieve the XML sent by gcm server. Here is my code :
<?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());
});
In the callback 'on_auth_success', i am sending a message to gcm server directed to my server id, it is sending a negative acknowledgement 'nack' which i can see in the log, but I don't know how to receive that in php code. The XML received by gcm as per log is :
<message>
<data:gcm xmlns:data="google:mobile:data">{"message_id":"123","from":"someid",
"error_description":"","error":"BAD_REGISTRATION",
"message_type":"nack"}</data:gcm></message>
Oh, I got it, since the response message didn't had any type, I have to add the callback 'on__message', with 2 underscore, because middle value is the value of type attribute of the message which the response don't have.