利用strophe.js +nginx 在openfire服务器注册用户
2015-02-06 10:25
253 查看
strophe是xmpp协议的javascript脚本解释库。
nginx用来解决跨域的问题。
要实现在openfire注册其实很简单,如果通过走后台实现(smack),只需要在前端利用ajax调用,如果使用smack,需要引入的jar包:
smack-bosh-4.0.4.jar
smack-core-4.0.4.jar
smack-core-dns-4.0.4.jar
smack-debug-4.0.4.jar
smack-experimental-4.0.4.jar
smack-extensions-4.0.4.jar
smack-jingle-4.0.4.jar
smack-legacy-4.0.4.jar
smack-resolver-dnsjava-4.0.4.jar
smack-resolver-javax-4.0.4.jar
smack-tcp-4.0.4.jar
kxml2.jar
注册方法实现:
但是如果需要实现前端strophe来注册,需要处理xmpp的一系列流验证,网上资料很少,最后在国外的论坛上找到一个strophe注册插件,其中有一个错误,修改之后可以用:
已经修改的注册插件下载地址附上:http://download.csdn.net/detail/huling2361/8428015
nginx用来解决跨域的问题。
要实现在openfire注册其实很简单,如果通过走后台实现(smack),只需要在前端利用ajax调用,如果使用smack,需要引入的jar包:
smack-bosh-4.0.4.jar
smack-core-4.0.4.jar
smack-core-dns-4.0.4.jar
smack-debug-4.0.4.jar
smack-experimental-4.0.4.jar
smack-extensions-4.0.4.jar
smack-jingle-4.0.4.jar
smack-legacy-4.0.4.jar
smack-resolver-dnsjava-4.0.4.jar
smack-resolver-javax-4.0.4.jar
smack-tcp-4.0.4.jar
kxml2.jar
注册方法实现:
public int register(String username,String password,String email){ xmppConnection = getConnection(); //可以直接改登陆用户的信息(如果是username的值必须和该用户的用户名相同) Registration r = new Registration(); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("username", username); attributes.put("password", password); attributes.put("email", email); // attributes.put("name", "name@192.168.1.100"); //添加用户,要设置type类型为set r.setType(IQ.Type.SET); r.setAttributes(attributes); //过滤器,用来过滤由服务器返回的信息(即得到注册信息的内容) PacketFilter packetFilter = new AndFilter(new PacketIDFilter(r.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = xmppConnection.createPacketCollector(packetFilter); System.out.println(r); try { xmppConnection.sendPacket(r); IQ result = (IQ) collector.nextResult(); if(result == null) { System.out.println("服务器没有返回任何信息"); disconnect(); return 0; } else if(result.getType().toString().equals("result")){ System.out.println("注册成功"); disconnect(); return 1; }else if(result.getType().toString().equals("error")){ if(result.getError().toString().equalsIgnoreCase("conflict")){ System.out.println("用户名称已存在"); disconnect(); return 2; } else { disconnect(); System.out.println("注册失败"); return 3; } }else{ disconnect(); return 4; } } catch (NotConnectedException e) { e.printStackTrace(); disconnect(); return 5; } }
但是如果需要实现前端strophe来注册,需要处理xmpp的一系列流验证,网上资料很少,最后在国外的论坛上找到一个strophe注册插件,其中有一个错误,修改之后可以用:
已经修改的注册插件下载地址附上:http://download.csdn.net/detail/huling2361/8428015
相关文章推荐
- php用户注册页面利用js进行表单验证
- Strophe.js连接XMPP服务器Openfire、Tigase实现Web私聊、群聊(MUC)
- php用户注册页面利用js进行表单验证具体实例
- Strophe.js连接XMPP服务器Openfire、Tigase实现Web私聊、群聊(MUC)
- Strophe.js连接XMPP服务器Openfire、Tigase实现Web私聊、群聊(MUC)
- 用户注册__浏览器+服务器__HTML+CSS+JS+JAVA
- Strophe.js连接XMPP服务器Openfire、Tigase实现Web私聊、群聊(MUC)
- php用户注册页面利用js进行表单验证具体实例
- Strophe.js连接XMPP服务器Openfire、Tigase实现Web私聊、群聊(MUC)
- php用户注册页面利用js进行表单验证
- 利用js实现用户注册检验 改进版(nm360浏览器不兼容)
- 利用对方服务器漏洞远程注册DLL
- 利用储存导入链接服务器的所有用户表(原作)
- ASP.net注册客户端JS脚本,利用两次提交解决下载后画面不能刷新的问题
- 在ASP.NET 中实现单用户登录(利用Cache, 将用户信息保存在服务器缓存中)[转]
- 利用nginx解决js跨域调用问题
- 利用SQL server 2005的复制功能分散用户访问服务器的负载