实时-xmpphpXMPP,从php脚本发送消息



嗨我有一个jabberserver,我希望能够从php脚本向用户推送消息。

F.x.如果我从浏览器调用script.php,它会向用户发送一条消息。我已经尝试了jaxl和xmpphp这两种xmp框架,但我无法使其工作。不是用我自己的服务器,也不是用facebooks服务器。

我在我的script.php中有以下内容:

error_reporting(E_ALL);    
include("lib/xmpphp/XMPPHP.php");  
$conn = new XMPP('chat.facebook.dk', 5222, 'username', 'password', '', 'chat.facebook.com', true, XMPPHP_Log::LEVEL_VERBOSE);  
$conn->connect();  
$conn->processUntil('session_start');  
$conn->message('someusername@chat.facebook.com', 'This is a test message!');  
$conn->disconnect();    

但什么也没发生,也没出错。我按照这个指南设置了一个echobot,它可以与我的服务器和facebook一起使用。脚本在这里:http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/<--并在服务器命令行上运行,等待消息,然后回复。

我该怎么办?

<?php 
set_time_limit(0);  // some time connection take while  
require_once 'xmpp-lib/XMPPHP/XMPP.php';  
$host = 'you Host name'; // ex.192.168.2.1  
$port = '5222'; // its defauls xmpp port 
$username = 'name@host' // ex vivek@host 
$pass = 'userpass';  
$conn = new XMPPHP_XMPP(host , $port, $username, $pass, 'xmpphp','yourhost', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);  
try {
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message('anotherusername@host', 'Hello!');
         $conn->disconnect(); 
} catch(XMPPHP_Exception $e) {
         die($e->getMessage()); 
} 
?>
<?php
$command = 'send_message';
$requestParams = array('type' => 'chat',
    'to' => '919999999999@127.0.0.0',
    'from' => '919999999991@127.0.0.0',
    'body' => 'Hi vivek patel',
    'subject' => 'test',
);
$request = xmlrpc_encode_request($command, $requestParams, (array('encoding' => 'utf-8')));
$context = stream_context_create(array('http' => array('method' => "POST",
        'header' => "User-Agent: XMLRPC::Client mod_xmlrpcrn" .
        "Content-Type: text/xmlrn" .
        "Content-Length: " . strlen($request),
        'content' => $request
    )
        )
);
try {
    $file = file_get_contents("http://127.0.0.0:4560/RPC2", false, $context);
    $response = xmlrpc_decode($file);
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}
if (xmlrpc_is_fault($response)) {
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
}
echo '<pre>';
echo print_r($response);
echo '</pre>';
?>

最新更新