• 大小: 178KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: Java
  • 标签: WebSocket  Web  wechat  

资源简介

使用WebSocket作为前后端连接方式, SpringMVC+JSP+WebSocket, 即时通讯, 最近聊天记录, 好友列表. 需要配置D盘下创建好对应文件, 图片需要配置nginx才可以访问: server { listen 8888; server_name localhost; location / { alias D://itchat4j/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

资源截图

代码片段和文件信息

package com.wechat.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONobject;
import com.wechat.web.api.MessageTools;
import com.wechat.web.beans.baseMsg;
import com.wechat.web.beans.UserInfo;
import com.wechat.web.core.Core;
import com.wechat.web.face.IMsgHandlerFace;
import com.wechat.web.test.SimpleDemo;
import com.wechat.web.utils.JacksonUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Controller
@RequestMapping(“/“)
public class ChatController {

    public static String QR_CODE_PATH = Contains.base_PATH + Contains.QR_CODE_PATH + “/QR.jpg“;
    private static Core core = Core.getInstance();

    @RequestMapping(value = “index“ method = RequestMethod.GET)
    public String doIndex(HttpServletRequest request HttpServletResponse response) {
        File file = new File(QR_CODE_PATH);
        if (file.exists()) {
            request.setAttribute(“qrCodePath“ Contains.FILE_base_URL + Contains.QR_CODE_PATH + “/QR.jpg“);
        }
        return “hello“;
    }


    @ResponseBody
    @RequestMapping(value = “qrcode“ method = RequestMethod.GET)
    public String doQrCode(HttpServletRequest request HttpServletResponse response) {
        File file = new File(QR_CODE_PATH);
        if (file.exists()) {
            return Contains.FILE_base_URL + Contains.QR_CODE_PATH + “/QR.jpg“;
        }
        return ““;
    }

    @ResponseBody
    @RequestMapping(value = “ping“ method = RequestMethod.GET)
    public String doPing(HttpServletRequest request HttpServletResponse response) {
        JSONobject object = new JSONobject();
        object.put(“alive“ core.isAlive());
        ListseMsg> list = new ArrayList<>();
        for (baseMsg msg : core.getMsgList()) {
            if (!msg.getFromUserName().equals(core.getUserName())) { // 发送者是自己
                list.add(msg);
            }
        }
        object.put(“msgList“ list);

        Listject> recentChats = new ArrayList<>();
        for (String key : core.getMsgMap().keySet()) {
            JSONobject user = null;
            if (key.startsWith(“@@“)) {
                for (JSONobject group : core.getGroupList()) {
                    if (key.equals(group.get(“UserName“))) {
                        user = group;
                    }
                }
            } else

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        311  2018-07-20 14:09  wechat\.idea\artifacts\web_chat_war.xml

     文件       3696  2018-07-23 13:51  wechat\.idea\artifacts\web_chat_war_exploded.xml

     文件        286  2018-07-23 14:48  wechat\.idea\artifacts\wechat_war.xml

     文件       3896  2018-07-26 14:29  wechat\.idea\artifacts\wechat_war_exploded.xml

     文件       1269  2018-07-23 14:48  wechat\.idea\compiler.xml

     文件         76  2018-07-20 14:09  wechat\.idea\copyright\profiles_settings.xml

     文件         42  2018-07-20 14:09  wechat\.idea\description.html

     文件        343  2018-07-20 16:02  wechat\.idea\encodings.xml

     文件        550  2018-07-20 14:16  wechat\.idea\libraries\Maven__aopalliance_aopalliance_1_0.xml

     文件        572  2018-07-20 14:19  wechat\.idea\libraries\Maven__commons_codec_commons_codec_1_9.xml

     文件        608  2018-07-20 14:16  wechat\.idea\libraries\Maven__commons_logging_commons_logging_1_1_3.xml

     文件        550  2018-07-20 14:19  wechat\.idea\libraries\Maven__com_alibaba_fastjson_1_2_31.xml

     文件        680  2018-07-20 15:38  wechat\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_0.xml

     文件        631  2018-07-20 15:38  wechat\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml

     文件        659  2018-07-20 15:38  wechat\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml

     文件        565  2018-07-20 14:19  wechat\.idea\libraries\Maven__com_squareup_okhttp3_okhttp_3_8_0.xml

     文件        546  2018-07-20 14:19  wechat\.idea\libraries\Maven__com_squareup_okio_okio_1_13_0.xml

     文件        561  2018-07-20 14:19  wechat\.idea\libraries\Maven__com_vdurmont_emoji_java_3_2_0.xml

     文件        577  2018-07-20 14:19  wechat\.idea\libraries\Maven__javax_activation_activation_1_1_1.xml

     文件        546  2018-07-20 14:16  wechat\.idea\libraries\Maven__javax_servlet_jsp_jsp_api_2_1.xml

     文件        558  2018-07-20 14:16  wechat\.idea\libraries\Maven__javax_servlet_servlet_api_2_5.xml

     文件        473  2018-07-23 14:48  wechat\.idea\libraries\Maven__jstl_jstl_1_2.xml

     文件        491  2018-07-26 14:27  wechat\.idea\libraries\Maven__junit_junit_4_11.xml

     文件        505  2018-07-20 14:19  wechat\.idea\libraries\Maven__log4j_log4j_1_2_16.xml

     文件        592  2018-07-20 14:19  wechat\.idea\libraries\Maven__org_apache_commons_commons_lang3_3_0.xml

     文件        613  2018-07-20 14:19  wechat\.idea\libraries\Maven__org_apache_httpcomponents_httpclient_4_5_3.xml

     文件        599  2018-07-20 14:19  wechat\.idea\libraries\Maven__org_apache_httpcomponents_httpcore_4_4_6.xml

     文件        585  2018-07-20 14:19  wechat\.idea\libraries\Maven__org_apache_httpcomponents_httpmime_4_5.xml

     文件        568  2018-07-20 14:16  wechat\.idea\libraries\Maven__org_hamcrest_hamcrest_core_1_3.xml

     文件        524  2018-07-20 14:19  wechat\.idea\libraries\Maven__org_json_json_20140107.xml

............此处省略114个文件信息

评论

共有 条评论