xiaogang
2021-03-13 c3b5bbea29386128bb09da0978fb70da0b5dce39
service-front/src/main/java/com/java110/front/smo/login/impl/OwnerAppLoginSMOImpl.java
@@ -67,11 +67,17 @@
        ResponseEntity<String> responseEntity;
        JSONObject loginInfo = JSONObject.parseObject(pd.getReqData());
        boolean loginByPhone = false;
        if (paramIn.containsKey("loginByPhone")) {
            loginByPhone = paramIn.getBoolean("loginByPhone");
        }
        loginInfo.put("passwd", AuthenticationFactory.passwdMd5(loginInfo.getString("password")));
        UserDto userDto = new UserDto();
        userDto.setUserName(loginInfo.getString("username"));
        userDto.setPassword(loginInfo.getString("password"));
        userDto.setLoginByPhone(loginByPhone);
        userDto.setLevelCd("02");
        userDto = super.postForApi(pd, userDto, ServiceCodeConstant.SERVICE_CODE_USER_LOGIN, UserDto.class);
        if (userDto == null) {
@@ -206,6 +212,16 @@
        //获取 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);
        ResponseEntity<String> userinfo_paramOut = outRestTemplate.getForEntity(userinfo_url, String.class);
        logger.debug("调用微信换去openId ", userinfo_paramOut);
        if (userinfo_paramOut.getStatusCode() != HttpStatus.OK) {
            return ResultVo.redirectPage("/");
        }
        JSONObject userinfo_paramObj = JSONObject.parseObject(userinfo_paramOut.getBody());
        int loginFlag = paramIn.getInteger("loginFlag");
@@ -214,10 +230,12 @@
            //将openId放到redis 缓存,给前段下发临时票据
            String code = UUID.randomUUID().toString();
            CommonCache.setValue(code, openId, expireTime);
            if(errorUrl.indexOf("?")> 0){
                errorUrl +=("&code=" + code);
            }else{
                errorUrl +=("?code=" + code);
            CommonCache.setValue(code+"-nickname",  userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code+"-headimgurl",  userinfo_paramObj.getString("headimgurl"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
                errorUrl += ("?code=" + code);
            }
            return ResultVo.redirectPage(errorUrl);
        }
@@ -234,12 +252,14 @@
            //将openId放到redis 缓存,给前段下发临时票据
            String code = UUID.randomUUID().toString();
            CommonCache.setValue(code, openId, expireTime);
            if(errorUrl.indexOf("?")> 0){
                errorUrl +=("&code=" + code);
            }else{
                errorUrl +=("?code=" + code);
            CommonCache.setValue(code+"-nickname",  userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code+"-headimgurl",  userinfo_paramObj.getString("headimgurl"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
                errorUrl += ("?code=" + code);
            }
            return ResultVo.redirectPage(errorUrl );
            return ResultVo.redirectPage(errorUrl);
        }
        // String accessToken = paramObj.getString("access_token");//暂时不用
@@ -261,14 +281,24 @@
        if (StringUtil.isEmpty(tmpUserDto.getKey())) {
            String code = UUID.randomUUID().toString();
            CommonCache.setValue(code, openId, expireTime);
            if(errorUrl.indexOf("?")> 0){
                errorUrl +=("&code=" + code);
            }else{
                errorUrl +=("?code=" + code);
            CommonCache.setValue(code+"-nickname",  userinfo_paramObj.getString("nickname"), expireTime);
            CommonCache.setValue(code+"-headimgurl",  userinfo_paramObj.getString("headimgurl"), expireTime);
            if (errorUrl.indexOf("?") > 0) {
                errorUrl += ("&code=" + code);
            } else {
                errorUrl += ("?code=" + code);
            }
            return ResultVo.redirectPage(errorUrl);
        }
        redirectUrl = redirectUrl + (redirectUrl.indexOf("?") > 0 ? "&key=" + tmpUserDto.getKey() : "?key=" + tmpUserDto.getKey());
        //如果参数中有key 直接用新的覆盖
        Map tempRedirectParam = super.urlToMap(redirectUrl);
        tempRedirectParam.put("key", tmpUserDto.getKey());
        if (redirectUrl.indexOf("?") > -1) {
            redirectUrl = redirectUrl.substring(0, redirectUrl.indexOf("?")) + super.mapToUrlParam(tempRedirectParam);
        } else {
            redirectUrl = redirectUrl + super.mapToUrlParam(tempRedirectParam);
        }
        //redirectUrl = redirectUrl + (redirectUrl.indexOf("?") > 0 ? "&key=" + tmpUserDto.getKey() : "?key=" + tmpUserDto.getKey());
        return ResultVo.redirectPage(redirectUrl);
    }
@@ -321,7 +351,7 @@
            openUrl = WechatConstant.OPEN_AUTH
                    .replace("APPID", smallWeChatDto.getAppId())
                    .replace("SCOPE", "snsapi_base")
                    .replace("SCOPE", "snsapi_userinfo")
                    .replace(
                            "REDIRECT_URL",
                            URLEncoder
@@ -365,6 +395,8 @@
        String code = paramIn.getString("code");
        String openId = CommonCache.getValue(code);
        String nickname = CommonCache.getValue(code+"-nickname");
        String headimgurl = CommonCache.getValue(code+"-headimgurl");
        if (StringUtil.isEmpty(openId)) {
            responseEntity = new ResponseEntity<>("页面失效,请刷新后重试", HttpStatus.UNAUTHORIZED);
@@ -381,6 +413,8 @@
        JSONObject userOwnerInfo = new JSONObject();
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setOpenId(openId);
        ownerAppUserDto.setNickName(nickname);
        ownerAppUserDto.setHeadImgUrl(headimgurl);
        ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
        if (curOwnerApp != null) {
            ownerAppUserDto.setAppUserId(curOwnerApp.getAppUserId());