2

サーバーに接続できますが、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」で、サーバーIDに向けられたgcmサーバーにメッセージを送信しています。ログに表示される否定応答「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>
4

2 に答える 2