mirror of
https://gitee.com/xchao/j-im.git
synced 2024-12-02 11:57:43 +08:00
删除测试模块
This commit is contained in:
parent
90f5701954
commit
34c9e52cf4
6
jim-site/.gitignore
vendored
6
jim-site/.gitignore
vendored
@ -1,6 +0,0 @@
|
||||
.settings/
|
||||
/target/
|
||||
.idea/
|
||||
*.iml
|
||||
*.classpath
|
||||
*.project
|
@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.j-im</groupId>
|
||||
<artifactId>jim-site</artifactId>
|
||||
<version>1.0.0.v20200410-RELEASE</version>
|
||||
<properties>
|
||||
<jim.version>3.0.0.v20200101-RELEASE</jim.version>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.j-im</groupId>
|
||||
<artifactId>jim-server</artifactId>
|
||||
<version>${jim.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,73 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.jim.site;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jim.common.config.ImConfig;
|
||||
import org.jim.common.packets.Command;
|
||||
import org.jim.common.utils.PropUtil;
|
||||
import org.jim.server.ImServerStarter;
|
||||
import org.jim.server.command.CommandManager;
|
||||
import org.jim.server.command.handler.ChatReqHandler;
|
||||
import org.jim.server.command.handler.HandshakeReqHandler;
|
||||
import org.jim.server.command.handler.LoginReqHandler;
|
||||
import org.jim.server.command.handler.processor.chat.DefaultAsyncChatMessageProcessor;
|
||||
import org.jim.server.config.ImServerConfig;
|
||||
import org.jim.server.config.PropertyImServerConfigBuilder;
|
||||
import org.jim.site.command.DemoWsHandshakeProcessor;
|
||||
import org.jim.site.service.LoginServiceProcessor;
|
||||
import org.jim.site.listener.ImDemoGroupListener;
|
||||
import org.tio.core.ssl.SslConfig;
|
||||
/**
|
||||
* IM服务端DEMO演示启动类;
|
||||
* @author WChao
|
||||
* @date 2018-04-05 23:50:25
|
||||
*/
|
||||
public class ImSiteServerStart {
|
||||
|
||||
public static void main(String[] args)throws Exception{
|
||||
ImServerConfig imServerConfig = new PropertyImServerConfigBuilder("jim.properties").build();
|
||||
//初始化SSL;(开启SSL之前,你要保证你有SSL证书哦...)
|
||||
initSsl(imServerConfig);
|
||||
//设置群组监听器,非必须,根据需要自己选择性实现;
|
||||
imServerConfig.setImGroupListener(new ImDemoGroupListener());
|
||||
ImServerStarter imServerStarter = new ImServerStarter(imServerConfig);
|
||||
|
||||
/*****************start 以下处理器根据业务需要自行添加与扩展,每个Command都可以添加扩展,此处为demo中处理**********************************/
|
||||
|
||||
HandshakeReqHandler handshakeReqHandler = CommandManager.getCommand(Command.COMMAND_HANDSHAKE_REQ, HandshakeReqHandler.class);
|
||||
//添加自定义握手处理器;
|
||||
handshakeReqHandler.addMultiProtocolProcessor(new DemoWsHandshakeProcessor());
|
||||
LoginReqHandler loginReqHandler = CommandManager.getCommand(Command.COMMAND_LOGIN_REQ,LoginReqHandler.class);
|
||||
//添加登录业务处理器;
|
||||
loginReqHandler.setSingleProcessor(new LoginServiceProcessor());
|
||||
//添加用户业务聊天记录处理器,用户自己继承抽象类BaseAsyncChatMessageProcessor即可,以下为内置默认的处理器!
|
||||
ChatReqHandler chatReqHandler = CommandManager.getCommand(Command.COMMAND_CHAT_REQ, ChatReqHandler.class);
|
||||
chatReqHandler.setSingleProcessor(new DefaultAsyncChatMessageProcessor());
|
||||
|
||||
/*****************end *******************************************************************************************/
|
||||
|
||||
imServerStarter.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启SSL之前,你要保证你有SSL证书哦!
|
||||
* @param imServerConfig
|
||||
* @throws Exception
|
||||
*/
|
||||
private static void initSsl(ImServerConfig imServerConfig) throws Exception {
|
||||
//开启SSL
|
||||
if(ImConfig.ON.equals(imServerConfig.getIsSSL())){
|
||||
String keyStorePath = PropUtil.get("jim.key.store.path");
|
||||
String keyStoreFile = keyStorePath;
|
||||
String trustStoreFile = keyStorePath;
|
||||
String keyStorePwd = PropUtil.get("jim.key.store.pwd");
|
||||
if (StringUtils.isNotBlank(keyStoreFile) && StringUtils.isNotBlank(trustStoreFile)) {
|
||||
SslConfig sslConfig = SslConfig.forServer(keyStoreFile, trustStoreFile, keyStorePwd);
|
||||
imServerConfig.setSslConfig(sslConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.jim.site.command;
|
||||
|
||||
import org.jim.common.ImChannelContext;
|
||||
import org.jim.common.ImConst;
|
||||
import org.jim.common.Jim;
|
||||
import org.jim.common.ImPacket;
|
||||
import org.jim.common.exception.ImException;
|
||||
import org.jim.common.http.HttpRequest;
|
||||
import org.jim.common.packets.Command;
|
||||
import org.jim.common.packets.LoginReqBody;
|
||||
import org.jim.common.utils.JsonKit;
|
||||
import org.jim.server.command.CommandManager;
|
||||
import org.jim.server.command.handler.LoginReqHandler;
|
||||
import org.jim.server.command.handler.processor.handshake.WsHandshakeProcessor;
|
||||
/**
|
||||
* @author WChao
|
||||
*
|
||||
*/
|
||||
public class DemoWsHandshakeProcessor extends WsHandshakeProcessor {
|
||||
|
||||
@Override
|
||||
public void onAfterHandshake(ImPacket packet, ImChannelContext imChannelContext) throws ImException {
|
||||
LoginReqHandler loginHandler = (LoginReqHandler)CommandManager.getCommand(Command.COMMAND_LOGIN_REQ);
|
||||
HttpRequest request = (HttpRequest)packet;
|
||||
String username = request.getParams().get("username") == null ? null : (String)request.getParams().get("username")[0];
|
||||
String password = request.getParams().get("password") == null ? null : (String)request.getParams().get("password")[0];
|
||||
String token = request.getParams().get("token") == null ? null : (String)request.getParams().get("token")[0];
|
||||
LoginReqBody loginBody = new LoginReqBody(username,password,token);
|
||||
byte[] loginBytes = JsonKit.toJsonBytes(loginBody);
|
||||
request.setBody(loginBytes);
|
||||
try{
|
||||
request.setBodyString(new String(loginBytes, ImConst.CHARSET));
|
||||
}catch (Exception e){
|
||||
throw new ImException(e);
|
||||
}
|
||||
ImPacket loginRespPacket = loginHandler.handler(request, imChannelContext);
|
||||
if(loginRespPacket != null){
|
||||
Jim.send(imChannelContext, loginRespPacket);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package org.jim.site.listener;
|
||||
|
||||
import org.jim.common.*;
|
||||
import org.jim.common.exception.ImException;
|
||||
import org.jim.common.listener.ImGroupListener;
|
||||
import org.jim.common.packets.*;
|
||||
import org.jim.common.utils.JsonKit;
|
||||
import org.jim.server.handler.ProtocolManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tio.core.ChannelContext;
|
||||
|
||||
/**
|
||||
* @author WChao
|
||||
* 2017年5月13日 下午10:38:36
|
||||
*/
|
||||
public class ImDemoGroupListener implements ImGroupListener {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ImGroupListener.class);
|
||||
|
||||
@Override
|
||||
public void onAfterBind(ImChannelContext imChannelContext, Group group) throws ImException {
|
||||
logger.info("群组:{},绑定成功!", JsonKit.toJSONString(group));
|
||||
JoinGroupRespBody joinGroupRespBody = JoinGroupRespBody.success();
|
||||
//回一条消息,告诉对方进群结果
|
||||
joinGroupRespBody.setGroup(group.getGroupId());
|
||||
ImPacket respPacket = ProtocolManager.Converter.respPacket(joinGroupRespBody, imChannelContext);
|
||||
//Jim.send(imChannelContext, respPacket);
|
||||
//发送进房间通知;
|
||||
joinGroupNotify(group, imChannelContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterBind(ImChannelContext imChannelContext, String groupId) throws ImException {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channelContext
|
||||
* @param group
|
||||
* @throws Exception
|
||||
* @author: WChao
|
||||
*/
|
||||
@Override
|
||||
public void onAfterUnbind(ImChannelContext channelContext, Group group) throws ImException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterUnbind(ImChannelContext imChannelContext, String groupId) throws ImException {
|
||||
//发退出房间通知 COMMAND_EXIT_GROUP_NOTIFY_RESP
|
||||
ExitGroupNotifyRespBody exitGroupNotifyRespBody = new ExitGroupNotifyRespBody();
|
||||
exitGroupNotifyRespBody.setGroup(groupId);
|
||||
User clientUser = imChannelContext.getSessionContext().getClient().getUser();
|
||||
if(clientUser == null) {
|
||||
return;
|
||||
}
|
||||
User notifyUser = new User(clientUser.getUserId(),clientUser.getNick());
|
||||
exitGroupNotifyRespBody.setUser(notifyUser);
|
||||
|
||||
RespBody respBody = new RespBody(Command.COMMAND_EXIT_GROUP_NOTIFY_RESP,exitGroupNotifyRespBody);
|
||||
ImPacket imPacket = new ImPacket(Command.COMMAND_EXIT_GROUP_NOTIFY_RESP, respBody.toByte());
|
||||
Jim.sendToGroup(groupId, ProtocolManager.Converter.respPacket(imPacket, imChannelContext));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送进房间通知;
|
||||
* @param group 群组对象
|
||||
* @param imChannelContext
|
||||
*/
|
||||
public void joinGroupNotify(Group group, ImChannelContext imChannelContext)throws ImException{
|
||||
ImSessionContext imSessionContext = imChannelContext.getSessionContext();
|
||||
User clientUser = imSessionContext.getClient().getUser();
|
||||
User notifyUser = new User(clientUser.getUserId(),clientUser.getNick());
|
||||
String groupId = group.getGroupId();
|
||||
//发进房间通知 COMMAND_JOIN_GROUP_NOTIFY_RESP
|
||||
JoinGroupNotifyRespBody joinGroupNotifyRespBody = JoinGroupNotifyRespBody.success();
|
||||
joinGroupNotifyRespBody.setGroup(groupId).setUser(notifyUser);
|
||||
Jim.sendToGroup(groupId, ProtocolManager.Converter.respPacket(joinGroupNotifyRespBody,imChannelContext));
|
||||
}
|
||||
|
||||
}
|
@ -1,266 +0,0 @@
|
||||
package org.jim.site.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tio.utils.lock.ListWithLock;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
/**
|
||||
* 美女图
|
||||
* @author tanyaowu
|
||||
* 2017年5月14日 上午9:48:03
|
||||
*/
|
||||
public class ImgMnService {
|
||||
private static Logger log = LoggerFactory.getLogger(ImgMnService.class);
|
||||
|
||||
public static final ListWithLock<String> imgListWithLock = new ListWithLock<>(new ArrayList<String>());
|
||||
|
||||
public static final String dftimg = "http://images.rednet.cn/articleimage/2013/01/23/1403536948.jpg";
|
||||
|
||||
public static final String filepath = "/page/imgs/mn.txt";
|
||||
|
||||
public static final int maxSize = 100000;
|
||||
|
||||
static {
|
||||
start();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @author: tanyaowu
|
||||
*/
|
||||
public ImgMnService() {
|
||||
|
||||
}
|
||||
|
||||
static AtomicInteger imgIndex = new AtomicInteger();
|
||||
|
||||
public static String nextImg() {
|
||||
|
||||
Lock lock = imgListWithLock.getLock().readLock();
|
||||
try {
|
||||
lock.lock();
|
||||
List<String> list = imgListWithLock.getObj();
|
||||
|
||||
if (list.size() == 0) {
|
||||
return dftimg;
|
||||
}
|
||||
|
||||
int index = imgIndex.incrementAndGet() % list.size();// RandomUtil.randomInt(0, list.size() - 1);
|
||||
log.info("图片index:" + index);
|
||||
String imgsrc = list.get(index);
|
||||
if (StringUtils.isNotBlank(imgsrc)) {
|
||||
return imgsrc;
|
||||
}
|
||||
return nextImg();
|
||||
|
||||
} catch (Exception e1) {
|
||||
log.error(e1.toString(), e1);
|
||||
return dftimg;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
work();
|
||||
try {
|
||||
Thread.sleep(60*1000 * 60); //多长时间爬一次
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "get img url").start();
|
||||
|
||||
}
|
||||
|
||||
static String[] pags = new String[] {
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_1.html", //唯美写真
|
||||
/*"http://www.mmonly.cc/wmtp/wmxz/list_27_2.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_3.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_4.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_5.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_6.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_7.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_8.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_9.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_10.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_11.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_12.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_13.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_14.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_15.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_16.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_17.html", //唯美写真
|
||||
"http://www.mmonly.cc/wmtp/wmxz/list_27_18.html", //唯美写真
|
||||
|
||||
"http://www.mmonly.cc/wmtp/qltp/list_22_2.html", //情侣图片*/
|
||||
};
|
||||
|
||||
public static void work() {
|
||||
String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
|
||||
File file = new File(basePath+filepath);
|
||||
if (file.exists()) {
|
||||
List<String> list = FileUtil.readLines(file, "utf-8");
|
||||
if (list.size() >= 1000) {
|
||||
imgListWithLock.getObj().addAll(list);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
FileUtil.touch(file);//创建文件
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
list.addAll(imgListWithLock.getObj());
|
||||
|
||||
long sleeptime = 500;
|
||||
boolean isfirst = false;
|
||||
if (list.size() == 0) {
|
||||
isfirst = true;
|
||||
sleeptime = 1;
|
||||
}
|
||||
|
||||
L1: for (String pag : pags) {
|
||||
try {
|
||||
Document doc = null;
|
||||
//创建页面对象
|
||||
doc = Jsoup.connect(pag).userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36")
|
||||
.timeout(10000).get();
|
||||
//根据标签和class id获取元素
|
||||
Elements div = doc.select("div.ABox");
|
||||
//根据标签获取元素
|
||||
Elements pages = div.select("a");
|
||||
|
||||
|
||||
|
||||
int count = 0;
|
||||
int invalidCount = 0;
|
||||
for (Element e : pages) {
|
||||
String page = e.attr("href");
|
||||
try {
|
||||
Document imgdoc = Jsoup.connect(page)
|
||||
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36").timeout(10000)
|
||||
.get();
|
||||
Elements div22 = imgdoc.select(".totalpage");
|
||||
String totalpageStr = div22.get(0).text();
|
||||
int totalpage = Integer.parseInt(totalpageStr);
|
||||
if (totalpage > 0) {
|
||||
for (int i = 1; i <= totalpage; i++) {
|
||||
String url = page.substring(0, page.length() - 5) + "_" + i + ".html";
|
||||
try {
|
||||
Document imgpage = Jsoup.connect(url)
|
||||
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36")
|
||||
.timeout(10000).get();
|
||||
Elements div2 = imgpage.select("#big-pic");
|
||||
Elements p = div2.select("p");
|
||||
Elements img = p.select("img");
|
||||
String src = img.attr("src");
|
||||
|
||||
if (StringUtils.isBlank(src) || !StringUtils.startsWith(src, "http")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isfirst) {
|
||||
boolean f = savefile(src);
|
||||
if (!f) {
|
||||
break L1;
|
||||
}
|
||||
} else {
|
||||
list.add(src);
|
||||
log.error("{}、【{}】", list.size(), src);
|
||||
while (list.size() > maxSize) {
|
||||
break L1;
|
||||
// list.remove(0);
|
||||
// log.error("删除一个元素后:{}", list.size());
|
||||
}
|
||||
}
|
||||
invalidCount++;
|
||||
|
||||
count++;
|
||||
i++;
|
||||
Thread.sleep(sleeptime);
|
||||
} catch (Exception e1) {
|
||||
//log.error("【"+url+"】爬取异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
//log.error("【"+page+"】爬取异常!");
|
||||
}
|
||||
}
|
||||
if (!isfirst) {
|
||||
savefile(list);
|
||||
}
|
||||
|
||||
log.info("抓取图片地址,打完收工,本次共找到:{}, 其中有效数据:{},", count, invalidCount);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> list1 = imgListWithLock.getObj();
|
||||
FileUtil.writeLines(list1,file.getPath(), "utf-8");
|
||||
}
|
||||
|
||||
public static void savefile(List<String> srcs) {
|
||||
WriteLock lock = imgListWithLock.getLock().writeLock();
|
||||
try {
|
||||
lock.lock();
|
||||
List<String> list = imgListWithLock.getObj();
|
||||
list.addAll(srcs);
|
||||
} catch (Exception e1) {
|
||||
log.error(e1.toString(), e1);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean savefile(String src) {
|
||||
WriteLock lock = imgListWithLock.getLock().writeLock();
|
||||
try {
|
||||
lock.lock();
|
||||
List<String> list = imgListWithLock.getObj();
|
||||
list.add(src);
|
||||
log.info("{}、【{}】", list.size(), src);
|
||||
while (list.size() > maxSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e1) {
|
||||
log.error(e1.toString(), e1);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @author: tanyaowu
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
start();
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.jim.site.service;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.jim.common.*;
|
||||
import org.jim.common.packets.Group;
|
||||
import org.jim.common.packets.LoginReqBody;
|
||||
import org.jim.common.packets.LoginRespBody;
|
||||
import org.jim.common.packets.User;
|
||||
import org.jim.common.session.id.impl.UUIDSessionIdGenerator;
|
||||
import org.jim.common.utils.Md5;
|
||||
import org.jim.server.command.handler.processor.login.LoginCmdProcessor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author WChao
|
||||
*
|
||||
*/
|
||||
public class LoginServiceProcessor implements LoginCmdProcessor {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(LoginServiceProcessor.class);
|
||||
|
||||
public static final Map<String, User> tokenMap = new HashMap<>();
|
||||
|
||||
private static String[] familyName = new String[] { "谭", "刘", "张", "李", "胡", "沈", "朱", "钱", "王", "伍", "赵", "孙", "吕", "马", "秦", "毛", "成", "梅", "黄", "郭", "杨", "季", "童", "习", "郑",
|
||||
"吴", "周", "蒋", "卫", "尤", "何", "魏", "章", "郎", " 唐", "汤", "苗", "孔", "鲁", "韦", "任", "袁", "贺", "狄朱" };
|
||||
|
||||
private static String[] secondName = new String[] { "艺昕", "红薯", "明远", "天蓬", "三丰", "德华", "歌", "佳", "乐", "天", "燕子", "子牛", "海", "燕", "花", "娟", "冰冰", "丽娅", "大为", "无为", "渔民", "大赋",
|
||||
"明", "远平", "克弱", "亦菲", "靓颖", "富城", "岳", "先觉", "牛", "阿狗", "阿猫", "辰", "蝴蝶", "文化", "冲之", "悟空", "行者", "悟净", "悟能", "观", "音", "乐天", "耀扬", "伊健", "炅", "娜", "春花", "秋香", "春香",
|
||||
"大为", "如来", "佛祖", "科比", "罗斯", "詹姆屎", "科神", "科蜜", "库里", "卡特", "麦迪", "乔丹", "魔术师", "加索尔", "法码尔", "南斯", "伊哥", "杜兰特", "保罗", "杭州", "爱湘", "湘湘", "昕", "函", "鬼谷子", "膑", "荡",
|
||||
"子家", "德利优视", "五方会谈", "来电话了", "T-IO", "Talent" ,"轨迹","超"};
|
||||
|
||||
/**
|
||||
* 根据用户名和密码获取用户
|
||||
* @param loginReqBody
|
||||
* @param imChannelContext
|
||||
* @return
|
||||
* @author: WChao
|
||||
*/
|
||||
public User getUser(LoginReqBody loginReqBody, ImChannelContext imChannelContext) {
|
||||
String text = loginReqBody.getUserId()+loginReqBody.getPassword();
|
||||
String key = ImConst.AUTH_KEY;
|
||||
String token = Md5.sign(text, key, CHARSET);
|
||||
User user = getUser(token);
|
||||
user.setUserId(loginReqBody.getUserId());
|
||||
return user;
|
||||
}
|
||||
/**
|
||||
* 根据token获取用户信息
|
||||
* @param token
|
||||
* @return
|
||||
* @author: WChao
|
||||
*/
|
||||
public User getUser(String token) {
|
||||
//demo中用map,生产环境需要用cache
|
||||
User user = tokenMap.get(token);
|
||||
if (user == null) {
|
||||
user = new User();
|
||||
user.setUserId(UUIDSessionIdGenerator.instance.sessionId(null));
|
||||
user.setNick(familyName[RandomUtil.randomInt(0, familyName.length - 1)] + secondName[RandomUtil.randomInt(0, secondName.length - 1)]);
|
||||
|
||||
user.setGroups(initGroups(user));
|
||||
user.setFriends(initFriends(user));
|
||||
user.setAvatar(nextImg());
|
||||
|
||||
if (tokenMap.size() > 10000) {
|
||||
tokenMap.clear();
|
||||
}
|
||||
tokenMap.put(token, user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public List<Group> initGroups(User user){
|
||||
//模拟的群组;正式根据业务去查数据库或者缓存;
|
||||
List<Group> groups = new ArrayList<Group>();
|
||||
groups.add(Group.newBuilder().groupId("100").name("J-IM朋友圈").build());
|
||||
return groups;
|
||||
}
|
||||
|
||||
public List<Group> initFriends(User user){
|
||||
List<Group> friends = new ArrayList<Group>();
|
||||
Group myFriend = Group.newBuilder().groupId("1").name("我的好友").build();
|
||||
List<User> myFriendGroupUsers = new ArrayList<User>();
|
||||
User user1 = new User();
|
||||
user1.setUserId(UUIDSessionIdGenerator.instance.sessionId(null));
|
||||
user1.setNick(familyName[RandomUtil.randomInt(0, familyName.length - 1)] + secondName[RandomUtil.randomInt(0, secondName.length - 1)]);
|
||||
user1.setAvatar(nextImg());
|
||||
myFriendGroupUsers.add(user1);
|
||||
myFriend.setUsers(myFriendGroupUsers);
|
||||
friends.add(myFriend);
|
||||
return friends;
|
||||
}
|
||||
|
||||
public String nextImg() {
|
||||
return ImgMnService.nextImg();
|
||||
}
|
||||
|
||||
/**
|
||||
* doLogin方法注意:J-IM登陆命令是根据user是否为空判断是否登陆成功,
|
||||
*
|
||||
* 当登陆失败时设置user属性需要为空,相反登陆成功user属性是必须非空的;
|
||||
*/
|
||||
@Override
|
||||
public LoginRespBody doLogin(LoginReqBody loginReqBody, ImChannelContext imChannelContext) {
|
||||
if(Objects.nonNull(loginReqBody.getUserId()) && Objects.nonNull(loginReqBody.getPassword())){
|
||||
return LoginRespBody.success();
|
||||
}else {
|
||||
return LoginRespBody.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(User user, ImChannelContext channelContext) {
|
||||
logger.info("登录成功回调方法");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(ImChannelContext imChannelContext) {
|
||||
logger.info("登录失败回调方法");
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
##J-IM\u57FA\u7840\u914D\u7F6E
|
||||
#ip
|
||||
jim.bind.ip = 127.0.0.1
|
||||
#\u7AEF\u53E3
|
||||
jim.port = 8888
|
||||
#\u5FC3\u8DF3\u8D85\u65F6\u65F6\u957F
|
||||
jim.heartbeat.timeout = 0
|
||||
#\u662F\u5426\u5F00\u542F\u6D88\u606F\u6301\u4E45\u5316(on:\u5F00\u542F,off:\u4E0D\u5F00\u542F)
|
||||
jim.store = off
|
||||
#\u662F\u5426\u5F00\u542F\u96C6\u7FA4(on:\u5F00\u542F,off:\u4E0D\u5F00\u542F)
|
||||
jim.cluster = off
|
||||
#\u662F\u5426\u5F00\u542FSSL(on:\u5F00\u542F,off:\u4E0D\u5F00\u542F)
|
||||
jim.ssl = off
|
||||
#JKS\u8BC1\u4E66\u5730\u5740
|
||||
jim.key.store.path = classpath:ssl/keystore.jks
|
||||
#JKS\u8BC1\u4E66\u5BC6\u7801
|
||||
jim.key.store.pwd = 214323428310224
|
||||
|
||||
##http\u534F\u8BAE \u914D\u7F6E
|
||||
#html/css/js\u7B49\u7684\u6839\u76EE\u5F55\uFF0C\u652F\u6301classpath:\u4E5F\u652F\u6301\u7EDD\u5BF9\u8DEF\u5F84
|
||||
jim.http.page = classpath:page
|
||||
#http mvc\u626B\u63CF\u5305\u8DEF\u5F84
|
||||
jim.http.scan.packages = ImServerDemoStart
|
||||
#http\u8D44\u6E90\u7F13\u5B58\u65F6\u957F
|
||||
jim.http.max.live.time = 0
|
||||
|
||||
##ws\u534F\u8BAE\u914D\u7F6E
|
||||
|
||||
|
||||
|
||||
##Redis\u76F8\u5173\u914D\u7F6E
|
||||
#\u8FDE\u63A5\u6C60\u8FDE\u63A5\u4E0D\u591F\u7528\u65F6,\u91CD\u8BD5\u83B7\u53D6\u8FDE\u63A5\u6B21\u6570
|
||||
jim.redis.retrynum = 100
|
||||
#\u53EF\u7528\u8FDE\u63A5\u5B9E\u4F8B\u7684\u6700\u5927\u6570\u76EE\uFF0C\u9ED8\u8BA4\u503C\u4E3A8\uFF1B
|
||||
jim.redis.maxactive = -1
|
||||
#\u63A7\u5236\u4E00\u4E2Apool\u6700\u591A\u6709\u591A\u5C11\u4E2A\u72B6\u6001\u4E3Aidle(\u7A7A\u95F2\u7684)\u7684jedis\u5B9E\u4F8B\uFF0C\u9ED8\u8BA4\u503C\u4E5F\u662F8\u3002
|
||||
jim.redis.maxidle = 20
|
||||
#\u7B49\u5F85\u53EF\u7528\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u9ED8\u8BA4\u503C\u4E3A-1\uFF0C\u8868\u793A\u6C38\u4E0D\u8D85\u65F6\u3002
|
||||
jim.redis.maxwait = 5000
|
||||
jim.redis.timeout = 2000
|
||||
#redis\u6240\u5728\u673A\u5668ip
|
||||
jim.redis.host = 127.0.0.1
|
||||
#redis\u7AEF\u53E3\u53F7
|
||||
jim.redis.port = 6379
|
||||
#redis\u5BC6\u7801
|
||||
jim.redis.auth =
|
@ -1,16 +0,0 @@
|
||||
#http://logback.qos.ch/manual/configuration.html
|
||||
#<include resource="includedConfig.xml"/> resource, file, url (\u88AB\u5305\u542B\u7684\u6587\u4EF6\u9700\u8981\u6EE1\u8DB3\u4E00\u5B9A\u683C\u5F0F)
|
||||
|
||||
context.name=j-im-server-demo
|
||||
|
||||
log.dir=./logs/j-im-server-demo
|
||||
|
||||
rolling.policy.file.name.pattern=yyyy-MM-dd
|
||||
max.file.size=100MB
|
||||
max.history=50
|
||||
|
||||
conversion.pattern=%d %-5level %logger{30}[%line]: %m%n
|
||||
root.level=info
|
||||
|
||||
|
||||
|
@ -1,159 +0,0 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds" debug="true">
|
||||
<property resource="logback.properties" />
|
||||
|
||||
<contextName>${context.name}</contextName> <!-- 本项目的名字 -->
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- root file 日志 -->
|
||||
<appender name="root-file-error"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.dir}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/error.%d{${rolling.policy.file.name.pattern}}.%i.log.zip</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${max.file.size}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>${max.history}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<appender name="root-file-warn"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.dir}/warn.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/warn.%d{${rolling.policy.file.name.pattern}}.%i.log.zip</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${max.file.size}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>${max.history}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>warn</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<appender name="root-file-info"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.dir}/info.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/info.%d{${rolling.policy.file.name.pattern}}.%i.log.zip</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${max.file.size}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>${max.history}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>INFO</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<appender name="root-file-debug"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.dir}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/debug.%d{${rolling.policy.file.name.pattern}}.%i.log.zip</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${max.file.size}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>${max.history}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<root level="${root.level}">
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="root-file-error"/>
|
||||
<appender-ref ref="root-file-warn"/>
|
||||
<appender-ref ref="root-file-info"/>
|
||||
<appender-ref ref="root-file-debug"/>
|
||||
</root>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- 跟踪客户端行为 -->
|
||||
<appender name="tio-client-trace-log-appender" class="ch.qos.logback.classic.sift.SiftingAppender">
|
||||
<discriminator>
|
||||
<Key>tio_client</Key>
|
||||
<DefaultValue>unknown</DefaultValue>
|
||||
</discriminator>
|
||||
|
||||
<sift>
|
||||
<appender name="${tio_client}" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/tio/client-trace/${tio_client}_%d{yyyyMMdd}.log</fileNamePattern>
|
||||
<maxFileSize>20MB</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<Append>false</Append>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>%m%n</pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
</sift>
|
||||
</appender>
|
||||
|
||||
<logger name="tio-client-trace-log" additivity="false">
|
||||
<level value="info"/>
|
||||
<appender-ref ref="tio-client-trace-log-appender"/>
|
||||
</logger>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<appender name="root-file-debug"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.dir}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.dir}/debug.%d{${rolling.policy.file.name.pattern}}.%i.log.zip</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>${max.file.size}</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>${max.history}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${conversion.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
|
||||
</configuration>
|
@ -1,17 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<div
|
||||
style='position: relation; border-radius: 10px; text-align: center; padding: 10px; font-size: 40pt; font-weight: bold; background-color: ##e4eaf4; color: #2d8cf0; border: 0px solid #2d8cf0; width: 600px; height: 400px; margin: auto; box-shadow: 1px 1px 50px #000; position: fixed; top: 0; left: 0; right: 0; bottom: 0;'>
|
||||
<a style='text-decoration: none'
|
||||
href='https://git.oschina.net/tywo45/t-io' target='_blank'><div
|
||||
style='text-shadow: 8px 8px 8px #99e;'>
|
||||
404<br>Not Found
|
||||
</div></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,17 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<div
|
||||
style='position: relation; border-radius: 10px; text-align: center; padding: 10px; font-size: 40pt; font-weight: bold; background-color: ##e4eaf4; color: #2d8cf0; border: 0px solid #2d8cf0; width: 600px; height: 400px; margin: auto; box-shadow: 1px 1px 50px #000; position: fixed; top: 0; left: 0; right: 0; bottom: 0;'>
|
||||
<a style='text-decoration: none'
|
||||
href='https://git.oschina.net/tywo45/t-io' target='_blank'><div
|
||||
style='text-shadow: 8px 8px 8px #99e;'>
|
||||
500<br>Server Error
|
||||
</div></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Before Width: | Height: | Size: 528 B |
@ -1,396 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<link rel="shortcut icon" href="/favicon.ico">
|
||||
<title>J-IM:支持百万在线用户</title>
|
||||
<style type="text/css" media="screen">
|
||||
*{margin:0;padding:0;}
|
||||
#wrap{margin:10px auto; width:80%; height:99%;}
|
||||
.unit{margin-bottom:5px; padding:5px; border:solid 1px #000; height:auto; clear:both;box-sizing:border-box;}
|
||||
.unit label{text-align:right;width:100px;line-height: 30px; display:inline-block;}
|
||||
.unit input{line-height: 30px; width:100px; height:30px;}
|
||||
.log {font-size:11px; font-family:Courier; overflow: auto; height:100%; background:black;width:85%;float:left}
|
||||
.log p{padding:2px;margin:0;}
|
||||
.content{width:100%;overflow:hidden;height:80%;margin:0 0 5px 0;}
|
||||
.online{width: 15%;height: 100%;float:right;background: #FCFCFC;border:solid 1px #000;box-sizing:border-box;}
|
||||
</style>
|
||||
<script type="text/javascript" src="./static/js/date.js"></script>
|
||||
</head>
|
||||
<script>
|
||||
var socket ;
|
||||
var logDiv;
|
||||
var username;
|
||||
var onSelected;
|
||||
var curUser;
|
||||
var friends = [];
|
||||
var groups = [];
|
||||
function connect(){
|
||||
if(curUser){
|
||||
alert("当前已登录,请先退出登录!");
|
||||
return;
|
||||
}
|
||||
var ip = document.getElementById("serverIp").value;
|
||||
var port = document.getElementById("port").value;
|
||||
username = document.getElementById("username").value;
|
||||
var password = document.getElementById("password").value;
|
||||
logDiv = document.getElementById('logs');
|
||||
socket = new WebSocket("ws:"+ip+":"+port+"?username="+username+"&password="+password);
|
||||
socket.onopen = function(e){
|
||||
|
||||
};
|
||||
socket.onerror = function(e){
|
||||
logDiv.innerHTML+="<font color='red' size='1'>异常:"+e+"</font><br>";
|
||||
scrollToBottom();
|
||||
};
|
||||
socket.onclose = function(e){
|
||||
curUser = null;
|
||||
logDiv.innerHTML+="<font color='green' size='1'>关闭连接...</font><br>";
|
||||
document.getElementById("onlinePanel").innerHTML=" 在线成员(0/0)";
|
||||
scrollToBottom();
|
||||
};
|
||||
socket.onmessage = function(e){
|
||||
var data = e.data;
|
||||
var dataObj = eval("("+data+")");//转换为json对象
|
||||
if(dataObj.command == 11){//接收到聊天响应处理;
|
||||
COMMAND_CHAT_RESP(dataObj);
|
||||
}else if(dataObj.command == 18){//获取用户信息响应处理;
|
||||
COMMAND_GET_USER_RESP(dataObj);
|
||||
}else if(10000 == dataObj.code && dataObj.command == 12){//聊天发送状态;
|
||||
COMMAND_CHAT_RESP_SEND_STATUS(data);
|
||||
}else if(dataObj.command == 9){//加入群组的消息通知处理;
|
||||
COMMAND_JOIN_GROUP_NOTIFY_RESP(dataObj);
|
||||
}else if(dataObj.command == 10){
|
||||
COMMAND_EXIT_GROUP_NOTIFY_RESP(dataObj);
|
||||
}else if(dataObj.command == 20 && dataObj.code == 10015){
|
||||
//获取消息失败,未开启持久化处理
|
||||
//...
|
||||
}else if(dataObj.command == 20 && dataObj.code == 10016){//处理离线消息;
|
||||
var msgFlag = "离线消息";
|
||||
COMMAND_GET_MESSAGE_RESP(dataObj,msgFlag);
|
||||
}else if(dataObj.command == 20 && dataObj.code == 10018){//处理历史消息;
|
||||
var msgFlag = "历史消息";
|
||||
var msgObj = dataObj.data;
|
||||
if(msgObj){
|
||||
COMMAND_GET_MESSAGE_RESP(dataObj,msgFlag);
|
||||
}else{//没有历史消息;
|
||||
OTHER(data);
|
||||
}
|
||||
}else if(dataObj.command == 6){//登陆命令返回状态处理
|
||||
COMMAND_LOGIN_RESP(dataObj,data);
|
||||
}else{
|
||||
OTHER(data);
|
||||
}
|
||||
scrollToBottom();
|
||||
};
|
||||
}
|
||||
//登陆通知处理
|
||||
function COMMAND_LOGIN_RESP(dataObj,data){
|
||||
if(10007 == dataObj.code){//登陆成功;
|
||||
logDiv.innerHTML+="<font color='green' size='1'>连接成功...</font><br>";
|
||||
var userCmd = "{\"cmd\":17,\"type\":\"0\",\"userId\":\""+username+"\"}";
|
||||
var msgCmd = "{\"cmd\":19,\"type\":\"0\",\"userId\":\""+username+"\"}";
|
||||
socket.send(userCmd);//获取登录用户信息;
|
||||
socket.send(msgCmd);//获取用户离线消息(好友+群组);
|
||||
scrollToBottom();
|
||||
}else if(10008 == dataObj.code){//登录失败;
|
||||
OTHER(data);
|
||||
}
|
||||
}
|
||||
function COMMAND_EXIT_GROUP_NOTIFY_RESP(data){
|
||||
var exitGroupNotify = data.data;
|
||||
var onlineUserCmd = "{\"cmd\":17,\"type\":\"0\",\"userId\":\""+curUser.userId+"\"}";
|
||||
logDiv.innerHTML+="<font color='#A3A3A3' size='1'>"+exitGroupNotify.user.nick+"("+exitGroupNotify.user.userId+")退出群聊...</font><br>";
|
||||
socket.send(onlineUserCmd);//获取在线用户列表;
|
||||
}
|
||||
//加入群组的消息通知处理;
|
||||
function COMMAND_JOIN_GROUP_NOTIFY_RESP(data){
|
||||
var user = data.user;
|
||||
logDiv.innerHTML+="<font color='#A3A3A3' size='1'>"+user.nick+"("+user.userId+")加入群聊...</font><br>";
|
||||
var onlineUserCmd = "{\"cmd\":17,\"type\":\"0\",\"userid\":\""+curUser.userId+"\"}";
|
||||
socket.send(onlineUserCmd);//获取在线用户列表;
|
||||
}
|
||||
//加入群组响应状态处理;
|
||||
function COMMAND_JOIN_GROUP_RESP(data){
|
||||
//成功加入群组响应信息;
|
||||
}
|
||||
//发送聊天请求发送状态处理;
|
||||
function COMMAND_CHAT_RESP_SEND_STATUS(data){
|
||||
//发送成功后的状态处理...
|
||||
}
|
||||
//获取用户信息响应处理;
|
||||
function COMMAND_GET_USER_RESP(data){
|
||||
var user = data.data;
|
||||
curUser = user;
|
||||
initOnlineUsers();
|
||||
}
|
||||
//接收到聊天响应处理;
|
||||
function COMMAND_CHAT_RESP(data){
|
||||
var chatObj = data.data;
|
||||
var createTime = new Date(chatObj.createTime).Format("yyyy/MM/dd HH:mm:ss");
|
||||
var from = chatObj.from;
|
||||
if(from == username)
|
||||
return;
|
||||
var content = chatObj.content;
|
||||
var user = getOnlineUserById(from);
|
||||
if(user){
|
||||
logDiv.innerHTML+="<font color='#009ACD' size='1' style='font-weight: bold'>"+user.nick+"("+user.id+")"+" "+createTime+"</font><br>";
|
||||
}else{
|
||||
logDiv.innerHTML+="<font color='#009ACD' size='1' style='font-weight: bold'>"+from+" "+createTime+"</font><br>";
|
||||
}
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='#FFFFFF' size='1'> "+content+"</font><br>";
|
||||
}
|
||||
//处理用户同步+持久化消息
|
||||
function COMMAND_GET_MESSAGE_RESP(data,msgFlag){
|
||||
var msgObj = data.data;
|
||||
friendOfflineMessage(msgObj,msgFlag);
|
||||
groupOfflineMessage(msgObj,msgFlag);
|
||||
}
|
||||
//好友消息
|
||||
function friendOfflineMessage(msgObj,msgFlag){
|
||||
var friends = msgObj.friends;
|
||||
for (var key in friends) {
|
||||
var chatDatas = friends[key];
|
||||
for(var index in chatDatas){
|
||||
var user_id = chatDatas[index].from;
|
||||
var createTime = new Date(chatDatas[index].createTime).Format("yyyy/MM/dd HH:mm:ss");
|
||||
logDiv.innerHTML+="<font color=' #009ACD' size='1' style='font-weight: bold'>"+user_id+"</font><font color='#DC143C' size='1' style='font-weight: bold'>(好友"+msgFlag+")</font>"+"<font color='#009ACD' size='1' style='font-weight: bold'>"+createTime+"</font><br>";
|
||||
logDiv.innerHTML+="<font color='#FFFFFF' size='1'> "+chatDatas[index].content+"</font><br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
//群组消息
|
||||
function groupOfflineMessage(msgObj,msgFlag){
|
||||
var groups = msgObj.groups;
|
||||
for (var key in groups) {
|
||||
var chatDatas = groups[key];
|
||||
for(var index in chatDatas){
|
||||
var user_id = chatDatas[index].from;
|
||||
var createTime = new Date(chatDatas[index].createTime).Format("yyyy/MM/dd HH:mm:ss");
|
||||
logDiv.innerHTML+="<font color=' #009ACD' size='1' style='font-weight: bold'>"+user_id+"</font><font color='#DC143C' size='1' style='font-weight: bold'>(群聊["+chatDatas[index].group_id+"]"+msgFlag+")</font>"+"<font color='#009ACD' size='1' style='font-weight: bold'>"+createTime+"</font><br>";
|
||||
logDiv.innerHTML+="<font color='#FFFFFF' size='1'> "+chatDatas[index].content+"</font><br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
//其它信息处理;
|
||||
function OTHER(data){
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='green' size='1'>"+data+"</font><br>";
|
||||
}
|
||||
function getOnlineUserById(id){
|
||||
var groups = curUser.groups;
|
||||
var onlineUserStr = "";
|
||||
for(var g = 0 ; g < groups.length ; g++){
|
||||
var group = groups[g];
|
||||
var users = group.users;
|
||||
for(var u = 0 ; u < users.length ; u++){
|
||||
var user = users[u];
|
||||
if(user.id == id){
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function initOnlineUsers(){
|
||||
var groups = curUser.groups;
|
||||
var onlineUserStr = "";
|
||||
for(var g = 0 ; g < groups.length ; g++){
|
||||
var group = groups[g];
|
||||
var users = group.users;
|
||||
onlineUserStr += " "+group.name+"在线成员("+users.length+"/"+users.length+")";
|
||||
for(var u = 0 ; u < users.length ; u++){
|
||||
var user = users[u];
|
||||
onlineUserStr +="<div id=\""+user.userId+"\" nick=\""+user.nick+"\" style=\"line-height: 25px;margin: 5px 5px 0 5px;padding-left:15px;cursor:pointer;\" onclick=\"onlineDb(this);\" onmouseover=\"onlineMove(this);\" onmouseleave=\"onlineLeave(this);\"><img alt=\""+user.userId+"\" src=\""+user.avatar+"\" height=\"25px\" width=\"25px;\" style=\"float:left\"> <font size='2'>"+user.nick+"("+user.userId+")</font></div>";
|
||||
}
|
||||
}
|
||||
if(!onlineUserStr){
|
||||
onlineUserStr = " 在线成员(0/0)";
|
||||
}
|
||||
document.getElementById("onlinePanel").innerHTML = onlineUserStr;
|
||||
}
|
||||
function disConnect(){
|
||||
socket.close();
|
||||
}
|
||||
|
||||
function send(){
|
||||
var toId = "";
|
||||
if(onSelected){
|
||||
toId = onSelected.getElementsByTagName("img")[0].alt;
|
||||
}
|
||||
var createTime = new Date().getTime();
|
||||
var content = document.getElementById('content').value;
|
||||
if(content == "")
|
||||
return ;
|
||||
var msg = "{\"from\": \""+username+"\",\"to\": \""+toId+"\",\"cmd\":11,\"createTime\":"+createTime+",\"chatType\":\"2\",\"msgType\": \"0\",\"content\": \""+content+"\"}";
|
||||
if(!toId){
|
||||
alert("请选择要私聊的人!");
|
||||
return;
|
||||
}
|
||||
if(toId == username){
|
||||
alert("无法给自己发送消息!");
|
||||
return ;
|
||||
}
|
||||
socket.send(msg);
|
||||
var chatObj = eval("("+msg+")");
|
||||
var createTime = new Date(chatObj.createTime).Format("yyyy/MM/dd HH:mm:ss");
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='#228B22' size='1' style='font-weight: bold'>"+chatObj.from+" "+createTime+"</font><br>";
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='#FFFFFF' size='1'> "+chatObj.content+"</font><br>";
|
||||
document.getElementById('content').value = "";
|
||||
}
|
||||
function sendGroup(){
|
||||
var createTime = new Date().getTime();
|
||||
var content = document.getElementById('content').value;
|
||||
if(content == "")
|
||||
return ;
|
||||
var msg = "{\"from\": \""+username+"\",\"createTime\":"+createTime+",\"cmd\":11,\"group_id\":\"100\",\"chatType\":\"1\",\"msgType\":\"0\",\"content\": \""+content+"\"}";
|
||||
socket.send(msg);
|
||||
var chatObj = eval("("+msg+")");
|
||||
var createTime = new Date(chatObj.createTime).Format("yyyy/MM/dd HH:mm:ss");
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='#228B22' size='1' style='font-weight: bold'>"+curUser.nick+"("+curUser.userId+")"+" "+createTime+"</font><br>";
|
||||
//处理数据
|
||||
logDiv.innerHTML+="<font color='#FFFFFF' size='1'> "+chatObj.content+"</font><br>";
|
||||
document.getElementById('content').value = "";
|
||||
}
|
||||
function scrollToBottom(){
|
||||
var logDiv = document.getElementById('logs');
|
||||
logDiv.scrollTop = logDiv.scrollHeight;
|
||||
}
|
||||
function clearLogs(){
|
||||
var logDiv = document.getElementById('logs');
|
||||
logDiv.innerHTML="";
|
||||
}
|
||||
function showServerConfig(obj){
|
||||
var target = document.getElementById("serverConfigId");
|
||||
if (target.style.display=="block"){
|
||||
target.style.display="none";
|
||||
obj.value="服务器配置";
|
||||
} else {
|
||||
target.style.display="block";
|
||||
obj.value='关闭配置';
|
||||
}
|
||||
}
|
||||
function onlineDb(obj){
|
||||
if(onSelected){
|
||||
if(onSelected.id != obj.id){
|
||||
onSelected.style.background = "";
|
||||
}
|
||||
}
|
||||
obj.style.background = "#D4D4D4";
|
||||
onSelected = obj;
|
||||
var sendBtn = document.getElementById("sendBtn");
|
||||
sendBtn.style="width: 150px;"
|
||||
sendBtn.value="发送给:"+onSelected.id;
|
||||
}
|
||||
function onlineMove(obj){
|
||||
if("undefined" == typeof(onSelected) || onSelected.id != obj.id){
|
||||
obj.style.background = "#F0F0F0";
|
||||
}
|
||||
}
|
||||
function onlineLeave(obj){
|
||||
var onlineDiv = document.getElementById("onlinePanel").getElementsByTagName("div");
|
||||
for(var i =0 ; i < onlineDiv.length ; i++){
|
||||
if("undefined" == typeof(onSelected) || onSelected.id != onlineDiv[i].id){
|
||||
onlineDiv[i].style.background = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
function setUserName(){
|
||||
document.getElementById("username").value = new Date().getTime();
|
||||
}
|
||||
function keyDown(e) {
|
||||
var ev= window.event||e;
|
||||
//13是键盘上面固定的回车键
|
||||
if (ev.keyCode == 13) {
|
||||
sendGroup();
|
||||
}
|
||||
}
|
||||
function authCmd(){
|
||||
if(!curUser){
|
||||
alert("demo中模拟命令需要先登录,请先登录!");
|
||||
}
|
||||
var authCmd = "{\"cmd\":3,\"token\":\"校验码\"}";
|
||||
socket.send(authCmd);
|
||||
}
|
||||
function heartbeatCmd(){
|
||||
if(!curUser){
|
||||
alert("demo中模拟命令需要先登录,请先登录!");
|
||||
}
|
||||
var heartbeatCmd = "{\"cmd\":13,\"hbbyte\":\"-127\"}";
|
||||
socket.send(heartbeatCmd);
|
||||
}
|
||||
|
||||
function friendHistoryCmd(){
|
||||
if(!curUser){
|
||||
alert("请先登录!");
|
||||
return;
|
||||
}
|
||||
var friend_id = document.getElementById("history_friend_id").value;;
|
||||
if(friend_id == ""){
|
||||
alert("请输入要获取的好友ID!");
|
||||
return;
|
||||
}
|
||||
var msgHistoryCmd = "{\"cmd\":19,\"type\":\"1\",\"fromUserId\":\""+friend_id+"\",\"userId\":\""+username+"\"}";
|
||||
socket.send(msgHistoryCmd);//获取用户历史消息;
|
||||
}
|
||||
|
||||
function groupHistoryCmd(){
|
||||
if(!curUser){
|
||||
alert("请先登录!");
|
||||
return;
|
||||
}
|
||||
var group_id = document.getElementById("history_group_id").value;;
|
||||
if(group_id == ""){
|
||||
alert("请输入要获取的群组ID!");
|
||||
return;
|
||||
}
|
||||
var msgHistoryCmd = "{\"cmd\":19,\"type\":\"1\",\"groupId\":\""+group_id+"\",\"userId\":\""+username+"\"}";
|
||||
socket.send(msgHistoryCmd);//获取群组历史消息;
|
||||
}
|
||||
</script>
|
||||
<body onload="setUserName();">
|
||||
<div id="wrap" style="height:600px;">
|
||||
<div class="unit">
|
||||
<label >用户名:</label>
|
||||
<input id="username" value=""/>
|
||||
<label style="width: 60px;">密码:</label>
|
||||
<input id="password" value ="123"/>
|
||||
<input onclick="javascript:connect();" type="button" value="登录" />
|
||||
<input onclick="javascript:disConnect();" type="button" value="退出" />
|
||||
<input onclick="javascript:showServerConfig(this);" type="button" value="服务器配置" />
|
||||
</div>
|
||||
<div class="unit" id="serverConfigId" style="display: none;">
|
||||
<label >服务器IP:</label>
|
||||
<input id="serverIp" value="localhost"/>
|
||||
<label>端口号:</label>
|
||||
<input id="port" value ="8888"/>
|
||||
</div>
|
||||
<div class="unit">
|
||||
<label>聊天记录:</label>
|
||||
<input type="button" value="清空记录" onclick="clearLogs();"/>
|
||||
<input type="button" value="鉴权命令" onclick="authCmd();"/>
|
||||
<input type="button" value="心跳命令" onclick="heartbeatCmd();"/>
|
||||
<input type="button" value="获取指定好友历史消息" onclick="friendHistoryCmd();" style="width: 150px;"/>
|
||||
<input id="history_friend_id" style="width:100px;" placeholder="输入好友ID"/>
|
||||
<input type="button" value="获取指定群组历史消息" onclick="groupHistoryCmd();" style="width: 150px;"/>
|
||||
<input id="history_group_id" style="width:100px;" placeholder="输入群组ID"/>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div id="logs" class="unit log">
|
||||
</div>
|
||||
<div id="onlinePanel" class="online">
|
||||
在线成员(0/0)
|
||||
</div>
|
||||
</div>
|
||||
<div class="unit">
|
||||
<label >输入内容:</label>
|
||||
<input id="content" style="width:500px;" onkeydown="keyDown(event)"/>
|
||||
<input onclick="javascript:sendGroup()" id="sendGroupBtn" type="button" value="群聊" /> <input onclick="javascript:send()" id="sendBtn" type="button" value="私聊" />
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,15 +0,0 @@
|
||||
Date.prototype.Format = function (fmt) { //author: wchao
|
||||
var o = {
|
||||
"M+": this.getMonth() + 1, //月份
|
||||
"d+": this.getDate(), //日
|
||||
"H+": this.getHours(), //小时
|
||||
"m+": this.getMinutes(), //分
|
||||
"s+": this.getSeconds(), //秒
|
||||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||||
"S": this.getMilliseconds() //毫秒
|
||||
};
|
||||
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||||
for (var k in o)
|
||||
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
||||
return fmt;
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,17 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>bean测试</title>
|
||||
</head>
|
||||
<body>
|
||||
post<br>
|
||||
<form action="/test/bean" method="post" enctype="application/x-www-form-urlencoded">
|
||||
<input type="text" name="id" value="123456"/><br><br>
|
||||
<input type="text" name="loginname" value="tanyaowu"/><br><br>
|
||||
<input type="text" name="nick" value="talent_tan"/><br><br>
|
||||
<input type="text" name="ip" value="192.168.1.156"/><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,43 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>plain测试</title>
|
||||
</head>
|
||||
<body>
|
||||
post<br>
|
||||
<form action="/test/plain" method="post" enctype="text/plain">
|
||||
<textarea name="before">
|
||||
{"name":"tan", "id":1245555}
|
||||
</textarea><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
|
||||
<br>pos:no namet<br>
|
||||
<form action="/test/plain" method="post" enctype="text/plain">
|
||||
<textarea name="">
|
||||
{"name":"tan", "id":1245555}
|
||||
</textarea><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
|
||||
|
||||
<br>get<br>
|
||||
<form action="/test/plain" method="get" enctype="text/plain">
|
||||
<textarea name="before">
|
||||
{"name":"tan", "id":1245555}
|
||||
</textarea><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<br>get:no name<br>
|
||||
<form action="/test/plain" method="get" enctype="text/plain">
|
||||
<textarea>
|
||||
{"name":"tan", "id":1245555}
|
||||
</textarea><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,24 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>POST测试</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
post<br>
|
||||
<form action="/test/post" method="post" enctype="application/x-www-form-urlencoded">
|
||||
<input type="text" name="before" value="~!@#$%^&*()_`=+-_:<>><>>';?,./1234567890"/><br><br>
|
||||
<input type="text" name="end" value="~!@#$%^&*()_`=+-_:<>><>>';?,./1234567890"/><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
|
||||
|
||||
<br>get<br>
|
||||
<form action="/test/post" method="get" enctype="application/x-www-form-urlencoded">
|
||||
<input type="text" name="before" value="~!@#$%^&*()_`=+-_:<>><>>';?,./1234567890"/><br><br>
|
||||
<input type="text" name="end" value="~!@#$%^&*()_`=+-_:<>><>>';?,./1234567890"/><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>文件上传测试</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/test/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="text" name="before" value="123456"/><br><br>
|
||||
<input type="file" name="uploadFile" /><br><br>
|
||||
<input type="text" name="end" value="987654"/><br><br>
|
||||
<input type="submit" value="提 交" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user