admin
2024-09-05 8631bb49abe5dfed233bc579a228c578232f8079
src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java
@@ -2,9 +2,13 @@
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.exception.LoginUserException;
import com.yeshi.buwan.dto.user.LoginInfoDto;
import com.yeshi.buwan.dto.user.QQUserInfo;
import com.yeshi.buwan.exception.user.LoginUserException;
import com.yeshi.buwan.exception.SMSException;
import com.yeshi.buwan.exception.user.RegisterUserException;
import com.yeshi.buwan.service.imp.CommentService;
import com.yeshi.buwan.service.imp.MaskKeyService;
import com.yeshi.buwan.service.imp.SystemService;
@@ -18,6 +22,8 @@
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.yeshi.utils.entity.wx.WeiXinUser;
@@ -31,6 +37,9 @@
@Controller
public class CommentParser {
    Logger logger = LoggerFactory.getLogger(CommentParser.class);
    @Resource
    private SystemService systemService;
    @Resource
@@ -85,17 +94,60 @@
            return;
        }
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
        LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait,
                name, UserParser.getIp(request) + ":" + request.getRemotePort());
        LoginInfoDto loginInfoDto = new LoginInfoDto();
        loginInfoDto.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort());
        loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId());
        int loginTypeInt = Integer.parseInt(loginType);
        loginInfoDto.setLoginType(loginTypeInt);
        switch (loginTypeInt) {
            case LoginUser.LOGIN_TYPE_EMAIL:
                loginInfoDto.setEmail(openid);
                break;
            case LoginUser.LOGIN_TYPE_QQ:
                QQUserInfo qqUserInfo = new QQUserInfo();
                qqUserInfo.setName(name);
                qqUserInfo.setOpenId(openid);
                qqUserInfo.setPortrait(portrait);
                qqUserInfo.setSex(sex);
                loginInfoDto.setQqUserInfo(qqUserInfo);
                break;
        }
        LoginUser lu = null;
        try {
            lu = userService.login(loginInfoDto);
            if (lu == null) {
                out.print(JsonUtil.loadFalseJson("登录失败"));
                return;
            }
        } catch (LoginUserException e) {
            //用户不存在
            if (e.getCode() == LoginUserException.CODE_NO_USER && loginTypeInt != LoginUser.LOGIN_TYPE_EMAIL) {
                //注册
                try {
                    lu = userService.register(loginInfoDto);
                } catch (RegisterUserException e1) {
                    out.print(JsonUtil.loadFalseJson("登录失败"));
                    return;
                }
            } else {
                out.print(JsonUtil.loadFalseJson(e.getMessage()));
                return;
            }
        }
        if (lu != null) {
            JSONObject object = new JSONObject();
            object.put("LoginUid", lu.getId());
            object.put("Portrait", lu.getPortrait());
            object.put("NickName", lu.getName());
            out.print(JsonUtil.loadTrueJson(object.toString()));
        } else {
            out.print(JsonUtil.loadFalseJson("登录失败"));
        }
    }
@@ -107,25 +159,52 @@
        }
        //通过code换取个人信息
        WeiXinUser weiXinUser = MyWXLoginUtil.getUserInfo(code, MyWXLoginUtil.WEIXIN_APPID, MyWXLoginUtil.WEIXIN_SECRET);
        try {
            logger.error("微信登录:" + new GsonBuilder().create().toJson(weiXinUser));
        } catch (Exception e) {
        }
        if (weiXinUser == null) {
            out.print(JsonUtil.loadFalseJson("获取授权信息失败"));
            out.print(JsonUtil.loadFalseJson("获取授权信息失败,请稍后再试"));
            return;
        }
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
        LoginInfoDto loginInfoDto = new LoginInfoDto();
        loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId());
        loginInfoDto.setLoginType(LoginUser.LOGIN_TYPE_WX);
        loginInfoDto.setWeiXinUser(weiXinUser);
        loginInfoDto.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort());
        LoginUser lu = userService.getLoginUser(weiXinUser.getOpenid(), detailSystem.getId(), 2, weiXinUser.getHeadimgurl(),
                weiXinUser.getNickname(), UserParser.getIp(request) + ":" + request.getRemotePort());
        if (lu != null) {
            JSONObject object = new JSONObject();
            object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu));
            out.print(JsonUtil.loadTrueJson(object.toString()));
        } else {
            out.print(JsonUtil.loadFalseJson("登录失败"));
        try {
            LoginUser lu = userService.login(loginInfoDto);
            if (lu != null) {
                JSONObject object = new JSONObject();
                object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu));
                out.print(JsonUtil.loadTrueJson(object.toString()));
            } else {
                out.print(JsonUtil.loadFalseJson("登录失败"));
            }
        } catch (LoginUserException e) {
            //用户不存在
            if (e.getCode() == LoginUserException.CODE_NO_USER) {
                //注册
                try {
                    LoginUser lu = userService.register(loginInfoDto);
                    if (lu != null) {
                        JSONObject object = new JSONObject();
                        object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu));
                        out.print(JsonUtil.loadTrueJson(object.toString()));
                    } else {
                        out.print(JsonUtil.loadFalseJson("登录失败"));
                    }
                } catch (RegisterUserException e1) {
                    out.print(JsonUtil.loadFalseJson("登录失败"));
                }
            } else {
                out.print(JsonUtil.loadFalseJson(e.getMessage()));
            }
        }
    }
    /**
@@ -154,6 +233,9 @@
        }
        out.print(JsonUtil.loadTrueJson(""));
    }
    /**
@@ -220,7 +302,6 @@
        }
    }
    /**
     * 绑定QQ
@@ -324,14 +405,18 @@
        } catch (SMSException e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseJson(e.getMessage()));
            logger.error("发送验证码出错:phone-{} msg-{}",phone,e.getMessage(),e);
            return;
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseJson("短信发送出错,请稍后再试"));
            logger.error("发送验证码出错:phone-{} msg-{}",phone,e.getMessage(),e);
            return;
        }
        out.print(JsonUtil.loadTrueJson(""));
    }
    public void getVideoCommentList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String videoId = request.getParameter("VideoId");