繁体   English   中英

xmpphp XMPP,从 php 脚本发送消息

[英]xmpphp XMPP, send message from php script

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

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

我有以下 ind 我的 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_xmlrpc\r\n" .
        "Content-Type: text/xml\r\n" .
        "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>';
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM