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, '[email protected]',
    'passwd', 'xmpphp', 'gmail.com', $printlog = true,
    $loglevel = XMPPHP_Log::LEVEL_INFO);  

    try {
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence();
        $conn->message('[email protected]', '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*****
[INFO]: Connecting to tcp://talk.google.com:5222 1228****
[INFO]: Starting TLS encryption 1228****
[INFO]: Attempting Auth... 1228****
[INFO]: Auth success! 1228****
[INFO]: Bound to [email protected]/xmpphp*** 1228****
[INFO]: Session started ok
 » 转载保留版权: 叽叽歪歪 » 《Gtalk PHP API 简单例子(基于XMPP)》
 » 本文链接地址: http://www.jijiwaiwai.info/2011/07/25/gtalk_php_api_xmpp_example/
 » 如果喜欢可以: 点此订阅本站

你可能感兴趣的:(Gtalk PHP API 简单例子(基于XMPP))