传送门: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:
解压。其中./XMPPHP为所需文件。其它为例子
<span style="color: #000000;"></span><span style="color: #000000;">php </span><span style="color: #0000ff;">require</span><span style="color: #000000;">(</span><span style="color: #000000;">'</span><span style="color: #000000;">XMPPHP/XMPP.php</span><span style="color: #000000;">'</span><span style="color: #000000;">); </span><span style="color: #800080;">$conn</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> XMPPHP_XMPP(</span><span style="color: #000000;">'</span><span style="color: #000000;">talk.google.com</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">5222</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">user@gmail.com</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">passwd</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">xmpphp</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">gmail.com</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #800080;">$printlog</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">true</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #800080;">$loglevel</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> XMPPHP_Log</span><span style="color: #000000;">::</span><span style="color: #000000;">LEVEL_INFO); </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { </span><span style="color: #800080;">$conn</span><span style="color: #000000;">-></span><span style="color: #000000;">connect(); </span><span style="color: #800080;">$conn</span><span style="color: #000000;">-></span><span style="color: #000000;">processUntil(</span><span style="color: #000000;">'</span><span style="color: #000000;">session_start</span><span style="color: #000000;">'</span><span style="color: #000000;">); </span><span style="color: #800080;">$conn</span><span style="color: #000000;">-></span><span style="color: #000000;">presence(); </span><span style="color: #800080;">$conn</span><span style="color: #000000;">-></span><span style="color: #000000;">message(</span><span style="color: #000000;">'</span><span style="color: #000000;">sb@gmail.com</span><span style="color: #000000;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">Hi! This is a test message for PHP API of Gtalk~</span><span style="color: #000000;">'</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">sb is short for somebody, to whom you want to send , // a joke!哈哈,就是SB</span> <span style="color: #000000;"> </span><span style="color: #800080;">$conn</span><span style="color: #000000;">-></span><span style="color: #000000;">disconnect(); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;">(XMPPHP_Exception </span><span style="color: #800080;">$e</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">die</span><span style="color: #000000;">(</span><span style="color: #800080;">$e</span><span style="color: #000000;">-></span><span style="color: #000000;">getMessage()); </span><span style="color: #008000;">//</span><span style="color: #008000;">异常</span> <span style="color: #000000;"> } </span><span style="color: #000000;">?> </span>
其中,*是用来对个人信息替换的。
<span style="color: #800080;">1228</span><span style="color: #000000;">***** [INFO]: Connecting to </span><span style="color: #008080;">tcp:</span><span style="color: #000000;">//talk.google.</span><span style="color: #008080;">com:</span><span style="color: #800080;">5222</span><span style="color: #000000;"> </span><span style="color: #800080;">1228</span><span style="color: #000000;">**** [INFO]: Starting TLS encryption </span><span style="color: #800080;">1228</span><span style="color: #000000;">**** [INFO]: Attempting Auth... </span><span style="color: #800080;">1228</span><span style="color: #000000;">**** [INFO]: Auth success! </span><span style="color: #800080;">1228</span><span style="color: #000000;">**** [INFO]: </span><span style="color: #0000ff;">Bound</span><span style="color: #000000;"> to user@gmail.com/xmpphp*** </span><span style="color: #800080;">1228</span><span style="color: #000000;">**** [INFO]: Session started ok</span>
» 转载保留版权:叽叽歪歪 » 《Gtalk PHP API 简单例子(基于XMPP)》» 本文链接地址:http://www.jijiwaiwai.info/2011/07/25/gtalk_php_api_xmpp_example/» 如果喜欢可以:点此订阅本站