|
@ -34,6 +34,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.el.lang.ELArithmetic;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -527,6 +528,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
String username = parameters.get("username");
|
|
|
String type = parameters.get("type");
|
|
|
String isDoctor = parameters.get("isDoctor");
|
|
|
String msg="";
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
|
throw new InvalidRequestException("client_id");
|
|
|
}
|
|
@ -568,13 +570,42 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
String captcha = wlyyRedisVerifyCodeService.getCodeNumber();
|
|
|
ResultMsg result= null;
|
|
|
if(StringUtils.isEmpty(type)){
|
|
|
result = ykyySMSService.ykyySendSMS(username,"您好,您的手机登录短信验证码是:"+captcha+",5分钟内有效。");
|
|
|
String res = ykyyService.getShortMessage("1",username);
|
|
|
String resltCode ="";
|
|
|
String captcha1 = "";
|
|
|
if (!StringUtils.isEmpty(res)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
if ("10000".equalsIgnoreCase(jsonObject.getString("code"))){
|
|
|
captcha1 = jsonObject.getString("value");
|
|
|
resltCode = jsonObject.getString("code");
|
|
|
}else if("199".equalsIgnoreCase(jsonObject.getString("code"))){
|
|
|
msg = jsonObject.getString("msg");
|
|
|
Oauth2Envelop<Captcha> oauth2Envelop = new Oauth2Envelop<>(msg, 199);
|
|
|
return new ResponseEntity<>(oauth2Envelop, HttpStatus.OK);
|
|
|
}else {
|
|
|
msg="发送失败";
|
|
|
Oauth2Envelop<Captcha> oauth2Envelop = new Oauth2Envelop<>(msg, -1);
|
|
|
return new ResponseEntity<>(oauth2Envelop, HttpStatus.OK);
|
|
|
}
|
|
|
}
|
|
|
if ("10000".equalsIgnoreCase(resltCode)) {
|
|
|
|
|
|
Captcha _captcha = new Captcha();
|
|
|
_captcha.setCode(captcha1);
|
|
|
_captcha.setExpiresIn(300);
|
|
|
wlyyRedisVerifyCodeService.store(client_id, username, captcha1, 300);
|
|
|
|
|
|
Oauth2Envelop<Captcha> oauth2Envelop = new Oauth2Envelop<>("captcha", 200, _captcha);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.set("Cache-Control", "no-store");
|
|
|
headers.set("Pragma", "no-cache");
|
|
|
return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
|
|
|
}
|
|
|
}else if("1".equals(type)){
|
|
|
result = ykyySMSService.ykyySendSMS(username,"您好,您的手机登录短信验证码是:"+captcha+",5分钟内有效。");
|
|
|
}else if("2".equals(type)) {
|
|
|
result = ykyySMSService.ykyySendSMS(username, "您好,您正在进行找回密码操作,您的短信验证码是:" + captcha + ",请勿将验证码告诉他人,5分钟内有效。");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (result.isSuccess()) {
|
|
|
Captcha _captcha = new Captcha();
|
|
|
_captcha.setCode(captcha);
|
|
@ -587,10 +618,10 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
headers.set("Pragma", "no-cache");
|
|
|
return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
|
|
|
}
|
|
|
throw new IllegalStateException("验证码发送失败!");
|
|
|
Oauth2Envelop<Captcha> oauth2Envelop = new Oauth2Envelop<>(msg, 200);
|
|
|
return new ResponseEntity<>(oauth2Envelop, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -1326,7 +1357,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/oauth/registerPatientAndLogin", method = RequestMethod.POST)
|
|
|
/*@RequestMapping(value = "/oauth/registerPatientAndLogin", method = RequestMethod.POST)
|
|
|
public ObjEnvelop registerPatientAndLogin(String name, String mobile, String idcard, String ssc, String pw,String client_id,String login_type,String captcha,String openid,String wxId)throws Exception{
|
|
|
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
@ -1389,6 +1420,96 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
|
|
|
return ObjEnvelop.getSuccess("success",wlyyUserSimple);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return ObjEnvelop.getError("登录失败!");
|
|
|
}*/
|
|
|
@RequestMapping(value = "/oauth/registerPatientAndLogin", method = RequestMethod.POST)
|
|
|
public ObjEnvelop registerPatientAndLogin(String name, String mobile, String idcard, String ssc, String pw,String client_id,String login_type,String captcha,String openid,String wxId)throws Exception{
|
|
|
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
|
throw new InvalidRequestException("client_id is null");
|
|
|
}
|
|
|
|
|
|
if (wlyyRedisVerifyCodeService.verification(client_id, mobile, captcha)) {
|
|
|
//验证码正确
|
|
|
} else {
|
|
|
return ObjEnvelop.getError("验证码错误!");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
List<BasePatientDO> basePatientDOS =basePatientDao.findByMobileAndDel(mobile,"1");
|
|
|
boolean localFlag = false;
|
|
|
boolean ykFlag = false;
|
|
|
String msg = "";
|
|
|
if (null!=basePatientDOS&&basePatientDOS.size()>0){
|
|
|
localFlag = true;
|
|
|
|
|
|
}
|
|
|
BasePatientDO basePatientDO = new BasePatientDO();
|
|
|
String r =ykyyService.getRegisterUser(mobile,pw,captcha,"a01522","xmijk","xmijk");
|
|
|
if (!StringUtils.isEmpty(r)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(r);
|
|
|
if (null!=jsonObject.get("code")&&"200".equalsIgnoreCase(jsonObject.get("code").toString())){
|
|
|
JSONObject jsonObject1 = JSONObject.parseObject(jsonObject.get("data").toString());
|
|
|
basePatientDO.setYktId(jsonObject1.getString("ID"));
|
|
|
}else if (null!=jsonObject.get("code")&&"199".equalsIgnoreCase(jsonObject.get("code").toString())){
|
|
|
msg = jsonObject.getString("msg");
|
|
|
ykFlag = true;
|
|
|
}
|
|
|
}
|
|
|
basePatientDO.setMobile(mobile);
|
|
|
String salt = UUID.randomUUID().toString().substring(0,5);
|
|
|
basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
|
|
|
basePatientDO.setSalt(salt);
|
|
|
basePatientDO.setDel("1");
|
|
|
basePatientDO.setEnabled(1);
|
|
|
basePatientDO.setLocked(0);
|
|
|
basePatientDO.setCreateTime(new Date());
|
|
|
basePatientDO.setUpdateTime(new Date());
|
|
|
|
|
|
BasePatientDO patientDO = basePatientDao.save(basePatientDO);
|
|
|
if (localFlag&&ykFlag){
|
|
|
return ObjEnvelop.getError("该手机号已经注册过");
|
|
|
}
|
|
|
|
|
|
ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
|
|
|
|
|
|
Map<String, String> parameters = new HashedMap();
|
|
|
|
|
|
parameters.put("username",patientDO.getMobile());
|
|
|
parameters.put("grant_type", "ihealthCode");
|
|
|
|
|
|
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());
|
|
|
}
|
|
|
|
|
|
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"));
|
|
|
String loginType = parameters.get("login_type");
|
|
|
|
|
|
BaseLoginLogDO baseLoginLogDO = new BaseLoginLogDO();
|
|
|
userDetailsService.setRolePhth(loginType, token, wlyyUserSimple.getId(), redisTemplate);
|
|
|
|
|
|
baseLoginLogDO.setUserId(wlyyUserSimple.getId());
|
|
|
baseLoginLogDO.setCreateTime(new Date());
|
|
|
String userAgent = JSONObject.toJSONString(wlyyUserSimple);
|
|
|
baseLoginLogDO.setUserAgent(userAgent);
|
|
|
baseLoginLogDO.setLoginType(loginType);
|
|
|
baseLoginLogService.save(baseLoginLogDO);
|
|
|
|
|
|
return ObjEnvelop.getSuccess("success",wlyyUserSimple);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|