| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private final static int expireTime = 7200; |
| | | |
| | | private final static int LOGIN_PAGE = 1; |
| | | private final static int COMMON_PAGE = 2; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | |
| | | 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); |
| | |
| | | //处理昵称有特殊符号导致 入库失败问题 |
| | | 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 之类 |
| | |
| | | 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 是否绑定了业主 |
| | |
| | | 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 { |
| | |
| | | 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 { |
| | |
| | | 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); |
| | |
| | | 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); |