xmpphp XMPP, 从php脚本中发送消息。

问题描述 投票:2回答:2

嗨,我有一个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('[email protected]', 'This is a test message!');  
$conn->disconnect();    

但是什么都没有发生,也没有错误. 我按照这个指南设置了一个echobot, 它可以在我的服务器和facebook上工作. 脚本在这里。http:/abhinavsingh.comlog201002写你的第一个facebook聊天机器人-php-using-jaxl-library。 <--并在服务器命令行上运行,等待消息,然后回复。

我应该怎么做?

php real-time xmpp xmpphp
2个回答
1
投票
<?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()); 
} 
?>

0
投票
<?php

$command = 'send_message';
$requestParams = array('type' => 'chat',
    'to' => '[email protected]',
    'from' => '[email protected]',
    '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>';
?>
© www.soinside.com 2019 - 2024. All rights reserved.