wuxw
2022-07-17 ce64e667815b39efdc2f8bd52be0d43d49db8d84
service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
@@ -9,6 +9,7 @@
import com.java110.core.context.PageData;
import com.java110.core.factory.AuthenticationFactory;
import com.java110.core.factory.WechatFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.dto.ownerCarOpenUser.OwnerCarOpenUserDto;
import com.java110.dto.smallWeChat.SmallWeChatDto;
@@ -26,7 +27,6 @@
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -54,6 +54,7 @@
    private final static int expireTime = 7200;
    private final static int LOGIN_PAGE = 1;
    private final static int COMMON_PAGE = 2;
    @Autowired
    private RestTemplate restTemplate;
@@ -214,13 +215,12 @@
        logger.debug("调用微信换去openId " + paramOut);
        if (paramOut.getStatusCode() != HttpStatus.OK) {
            return ResultVo.redirectPage(errorUrl);
        }
        JSONObject paramObj = JSONObject.parseObject(paramOut.getBody());
        //获取 openId
        String openId = paramObj.getString("openid");
        String userinfo_url = WechatConstant.APP_GET_USER_INFO_URL
                .replace("ACCESS_TOKEN", paramObj.getString("access_token"))
                .replace("OPENID", openId);
@@ -235,6 +235,11 @@
        //处理昵称有特殊符号导致 入库失败问题
        userinfo_paramObj.put("nickname", Base64Convert.byteToBase64(userinfo_paramObj.getString("nickname").getBytes()));
        //公众号未绑定 开放平台
        if (StringUtil.isEmpty(userinfo_paramObj.getString("unionid"))) {
            userinfo_paramObj.put("unionid", "-1");
        }
        int loginFlag = paramIn.getInteger("loginFlag");
        //说明是登录页面,下发code 就可以,不需要下发key 之类
@@ -244,12 +249,26 @@
            CommonCache.setValue(code, openId, expireTime);
            CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
                errorUrl += ("?code=" + code);
            }
            logger.debug("登录跳转url:{}", errorUrl);
            return ResultVo.redirectPage(errorUrl);
        }
        if (loginFlag == COMMON_PAGE) {
            //将openId放到redis 缓存,给前段下发临时票据
            if (errorUrl.indexOf("?") > 0) {
                redirectUrl += ("&openId=" + openId);
            } else {
                redirectUrl += ("?openId=" + openId);
            }
            logger.debug("跳转url:{}", redirectUrl);
            return ResultVo.redirectPage(redirectUrl);
        }
        //判断当前openId 是否绑定了业主
@@ -266,6 +285,7 @@
            CommonCache.setValue(code, openId, expireTime);
            CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
@@ -295,6 +315,8 @@
            CommonCache.setValue(code, openId, expireTime);
            CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
@@ -523,6 +545,7 @@
        String openId = CommonCache.getValue(code);
        String nickname = CommonCache.getValue(code + "-nickname");
        String headimgurl = CommonCache.getValue(code + "-headimgurl");
        String unionid = CommonCache.getValue(code + "-unionid");
        if (StringUtil.isEmpty(openId)) {
            responseEntity = new ResponseEntity<>("页面失效,请刷新后重试", HttpStatus.UNAUTHORIZED);
@@ -539,6 +562,7 @@
        JSONObject userOwnerInfo = new JSONObject();
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setOpenId(openId);
        ownerAppUserDto.setUnionId(unionid);
        // ownerAppUserDto.setNickName(StringUtil.encodeEmoji(nickname));
        ownerAppUserDto.setNickName(nickname);
        ownerAppUserDto.setHeadImgUrl(headimgurl);