1.下载presence.jar包
下载地址:http://www.igniterealtime.org/projects/openfire/plugins.jsp
2.把下载的presence.jar复制到部署的openfire目录下的plugins文件夹下,插件会自动部署运行
3.进入openfire的admin管理页面 在服务器设置下找到presence service 设置属性为anyone 确保插件允许任何人访问,并把下发方框里的unaviliable改为available让用户状态信息变得可访问
4,在openfire管理页面插件栏重启插件
5.判断openfire用户在线状态
传入的strUrl格式是最重要的一步,我就是在这卡了
strUrl=http://(1):9090/plugins/presence/status?jid="+(2)+"&type=xml";
(1)应该是你部署openfire服务器的地址
(2)应该是你openfire ofUser表中的用户名加上“@你设置的openfire的domain”
//0表示无此用户 1表示在线 2表示离线
public int short isonline(String strUrl)
{
int line = 0; //-不存在-
try
{
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if(oConn!=null)
{
BufferedReader reader= new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if(reader!=null)
{
String strFlag = reader.readLine();
reader.close();
if(strFlag.indexOf("type=\"unavailable\"")>=0)
{
lone= 2;
}
if(strFlag.indexOf("type=\"error\"")>=0)
{
line = 0;
}
else if(strFlag.indexOf("priority")>=0 || strFlag.indexOf("id=\"")>=0)
{
line = 1;
}
}
}
}
catch(Exception e)
{
}
return line;
}
{
int line = 0; //-不存在-
try
{
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if(oConn!=null)
{
BufferedReader reader= new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if(reader!=null)
{
String strFlag = reader.readLine();
reader.close();
if(strFlag.indexOf("type=\"unavailable\"")>=0)
{
lone= 2;
}
if(strFlag.indexOf("type=\"error\"")>=0)
{
line = 0;
}
else if(strFlag.indexOf("priority")>=0 || strFlag.indexOf("id=\"")>=0)
{
line = 1;
}
}
}
}
catch(Exception e)
{
}
return line;
}