首页 > 其他 > 详细

判断openfire用户的状态

时间:2016-09-30 12:06:31      阅读:809      评论:0      收藏:0      [点我收藏+]

/**
* 判断openfire用户的状态
* 说明 :必须要 openfire加载 presence 插件,同时设置任何人都可以访问
* /status?jid=user1@my.openfire.com&type=xml 返回值 : 0 - 用户不存在; 1 - 用户在线; 2 -用户离线
* 示例:http://192.168.1.254:9090/plugins/presence/status?jid=13817764475@192.168.1.254&type=xml

* @后面的参数是服务器名称,我测试时服务器名称写为了192.168.1.254

*/
public static short IsUserOnLine(String strUrl) {
strUrl = "http://192.168.1.254:9090/plugins/presence/status?jid=13817764475@192.168.1.254&type=xml";
short shOnLineState = 0; // -不存在-
try {
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if (oConn != null) {
BufferedReader oIn = new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if (null != oIn) {
String strFlag = oIn.readLine();
oIn.close();

if (strFlag.indexOf("type=\"unavailable\"") >= 0) {
shOnLineState = 2;
}
if (strFlag.indexOf("type=\"error\"") >= 0) {
shOnLineState = 0;
} else if (strFlag.indexOf("priority") >= 0 || strFlag.indexOf("id=\"") >= 0) {
shOnLineState = 1;
}
}
}
} catch (Exception e) {

}
return shOnLineState;
}

判断openfire用户的状态

原文:http://www.cnblogs.com/shihaiming/p/5923022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!