|  | @ -166,9 +166,12 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
 | 
	
		
			
				|  |  |         wlyyUserSimple.setState(parameters.get("state"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String loginType = parameters.get("login_type");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String openid = parameters.get("openid");
 | 
	
		
			
				|  |  |         //更新患者openId
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(openid) && !"undefined".equalsIgnoreCase(openid) && "3".equalsIgnoreCase(loginType)){
 | 
	
		
			
				|  |  |             userDetailsService.updateOpenId(openid,wlyyUserSimple.getId());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return getResponse(wlyyUserSimple);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -372,6 +375,95 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
 | 
	
		
			
				|  |  |         return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 登陆
 | 
	
		
			
				|  |  |      * @param parameters
 | 
	
		
			
				|  |  |      * 不定入参:
 | 
	
		
			
				|  |  |      * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
 | 
	
		
			
				|  |  |      * mobile:手机号
 | 
	
		
			
				|  |  |      * captcha:验证码
 | 
	
		
			
				|  |  |      * clientId:
 | 
	
		
			
				|  |  |      * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
 | 
	
		
			
				|  |  |      * @param httpSession
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/oauth/registAndLogin", method = RequestMethod.POST)
 | 
	
		
			
				|  |  |     public ResponseEntity<Oauth2Envelop<WlyyUserSimple>> registAndLogin(@RequestParam Map<String, String> parameters, HttpSession httpSession) throws Exception {
 | 
	
		
			
				|  |  |         //用于标记是否注册成功
 | 
	
		
			
				|  |  |         boolean registFlag = false;
 | 
	
		
			
				|  |  |         String client_id = parameters.get("client_id");
 | 
	
		
			
				|  |  |         if (StringUtils.isEmpty(client_id)) {
 | 
	
		
			
				|  |  |             throw new InvalidRequestException("client_id is null");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String type = parameters.get("login_type");
 | 
	
		
			
				|  |  |         if (StringUtils.isEmpty(type)) {
 | 
	
		
			
				|  |  |             throw new InvalidRequestException("regist type is null");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //type :1居民  2:医生
 | 
	
		
			
				|  |  |         if("3".equals(type)){
 | 
	
		
			
				|  |  |             String mobile = parameters.get("mobile");
 | 
	
		
			
				|  |  |             String captcha = parameters.get("captcha");
 | 
	
		
			
				|  |  |             HttpHeaders reqHeaders = new HttpHeaders();
 | 
	
		
			
				|  |  |             MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
 | 
	
		
			
				|  |  |             params.add("mobile", mobile);
 | 
	
		
			
				|  |  |             params.add("captcha", captcha);
 | 
	
		
			
				|  |  |             params.add("openid", parameters.get("openid"));
 | 
	
		
			
				|  |  |             HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(params, reqHeaders);
 | 
	
		
			
				|  |  |             Map<String, Object> result = restTemplate.postForObject("http://svr-patient-111:10021/basePatient/regist", httpEntity, HashMap.class);//svr-patient
 | 
	
		
			
				|  |  |             Map<String,Object> obj = (Map<String, Object>) result.get("obj");
 | 
	
		
			
				|  |  |             if("1".equals(obj.get("code"))){
 | 
	
		
			
				|  |  |                 registFlag = true;
 | 
	
		
			
				|  |  |                 parameters.put("username",mobile);
 | 
	
		
			
				|  |  |                 wlyyRedisVerifyCodeService.store(client_id, mobile, captcha, 120);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 return getFailedResponse(obj.get("message").toString(),-1,null);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             return getFailedResponse("暂不提供其他类型人员注册",-1,null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(registFlag){
 | 
	
		
			
				|  |  |             parameters.put("grant_type", "captcha");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
 | 
	
		
			
				|  |  |             if (authenticatedClient != null) {
 | 
	
		
			
				|  |  |                 oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
 | 
	
		
			
				|  |  |             if (token == null) {
 | 
	
		
			
				|  |  |                 throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             /*如果是移动端登陆则移除之前的token,
 | 
	
		
			
				|  |  |             在网关处通过HTTP状态码告知前端是过期(402)还是账号在别处登陆(403),
 | 
	
		
			
				|  |  |             实现同一账号只能在一处登陆*/
 | 
	
		
			
				|  |  |             HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
 | 
	
		
			
				|  |  |             if (request.getHeader("login-device") != null && request.getHeader("login-device").equals("mobile")) {
 | 
	
		
			
				|  |  |                 tokenStore.removeAccessToken(token.getValue());
 | 
	
		
			
				|  |  |                 tokenStore.removeRefreshToken(token.getRefreshToken().getValue());
 | 
	
		
			
				|  |  |                 token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (token == null) {
 | 
	
		
			
				|  |  |                 throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username"));
 | 
	
		
			
				|  |  |             wlyyUserSimple.setAccessToken(token.getValue());
 | 
	
		
			
				|  |  |             wlyyUserSimple.setTokenType(token.getTokenType());
 | 
	
		
			
				|  |  |             wlyyUserSimple.setExpiresIn(token.getExpiresIn());
 | 
	
		
			
				|  |  |             wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue());
 | 
	
		
			
				|  |  |             wlyyUserSimple.setUser(parameters.get("username"));
 | 
	
		
			
				|  |  |             wlyyUserSimple.setState(parameters.get("state"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String loginType = parameters.get("login_type");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return getResponse(wlyyUserSimple);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     protected TokenGranter getTokenGranter() {
 | 
	
		
			
				|  |  |         return this.tokenGranter;
 | 
	
	
		
			
				|  | @ -392,6 +484,15 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
 | 
	
		
			
				|  |  |         return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private ResponseEntity<Oauth2Envelop<WlyyUserSimple>> getFailedResponse(String message ,int status,WlyyUserSimple ehrUserSimple) {
 | 
	
		
			
				|  |  |         HttpHeaders headers = new HttpHeaders();
 | 
	
		
			
				|  |  |         headers.set("Cache-Control", "no-store");
 | 
	
		
			
				|  |  |         headers.set("Pragma", "no-cache");
 | 
	
		
			
				|  |  |         Oauth2Envelop<WlyyUserSimple> oauth2Envelop = new Oauth2Envelop<>(message, status, ehrUserSimple);
 | 
	
		
			
				|  |  |         return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     protected WebResponseExceptionTranslator getExceptionTranslator() {
 | 
	
		
			
				|  |  |         return wlyyOAuth2ExceptionTranslator;
 |