|
@ -1,10 +1,14 @@
|
|
|
package com.yihu.jw.security.core.userdetails.jdbc;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.security.core.userdetails.SaltUser;
|
|
|
import com.yihu.jw.security.model.WlyyUserDetails;
|
|
|
import com.yihu.jw.security.model.WlyyUserSimple;
|
|
|
import com.yihu.jw.util.http.HttpClientKit;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
@ -16,6 +20,8 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
import org.springframework.security.oauth2.provider.ClientDetails;
|
|
|
import org.springframework.security.oauth2.provider.ClientDetailsService;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
@ -36,6 +42,13 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
private static final String DEFAULT_DOCTOR_DETAILS_STATEMENT = "SELECT * FROM base_doctor d WHERE d.mobile = ? OR d.idcard = ?";
|
|
|
|
|
|
private static final String DEFAULT_PATIENT_DETAILS_STATEMENT = "SELECT * FROM base_patient p WHERE p.mobile = ? OR p.idcard = ?";
|
|
|
private static final String DEFAULT_PATIENT_DETAILS_ID_STATEMENT = "SELECT * FROM base_patient p WHERE p.id = ? ";
|
|
|
|
|
|
private static final String DEFAULT_PATIENT_INSERT_STATEMENT =
|
|
|
"INSERT into base_patient (`id`,`ihealth_openid`,`ihealth_openid_time`,`idcard`,`password`,`salt`,`name`,`birthday`,`sex`,`mobile`," +
|
|
|
"`province_code`,`province_name`,`city_code`,`city_name`,`town_code`,`town_name`,`street_code`,`street_name`,`address`," +
|
|
|
"`del`,`locked`,`enabled`,`login_failure_count`,`login_date`) " +
|
|
|
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
|
private static final String BespeakRegist = "bespeakRegist:";
|
|
|
|
|
@ -48,6 +61,13 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
@Value("${user.tryLoginTimes}")
|
|
|
private Integer tryLoginTimes;//失败重试次数
|
|
|
|
|
|
@Value("${iHealth.user-info-uri}")
|
|
|
private String iHealthUserInfoUrl;//失败重试次数
|
|
|
|
|
|
@Autowired
|
|
|
private ClientDetailsService clientDetailsService;
|
|
|
|
|
|
|
|
|
public WlyyUserDetailsService(DataSource dataSource) {
|
|
|
this.setDataSource(dataSource);
|
|
|
}
|
|
@ -56,6 +76,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
* 用户登录判读接口
|
|
|
* 判断loginType查找用户信息
|
|
|
* 用户类型 1或默认为user,2:医生登录,3:患者登录
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
* @throws UsernameNotFoundException
|
|
@ -80,61 +101,128 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
}
|
|
|
|
|
|
|
|
|
public void unlocked(String username){
|
|
|
public void unlocked(String username) {
|
|
|
String loginType = getLogintype();
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){ //1或默认查找user表,为平台管理员账号
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号
|
|
|
//解除锁定
|
|
|
this.getJdbcTemplate().update("update base_user u set login_failure_count = 0, u.locked = 0 where u.username = ? or u.mobile = ? or u.idcard = ?", username, username, username);
|
|
|
}else if("2".equals(loginType)){//2.为医生账号
|
|
|
} else if ("2".equals(loginType)) {//2.为医生账号
|
|
|
//解除锁定
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = 0, d.locked = 0 where d.mobile = ? or d.idcard = ?",username, username);
|
|
|
}else if("3".equals(loginType)){ //3.患者账号
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = 0, d.locked = 0 where d.mobile = ? or d.idcard = ?", username, username);
|
|
|
} else if ("3".equals(loginType)) { //3.患者账号
|
|
|
//解除锁定
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 5, p.locked = 0 where p.mobile = ? or p.idcard = ?",username, username);
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 5, p.locked = 0 where p.mobile = ? or p.idcard = ?", username, username);
|
|
|
} //...
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户登录判读接口
|
|
|
* 判断loginType查找用户信息
|
|
|
* 用户类型 1或默认为user,2:医生登录,3:患者登录
|
|
|
* 用户类型 1或默认为user,2:医生登录,3:患者登录,4:i健康系统-患者登录(i健康患者可以不注册直接登录互联网系统,首次使用,根据i健康居民code去i健康查询居民信息,然后保存到base.base_patient)
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WlyyUserDetails> getWlyyUserDetails(String username){
|
|
|
public List<WlyyUserDetails> getWlyyUserDetails(String username) {
|
|
|
|
|
|
String loginType = getLogintype();
|
|
|
|
|
|
List<WlyyUserDetails> users = null;
|
|
|
//1或默认查找user表,为平台管理员账号
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) {
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_USER_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username, username);
|
|
|
//2.为医生登录账号
|
|
|
}else if("2".equals(loginType)){
|
|
|
} else if ("2".equals(loginType)) {
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_DOCTOR_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username);
|
|
|
//3.患者登录
|
|
|
}else if("3".equals(loginType)){
|
|
|
} else if ("3".equals(loginType)) {
|
|
|
//查找是否存在预注册 用户
|
|
|
String userName = redisTemplate.opsForValue().get(BespeakRegist + username);
|
|
|
if(StringUtils.isNotBlank(userName)){
|
|
|
if (StringUtils.isNotBlank(userName)) {
|
|
|
//保存到数据库
|
|
|
this.getJdbcTemplate().execute("update base_patient set del=1 where mobile='"+username+"'");
|
|
|
this.getJdbcTemplate().execute("update base_patient set del=1 where mobile='" + username + "'");
|
|
|
redisTemplate.opsForValue().get(BespeakRegist + username);
|
|
|
redisTemplate.delete(BespeakRegist+username);
|
|
|
redisTemplate.delete(BespeakRegist + username);
|
|
|
}
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username);
|
|
|
}//..
|
|
|
// 去i健康查询用户
|
|
|
}else if("4".equals(loginType)){
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_ID_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username);
|
|
|
|
|
|
if ((null == users || users.size() == 0) && "4".equals(loginType)) {
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("clientId", getClientId()));
|
|
|
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(getClientId());
|
|
|
params.add(new BasicNameValuePair("clientSecret", clientDetails.getClientSecret()));
|
|
|
params.add(new BasicNameValuePair("code", username));
|
|
|
params.add(new BasicNameValuePair("openid", getOpenid()));
|
|
|
String res = HttpClientKit.post(iHealthUserInfoUrl, params, "UTF-8");
|
|
|
JSONObject patient = JSONObject.parseObject(res);
|
|
|
if(patient.getInteger("status") == -1){
|
|
|
logger.error("去i健康查询用户信息失败:" + patient.getString("error"));
|
|
|
return users;
|
|
|
}
|
|
|
try {
|
|
|
this.getJdbcTemplate().update(DEFAULT_PATIENT_INSERT_STATEMENT,
|
|
|
new Object[]{patient.getString("code"),
|
|
|
patient.getString("openid"),
|
|
|
new Date(),
|
|
|
patient.getString("idcard"),
|
|
|
patient.getString("password"),
|
|
|
patient.getString("salt"),
|
|
|
patient.getString("name"),
|
|
|
patient.getDate("birthday"),
|
|
|
patient.getInteger("sex"),
|
|
|
patient.getString("mobile"),
|
|
|
patient.getString("province"),
|
|
|
patient.getString("provinceName"),
|
|
|
patient.getString("city"),
|
|
|
patient.getString("cityName"),
|
|
|
patient.getString("town"),
|
|
|
patient.getString("townName"),
|
|
|
patient.getString("street"),
|
|
|
patient.getString("streetName"),
|
|
|
patient.getString("address"),
|
|
|
1,
|
|
|
0,
|
|
|
1,
|
|
|
0,
|
|
|
new Date()
|
|
|
}
|
|
|
);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
WlyyUserDetails user = new WlyyUserDetails();
|
|
|
user.setName(patient.getString("name"));
|
|
|
user.setPassword(patient.getString("password"));
|
|
|
if(patient.getInteger("sex") == 1){
|
|
|
user.setGender(WlyyUserDetails.Gender.male);
|
|
|
}else if(patient.getInteger("sex") == 2){
|
|
|
user.setGender(WlyyUserDetails.Gender.female);
|
|
|
}
|
|
|
user.setId(username);
|
|
|
user.setIdcard(patient.getString("idcard"));
|
|
|
user.setMobile(patient.getString("mobile"));
|
|
|
user.setEnabled(true);
|
|
|
user.setLocked(false);
|
|
|
user.setLockedDate(null);
|
|
|
users.add(user);
|
|
|
}
|
|
|
}
|
|
|
return users;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置用户登录时间,返回登录信息
|
|
|
* 判断loginType,用户类型 1或默认为user,2:医生登录,3:患者登录
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
* @throws UsernameNotFoundException
|
|
|
*/
|
|
|
public WlyyUserSimple authSuccess (String username) throws UsernameNotFoundException {
|
|
|
public WlyyUserSimple authSuccess(String username) throws UsernameNotFoundException {
|
|
|
//加载用户简略信息
|
|
|
List<WlyyUserSimple> users = getWlyyUserSimple(username);
|
|
|
if (users == null || users.size() == 0) {
|
|
@ -143,16 +231,16 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
return users.get(0);
|
|
|
}
|
|
|
|
|
|
public String authFailure () throws UsernameNotFoundException {
|
|
|
public String authFailure() throws UsernameNotFoundException {
|
|
|
//获取失败次数
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
String username = request.getParameter("username");
|
|
|
Map<String,Object> map = getLoginFailureCount(username);
|
|
|
Integer loginFailureCount = Integer.valueOf(map.get("login_failure_count").toString());
|
|
|
Map<String, Object> map = getLoginFailureCount(username);
|
|
|
Integer loginFailureCount = null == map.get("login_failure_count") ? 0 : Integer.valueOf(map.get("login_failure_count").toString());
|
|
|
Object timeObj = map.get("last_login_failure_time");
|
|
|
if(timeObj == null){
|
|
|
if (timeObj == null) {
|
|
|
loginFailureCount = 0;
|
|
|
}else{
|
|
|
} else {
|
|
|
Timestamp timestamp = (Timestamp) timeObj;
|
|
|
//判断是否得重置登陆次数
|
|
|
Date date = new Date(timestamp.getTime());
|
|
@ -161,49 +249,50 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
loginFailureCount = 0;
|
|
|
}
|
|
|
}
|
|
|
loginFailureCount ++;
|
|
|
loginFailureCount++;
|
|
|
if (loginFailureCount >= tryLoginTimes) {
|
|
|
locked(username);
|
|
|
return "账号已被锁定,请"+autoUnlockTime+"分钟后重试!";
|
|
|
return "账号已被锁定,请" + autoUnlockTime + "分钟后重试!";
|
|
|
} else {
|
|
|
addFailureCount(username,loginFailureCount);
|
|
|
addFailureCount(username, loginFailureCount);
|
|
|
return "账号或密码错误,还可以再试" + (tryLoginTimes - loginFailureCount) + "次!";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取失败次数 返回 map key1: login_failure_count 失败次数
|
|
|
* key2: last_login_failure_time 上次登录失败时间 /可能为null
|
|
|
* key2: last_login_failure_time 上次登录失败时间 /可能为null
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Object> getLoginFailureCount(String username){
|
|
|
public Map<String, Object> getLoginFailureCount(String username) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
String loginType = getLogintype();
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){ //1或默认查找user表,为平台管理员账号
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号
|
|
|
result = this.getJdbcTemplate().queryForMap("select u.login_failure_count,u.last_login_failure_time from base_user u where u.username = ? or u.mobile = ? or u.idcard = ?", username, username, username);
|
|
|
}else if("2".equals(loginType)){//2.为医生账号
|
|
|
} else if ("2".equals(loginType)) {//2.为医生账号
|
|
|
result = this.getJdbcTemplate().queryForMap("select d.login_failure_count,d.last_login_failure_time from base_doctor d where d.mobile = ? or d.idcard = ?", username, username);
|
|
|
}else if("3".equals(loginType)){ //3.患者账号
|
|
|
result = this.getJdbcTemplate().queryForMap("select p.login_failure_count,p.last_login_failure_time from base_patient p where p.mobile = ? or p.idcard = ?",username, username);
|
|
|
} else if ("3".equals(loginType)) { //3.患者账号
|
|
|
result = this.getJdbcTemplate().queryForMap("select p.login_failure_count,p.last_login_failure_time from base_patient p where p.mobile = ? or p.idcard = ?", username, username);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 锁定账号
|
|
|
*
|
|
|
* @param username
|
|
|
*/
|
|
|
public void locked(String username){
|
|
|
public void locked(String username) {
|
|
|
String loginType = getLogintype();
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){ //1或默认查找user表,为平台管理员账号
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号
|
|
|
//账号锁定
|
|
|
this.getJdbcTemplate().update("update base_user u set u.login_failure_count = 5, u.locked = 1, u.locked_date = ? where u.username = ? or u.mobile = ? or u.idcard = ?", new Date(), username, username, username);
|
|
|
}else if("2".equals(loginType)){//2.为医生账号
|
|
|
} else if ("2".equals(loginType)) {//2.为医生账号
|
|
|
//账号锁定
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = 5, d.locked = 1, d.locked_date = ? where d.mobile = ? or d.idcard = ?", new Date(), username, username);
|
|
|
}else if("3".equals(loginType)){ //3.患者账号
|
|
|
} else if ("3".equals(loginType)) { //3.患者账号
|
|
|
//账号锁定
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 5, p.locked = 1, p.locked_date = ? where p.mobile = ? or p.idcard = ?", new Date(), username, username);
|
|
|
} //...
|
|
@ -211,20 +300,21 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
|
|
|
/**
|
|
|
* 更新登录失败次数
|
|
|
*
|
|
|
* @param username
|
|
|
* @param loginFailureCount
|
|
|
*/
|
|
|
public void addFailureCount(String username,Integer loginFailureCount){
|
|
|
public void addFailureCount(String username, Integer loginFailureCount) {
|
|
|
String loginType = getLogintype();
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){ //1或默认查找user表,为平台管理员账号
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号
|
|
|
//更新失败次数
|
|
|
this.getJdbcTemplate().update("update base_user u set u.login_failure_count = ? ,u.last_login_failure_time = ? where u.username = ? or u.mobile = ? or u.idcard = ?", loginFailureCount,new Date(), username, username, username);
|
|
|
}else if("2".equals(loginType)){//2.为医生账号
|
|
|
this.getJdbcTemplate().update("update base_user u set u.login_failure_count = ? ,u.last_login_failure_time = ? where u.username = ? or u.mobile = ? or u.idcard = ?", loginFailureCount, new Date(), username, username, username);
|
|
|
} else if ("2".equals(loginType)) {//2.为医生账号
|
|
|
//更新失败次数
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = ?, d.last_login_failure_time = ? where d.mobile = ? or d.idcard = ?", loginFailureCount,new Date(), username, username);
|
|
|
}else if("3".equals(loginType)){ //3.患者账号
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = ?, d.last_login_failure_time = ? where d.mobile = ? or d.idcard = ?", loginFailureCount, new Date(), username, username);
|
|
|
} else if ("3".equals(loginType)) { //3.患者账号
|
|
|
//更新失败次数
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = ? ,p.last_login_failure_time = ? where p.mobile = ? or p.idcard = ?", loginFailureCount,new Date(),username, username);
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = ? ,p.last_login_failure_time = ? where p.mobile = ? or p.idcard = ?", loginFailureCount, new Date(), username, username);
|
|
|
} //...
|
|
|
}
|
|
|
|
|
@ -237,40 +327,46 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
/**
|
|
|
* 设置用户登录时间,返回登录信息
|
|
|
* 判断loginType,用户类型 1或默认为user,2:医生登录,3:患者登录
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WlyyUserSimple> getWlyyUserSimple(String username){
|
|
|
public List<WlyyUserSimple> getWlyyUserSimple(String username) {
|
|
|
|
|
|
String loginType = getLogintype();
|
|
|
|
|
|
List<WlyyUserSimple> users = null;
|
|
|
|
|
|
//1或默认查找user表,为平台管理员账号
|
|
|
if(StringUtils.isBlank(loginType)||"1".equals(loginType)){
|
|
|
if (StringUtils.isBlank(loginType) || "1".equals(loginType)) {
|
|
|
//更新登录时间
|
|
|
this.getJdbcTemplate().update("update base_user u set u.login_failure_count = 0, u.login_date = ? where u.username = ? or u.mobile = ? or u.idcard = ?", new Date(), username, username, username);
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_USER_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), username, username, username);
|
|
|
//2.为医生登录账号
|
|
|
}else if("2".equals(loginType)){
|
|
|
} else if ("2".equals(loginType)) {
|
|
|
//更新登录时间
|
|
|
this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = 0, d.login_date = ? where d.mobile = ? or d.idcard = ?", new Date(), username, username);
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_DOCTOR_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), username, username);
|
|
|
//3.患者登录
|
|
|
}else if("3".equals(loginType)){
|
|
|
} else if ("3".equals(loginType)) {
|
|
|
//更新登录时间
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 0, p.login_date = ? where p.mobile = ? or p.idcard = ?", new Date(), username, username);
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), username, username);
|
|
|
} //...
|
|
|
} else if("4".equals(loginType)){
|
|
|
//更新登录时间
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 0, p.login_date = ? where p.mobile = ? or p.idcard = ?", new Date(), username, username);
|
|
|
users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_ID_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), username);
|
|
|
}
|
|
|
|
|
|
return users;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取用户登录类型
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String getLogintype(){
|
|
|
public String getLogintype() {
|
|
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
|
@ -279,26 +375,54 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
|
|
|
return loginType;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取i健康用户登录openid型
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String getOpenid() {
|
|
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
|
|
String openid = request.getParameter("openid");
|
|
|
|
|
|
return openid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取i健康用户登录openid型
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String getClientId() {
|
|
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
|
|
public boolean setRolePhth(String loginType, OAuth2AccessToken token, String id, StringRedisTemplate redisTemplate){
|
|
|
String clientId = request.getParameter("client_id");
|
|
|
|
|
|
if(org.apache.commons.lang.StringUtils.isBlank(loginType)||"1".equals(loginType)){ //1或默认查找user表,为平台管理员账号
|
|
|
String key = "wlyy2:auth:token:"+token.getValue();
|
|
|
redisTemplate.opsForValue().set(key,"/**");
|
|
|
redisTemplate.expire(key,token.getExpiresIn(), TimeUnit.SECONDS);
|
|
|
}else if("2".equals(loginType)){//2.为医生账号
|
|
|
return clientId;
|
|
|
}
|
|
|
|
|
|
|
|
|
public boolean setRolePhth(String loginType, OAuth2AccessToken token, String id, StringRedisTemplate redisTemplate) {
|
|
|
|
|
|
}else if("3".equals(loginType)){ //3.患者账号
|
|
|
String key = "wlyy2:auth:token:"+token.getValue();
|
|
|
redisTemplate.opsForValue().set(key,"/**");
|
|
|
redisTemplate.expire(key,token.getExpiresIn(), TimeUnit.SECONDS);
|
|
|
}else{
|
|
|
if (org.apache.commons.lang.StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号
|
|
|
String key = "wlyy2:auth:token:" + token.getValue();
|
|
|
redisTemplate.opsForValue().set(key, "/**");
|
|
|
redisTemplate.expire(key, token.getExpiresIn(), TimeUnit.SECONDS);
|
|
|
} else if ("2".equals(loginType)) {//2.为医生账号
|
|
|
|
|
|
} else if ("3".equals(loginType) || "4".equals(loginType)) { //3.患者账号
|
|
|
String key = "wlyy2:auth:token:" + token.getValue();
|
|
|
redisTemplate.opsForValue().set(key, "/**");
|
|
|
redisTemplate.expire(key, token.getExpiresIn(), TimeUnit.SECONDS);
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public void updateOpenId(String openid,String userId){
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.openid = ? where p.id= ?",openid ,userId);
|
|
|
public void updateOpenId(String openid, String userId) {
|
|
|
this.getJdbcTemplate().update("update base_patient p set p.openid = ? where p.id= ?", openid, userId);
|
|
|
}
|
|
|
}
|