xmpphp XMPP,从 php 脚本发送消息 [英] xmpphp XMPP, send message from php script

查看:70
本文介绍了xmpphp XMPP,从 php 脚本发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

我的 script.php 有以下内容:

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('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/ <-- 并运行在服务器命令行上,等待消息,然后回复.

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.

我该怎么办?

推荐答案

<?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()); 
} 
?>

这篇关于xmpphp XMPP,从 php 脚本发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆