xmpphp XMPP,从 php 脚本发送消息

发布于 2024-11-01 19:43:16 字数 1065 浏览 2 评论 0原文

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

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

我的 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.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/ <-- 在服务器命令行上运行,等待消息,然后回复。

我必须做什么?

Hi
I have a jabberserver and i would like to be able to push messages out to users from a php script.

F.x. if i call script.php from my browser, it sends a message to a user.
I've tried both with jaxl and xmpphp which are xmp frameworks, but i cant get it to work. Not with my own server, and neither with facebooks server.

I have the following ind my 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();    

But nothing happends and no errors either.
I've followed this guide to set up an echobot, and it works with both my server and facebook. The script is here: http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/ <-- and is run on the server commandline, and waiting for a message, and then replys.

What do i have to do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梓梦 2024-11-08 19:43:16
<?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 
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()); 
} 
?>
秋凉 2024-11-08 19:43:16
<?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>';
?>
<?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>';
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文