嗨,我有一个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.comlog201002写你的第一个facebook聊天机器人-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());
}
?>