帝王 发表于 2015-8-27 08:19:28

Gtalk PHP API 简单例子(基于XMPP)

1.下载库文件
  传送门:http://code.google.com/p/xmpphp/
或者使用svn co出来: svn://netflint.net/xmpphp
  简单说明:
XMPPHP is the successor to Class.Jabber.PHP that I've been promising
for years. Taking advantage of PHP5, I believe it to be an elegant
solution with a direct approach.
Some of the features include:


[*]Connect to any XMPP 1.0 server (Google Talk, LJ Talk, jabber.org, etc)
[*]Supports TLS encryption
[*]Several XML processing approaches and supported styles (process
indefinitely, processUntil an event, processTime for a number of
seconds), waiting on events or map them, etc.

2.使用方法
  解压。其中./XMPPHP为所需文件。其它为例子

3.示例代码



<?php
require('XMPPHP/XMPP.php');
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'user@gmail.com',
'passwd', 'xmpphp', 'gmail.com', $printlog = true,
$loglevel = XMPPHP_Log::LEVEL_INFO);
try {
$conn->connect();
$conn->processUntil('session_start');
$conn->presence();
$conn->message('sb@gmail.com', 'Hi! This is a
test message for PHP API of Gtalk~');
//sb is short for somebody, to whom you want to send,
// a joke!哈哈,就是SB
      $conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());//异常
    }
?>

4.返回消息
  其中,*是用来对个人信息替换的。



1228*****
: Connecting to tcp://talk.google.com:5222 1228****
: Starting TLS encryption 1228****
: Attempting Auth... 1228****
: Auth success! 1228****
: Bound to user@gmail.com/xmpphp*** 1228****
: Session started ok


 &raquo; 转载保留版权:叽叽歪歪 &raquo; 《Gtalk PHP API 简单例子(基于XMPP)》

 &raquo; 本文链接地址:http://www.jijiwaiwai.info/2011/07/25/gtalk_php_api_xmpp_example/

 &raquo; 如果喜欢可以:点此订阅本站
页: [1]
查看完整版本: Gtalk PHP API 简单例子(基于XMPP)