-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44fae70
commit 0fd0019
Showing
193 changed files
with
13,851 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?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>com.xbjs</groupId> | ||
<artifactId>webim</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>webim</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.3.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.websocket</groupId> | ||
<artifactId>javax.websocket-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-websocket</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<optional>true</optional> | ||
<scope>true</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid</artifactId> | ||
<version>1.0.29</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
</build> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.xbjs.webim; | ||
|
||
import com.xbjs.webim.controller.WebSocketController; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018 /8/2 | ||
* @description: | ||
*/ | ||
@SpringBootApplication | ||
@MapperScan("com.xbjs.webim.mapper.*") | ||
public class WebimApplication { | ||
|
||
/** | ||
* The entry point of application. | ||
* | ||
* @param args the input arguments | ||
*/ | ||
public static void main(String[] args) { | ||
SpringApplication springApplication = new SpringApplication(WebimApplication.class); | ||
ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args); | ||
//解决WebSocket不能注入的问题 | ||
WebSocketController.setApplicationContext(configurableApplicationContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.xbjs.webim.common; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.xbjs.webim.pojo.ChatMessageResult; | ||
import com.xbjs.webim.pojo.ChatlogResult; | ||
import com.xbjs.webim.pojo.ImChatlog; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018 /9/6 | ||
*/ | ||
@Component | ||
public class ChatMessage { | ||
@Autowired | ||
private Gson gson; | ||
|
||
|
||
/** | ||
* 组装聊天信息 | ||
* | ||
* @param message the message | ||
* @return the chat message | ||
*/ | ||
public ChatMessageResult getChatMessage(String message) { | ||
ChatMessageResult chatMessageResult = new ChatMessageResult(); | ||
JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject(); | ||
JsonObject minData = jsonObject.get("data").getAsJsonObject().get("mine").getAsJsonObject(); | ||
JsonObject toData = jsonObject.get("data").getAsJsonObject().get("to").getAsJsonObject(); | ||
//chatMessageResult.setFromid(minData.get("id").getAsString()); | ||
chatMessageResult.setUsername(minData.get("username").getAsString()); | ||
// chatMessageResult.setMine(minData.get("mine").getAsBoolean()); | ||
chatMessageResult.setId(minData.get("id").getAsString()); | ||
chatMessageResult.setContent(minData.get("content").getAsString()); | ||
chatMessageResult.setAvatar(minData.get("avatar").getAsString()); | ||
chatMessageResult.setTimestamp(System.currentTimeMillis()); | ||
chatMessageResult.setType(toData.get("type").getAsString()); | ||
chatMessageResult.setChatType("chatMessage"); | ||
return chatMessageResult; | ||
} | ||
|
||
public ImChatlog setChatLog(String message, int status) { | ||
|
||
ImChatlog imChatlog = new ImChatlog(); | ||
JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject(); | ||
JsonObject minData = jsonObject.get("data").getAsJsonObject().get("mine").getAsJsonObject(); | ||
JsonObject toData = jsonObject.get("data").getAsJsonObject().get("to").getAsJsonObject(); | ||
imChatlog.setContent(minData.get("content").getAsString()); | ||
imChatlog.setFromid(minData.get("id").getAsLong()); | ||
imChatlog.setSendtime(System.currentTimeMillis()); | ||
imChatlog.setTyp(toData.get("type").getAsString()); | ||
imChatlog.setToid(toData.get("id").getAsLong()); | ||
imChatlog.setStatus(status); | ||
return imChatlog; | ||
} | ||
|
||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.xbjs.webim.common; | ||
|
||
import javax.servlet.*; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018/9/10 | ||
* @description: | ||
*/ | ||
public class ImFilter implements Filter { | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
|
||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.xbjs.webim.common; | ||
|
||
import org.springframework.boot.web.servlet.MultipartConfigFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.socket.server.standard.ServerEndpointExporter; | ||
|
||
import javax.servlet.MultipartConfigElement; | ||
|
||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018/9/4 | ||
* @description: | ||
*/ | ||
@Configuration | ||
public class WebSocketConfig { | ||
@Bean | ||
public ServerEndpointExporter serverEndpointExporter() { | ||
return new ServerEndpointExporter(); | ||
} | ||
|
||
@Bean | ||
public MultipartConfigElement multipartConfigElement(){ | ||
MultipartConfigFactory multipartConfigFactory=new MultipartConfigFactory(); | ||
multipartConfigFactory.setMaxFileSize("102400MB"); | ||
multipartConfigFactory.setMaxRequestSize("102401MB"); | ||
return multipartConfigFactory.createMultipartConfig(); | ||
} | ||
|
||
} | ||
|
54 changes: 54 additions & 0 deletions
54
src/main/java/com/xbjs/webim/controller/OtherController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.xbjs.webim.controller; | ||
|
||
import com.google.gson.Gson; | ||
import com.xbjs.webim.common.WebSocketConfig; | ||
import com.xbjs.webim.pojo.ChatlogResult; | ||
import com.xbjs.webim.service.OtherService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.websocket.server.PathParam; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018/9/10 | ||
* @description: | ||
*/ | ||
@RestController | ||
@Import(value = {WebSocketConfig.class}) | ||
public class OtherController { | ||
@Autowired | ||
private OtherService otherService; | ||
|
||
@PostMapping("/uploadfile") | ||
@ResponseBody | ||
public String uploadFile(@RequestParam("file") MultipartFile multipartFile) { | ||
try { | ||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); | ||
requestFactory.setBufferRequestBody(false); | ||
RestTemplate rest = new RestTemplate(requestFactory); | ||
otherService.uploadFile(multipartFile); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return "{'state':true}"; | ||
} | ||
|
||
@GetMapping("/getChatLog") | ||
@ResponseBody | ||
public List<ChatlogResult> getChatLog(@PathParam("id") Long id, @PathParam("type") String type, HttpServletRequest request) { | ||
return otherService.getChatLog(id,type,(Long) request.getSession().getAttribute("userId")); | ||
} | ||
|
||
} | ||
|
31 changes: 31 additions & 0 deletions
31
src/main/java/com/xbjs/webim/controller/PageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.xbjs.webim.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* | ||
* @author: xincheng.zhao | ||
* @date: 2018/8/2 | ||
* @description: | ||
*/ | ||
@Controller | ||
public class PageController { | ||
@GetMapping("/") | ||
public String index() { | ||
return "index.html"; | ||
} | ||
|
||
@GetMapping("/login") | ||
public String login() { | ||
return "login.html"; | ||
} | ||
|
||
@GetMapping("/upload") | ||
public String upload() { | ||
return "upload.html"; | ||
} | ||
|
||
} |
Oops, something went wrong.