| | |
| | | |
| | | private final static int expireTime = 7200; |
| | | |
| | | private final static int LOGIN_PAGE = 1; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | |
| | | JSONObject loginInfo = JSONObject.parseObject(pd.getReqData()); |
| | | |
| | | loginInfo.put("passwd", AuthenticationFactory.passwdMd5(loginInfo.getString("password"))); |
| | | responseEntity = this.callCenterService(restTemplate, pd, loginInfo.toJSONString(), ServiceConstant.SERVICE_API_URL + "/api/user.service.login", HttpMethod.POST); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserName(loginInfo.getString("username")); |
| | | userDto.setPassword(loginInfo.getString("password")); |
| | | userDto = super.postForApi(pd,userDto,ServiceCodeConstant.SERVICE_CODE_USER_LOGIN,UserDto.class); |
| | | |
| | | if(userDto == null){ |
| | | responseEntity = new ResponseEntity<>("用户名或密码错误", HttpStatus.BAD_REQUEST); |
| | | return responseEntity; |
| | | } |
| | | |
| | | JSONObject userInfo = JSONObject.parseObject(responseEntity.getBody()); |
| | | |
| | | //根据用户查询商户信息 |
| | | String userId = userInfo.getString("userId"); |
| | | String userId = userDto.getUserId(); |
| | | |
| | | pd = PageData.newInstance().builder(userId, "", "", pd.getReqData(), |
| | | "", "", "", "", |
| | |
| | | JSONObject paramOut = new JSONObject(); |
| | | paramOut.put("result", 0); |
| | | paramOut.put("owner", appUser); |
| | | paramOut.put("token", userInfo.getString("token")); |
| | | paramOut.put("token", userDto.getToken()); |
| | | |
| | | userDto = new UserDto(); |
| | | userDto.setUserId(ownerAppUserDtos.get(0).getUserId()); |
| | | UserDto tmpUserDto = super.getForApi(pd, userDto, ServiceCodeConstant.QUERY_USER_SECRET, UserDto.class); |
| | | paramOut.put("key", tmpUserDto.getKey()); |
| | | |
| | | String appId = pd.getAppId(); |
| | | |
| | |
| | | |
| | | //获取 openId |
| | | String openId = paramObj.getString("openid"); |
| | | //判断当前openId 是否绑定了业主 |
| | | |
| | | int loginFlag = paramIn.getInteger("loginFlag"); |
| | | //说明是登录页面,下发code 就可以,不需要下发key 之类 |
| | | if(loginFlag == LOGIN_PAGE){ |
| | | //将openId放到redis 缓存,给前段下发临时票据 |
| | | String code = UUID.randomUUID().toString(); |
| | | CommonCache.setValue(code, openId, expireTime); |
| | | return ResultVo.redirectPage(errorUrl + "?code=" + code); |
| | | } |
| | | |
| | | //判断当前openId 是否绑定了业主 |
| | | pd = PageData.newInstance().builder("-1", "", "", pd.getReqData(), |
| | | "", "", "", "", |
| | | pd.getAppId()); |
| | |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserId(ownerAppUserDtos.get(0).getUserId()); |
| | | UserDto tmpUserDto = super.getForApi(pd, userDto, ServiceCodeConstant.QUERY_USER_SECRET, UserDto.class); |
| | | |
| | | if(StringUtil.isEmpty(tmpUserDto.getKey())){ |
| | | String code = UUID.randomUUID().toString(); |
| | | CommonCache.setValue(code, openId, expireTime); |
| | | return ResultVo.redirectPage(errorUrl + "?code=" + code); |
| | | } |
| | | redirectUrl = redirectUrl + (redirectUrl.indexOf("?") > 0 ? "&key=" + tmpUserDto.getKey() : "?key=" + tmpUserDto.getKey()); |
| | | return ResultVo.redirectPage(redirectUrl); |
| | | |
| | |
| | | @Override |
| | | public ResponseEntity<String> refreshToken(IPageData pd, String redirectUrl, |
| | | String errorUrl, |
| | | String loginFlag, |
| | | HttpServletRequest request, HttpServletResponse response) throws SMOException { |
| | | //分配urlCode |
| | | String urlCode = UUID.randomUUID().toString(); |
| | |
| | | URLEncoder |
| | | .encode( |
| | | (newUrl |
| | | + "/app/loginOwnerWechatAuth?appId=992020061452450002&urlCode=" + urlCode), |
| | | + "/app/loginOwnerWechatAuth?appId=992020061452450002&urlCode=" + urlCode+"&loginFlag="+loginFlag), |
| | | "UTF-8")).replace("STATE", "1"); |
| | | |
| | | } catch (Exception e) { |