我正在尝试使用php
推送使用XMPP协议的通知。我正在尝试的代码是:
<?php
include 'XMPPHP/XMPP.php';
set_time_limit(0);
echo 'Current PHP version: ' . phpversion();
$conn = new XMPPHP_XMPP('fcm-xmpp.googleapis.com',5235, 'senderid@gcm.googleapis.com', 'serverapikey','xmpphp','gcm.googleapis.com','true', 'info');
echo 'before try';
try {
$conn->connect();
echo 'after connect';
$conn->presence($status='Controller available.');
//$conn->processUntil(array('session_start', 'roster_received'));
//echo 'payload is '.$payload;
//$conn->presence($status='Controller available.');
$msg =" <message id=\"\">
<gcm xmlns=\"google:mobile:data\">
\"to\" : \"regId\",
\"message_id\":\"m-1366082849205\"
\"data\":
{
\"hello\":\"world\"
},
\"time_to_live\":\"600\"
}
</gcm>
</message>";
$conn->message('senderid@gcm.googleapis.com', $msg);
$conn->disconnect();
} catch(Exception $e) {
die($e->getMessage());
}
?>
我可以通过http
连接并发送通知。但我希望使用xampp
协议来做到这一点。请让我知道如何实现它。