您好 我有一个jabberserver,我希望能够从PHP脚本向用户推送消息。
F.X。如果我从浏览器调用script.php,它会向用户发送一条消息。 我已尝试使用jaxl和xmpphp这些都是xmp框架,但我无法让它工作。不是我自己的服务器,也不是facebooks服务器。
我的脚本中有以下内容.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/< - 并在服务器命令行上运行,等待消息,然后回复。
我该怎么做?
答案 0 :(得分: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());
}
?>
答案 1 :(得分:0)
<?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>';
?>