2011-04-15 152 views
2

嗨 我有一個jabberserver,我希望能夠將消息從php腳本推送給用戶。xmpphp XMPP,從php腳本發送消息

F.x.如果我從瀏覽器調用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('[email protected]', 'This is a test message!'); 
$conn->disconnect();  

但沒有happends,要麼沒有錯誤。 我按照本指南設置了一個echobot,它可以與我的服務器和facebook一起工作。腳本在這裏:http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/ < - 並在服務器命令行上運行,並等待消息,然後回覆。

我該怎麼辦?

+0

如果你的腳本運行在什麼服務器上? windows/unix?檢查郵件是否正常工作。 – Stewie 2011-04-15 18:52:34

+0

我100%確定郵件正確。 – Danielss89 2011-04-15 19:35:03

+0

我的意思是郵件deamon(SMTP服務器) – Stewie 2011-04-15 19:43:43

回答

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 = '[email protected]' // ex [email protected] 
$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('[email protected]', 'Hello!'); 
     $conn->disconnect(); 
} catch(XMPPHP_Exception $e) { 
     die($e->getMessage()); 
} 
?>