提交 c37dd5a6 编写于 作者: xixian.wang@picahealth.com's avatar xixian.wang@picahealth.com

Merge branch 'dev-20200113-token' into 'release'

合并分支到release

user_token_tourist的处理

See merge request !23
流水线 #24548 已失败 于阶段
in 3 second
......@@ -29,6 +29,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Spring cloud dependencies begin-->
......
......@@ -171,6 +171,7 @@ public abstract class AccountBaseController extends BaseController {
accountUser.setLoginFrom(this.getSourceType());
accountUser.setLoginPlatform(this.getProductType());
accountUser.setLoginIp(super.getIpAddr());
accountUser.setUserTokenTourist(this.getUserTokenTourist());
return accountUser;
}
......@@ -216,4 +217,9 @@ public abstract class AccountBaseController extends BaseController {
}
return null;
}
public String getUserTokenTourist() {
HttpServletRequest request = super.getRequest();
return request.getHeader("user_token_tourist");
}
}
......@@ -69,6 +69,7 @@ public class LoginController extends AccountBaseController {
Integer sourceType = super.getSourceType();
request.setSourceType(sourceType);
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
AccountUtils.checkMobilePhone(request.getMobile());
AccountUtils.checkPassword(request.getPassword());
LoginResult login = loginService.login(request);
......@@ -95,6 +96,7 @@ public class LoginController extends AccountBaseController {
Integer sourceType = super.getSourceType();
request.setSourceType(sourceType);
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
LoginResult login = loginService.loginAndRegister(request);
if (SourceTypeEnum.SAAS.getCode().equals(sourceType)) {
login.setDoctorId("");
......@@ -111,6 +113,7 @@ public class LoginController extends AccountBaseController {
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
LoginResult result = loginService.loginByWeChat(request);
return PicaResponse.toResponse(result);
}
......@@ -122,6 +125,7 @@ public class LoginController extends AccountBaseController {
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
LoginResult result = loginService.loginByWeChatStep(request);
return PicaResponse.toResponse(result);
}
......@@ -137,7 +141,7 @@ public class LoginController extends AccountBaseController {
@PostMapping("/login/wechat/bind")
public PicaResponse bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
request.setUserTokenTourist(super.getUserTokenTourist());
Long result = cacheClient.setnx(cache_prifix + request.getWeChatCode(), request.getWeChatCode());
if (result == 1) {
try {
......@@ -187,7 +191,7 @@ public class LoginController extends AccountBaseController {
String newToken = tokenService.getToken(headersMap);
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, super.getProductType(), super.getSourceType(),
AccountTypeEnum.LOGIN_OUT.getCode(), super.getIpAddr(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(), AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),
newToken);
newToken,0,super.getUserTokenTourist());
picaLogUtils.info(entity);
return PicaResponse.toResponse(newToken);
} else {
......@@ -229,6 +233,7 @@ public class LoginController extends AccountBaseController {
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
return PicaResponse.toResponse(loginService.loginByApple(request));
}
......@@ -239,6 +244,7 @@ public class LoginController extends AccountBaseController {
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
return PicaResponse.toResponse(loginService.loginByAppleStep(request));
}
......@@ -250,6 +256,7 @@ public class LoginController extends AccountBaseController {
req.setProductType(super.getProductType());
req.setSourceType(super.getSourceType());
req.setLoginIp(super.getIpAddr());
req.setUserTokenTourist(super.getUserTokenTourist());
LoginResult oneClickLoginResultVo = loginService.oneClickLogin(req);
return PicaResponse.toResponse(oneClickLoginResultVo);
}
......
......@@ -50,6 +50,7 @@ public class RegisterController extends AccountBaseController {
Integer sourceType = super.getSourceType();
request.setSourceType(sourceType);
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
result = registerService.register(request);
if (sourceType==3){
result.setDoctorId("");
......
......@@ -15,6 +15,17 @@ public class AccountUser extends PicaUser {
//登录ip
private String loginIp;
//用户本地token
private String userTokenTourist;
public String getUserTokenTourist() {
return userTokenTourist;
}
public void setUserTokenTourist(String userTokenTourist) {
this.userTokenTourist = userTokenTourist;
}
public Integer getAcctId() {
return acctId;
}
......
......@@ -40,6 +40,26 @@ public class LogLoginEntity extends AccountLogEntity {
private String token;
private int isLogin;
private String userTokenTourist;
public int getIsLogin() {
return isLogin;
}
public void setIsLogin(int isLogin) {
this.isLogin = isLogin;
}
public String getUserTokenTourist() {
return userTokenTourist;
}
public void setUserTokenTourist(String userTokenTourist) {
this.userTokenTourist = userTokenTourist;
}
private QueryMobileEntity queryMobileEntity;
public QueryMobileEntity getQueryMobileEntity() {
......
......@@ -21,7 +21,7 @@ public class AccountLogEntityUtils {
* @return
*/
public static LogLoginEntity getLogLoginEntity(Integer acctId, Integer productType, Integer sourceType,
int code, String ipAddr, int code1, int code2,String token) {
int code, String ipAddr, int code1, int code2,String token,int isLogin,String userTokenTourist) {
LogLoginEntity entity = new LogLoginEntity();
Date currentTime = new Date();
entity.setAcctId(acctId);
......@@ -38,6 +38,8 @@ public class AccountLogEntityUtils {
entity.setLoginStatus(code1);
entity.setLogType(code2);
entity.setToken(token);
entity.setIsLogin(isLogin);
entity.setUserTokenTourist(userTokenTourist);
return entity;
}
......
......@@ -52,6 +52,16 @@ public class BaseRequest {
private Integer xPos;
@ApiModelProperty("h5端适配缩放后背景图实际宽度")
private Integer imageW;
@ApiModelProperty("用户本地token")
private String userTokenTourist;
public String getUserTokenTourist() {
return userTokenTourist;
}
public void setUserTokenTourist(String userTokenTourist) {
this.userTokenTourist = userTokenTourist;
}
public String getCaptchaToken() {
return captchaToken;
......
......@@ -15,6 +15,8 @@ public class OneClickLoginReq {
private Integer productType = 0;
private String userTokenTourist;
public String getLoginIp() {
return loginIp;
}
......@@ -46,4 +48,14 @@ public class OneClickLoginReq {
public void setSourceType(Integer sourceType) {
this.sourceType = sourceType;
}
public String getUserTokenTourist() {
return userTokenTourist;
}
public void setUserTokenTourist(String userTokenTourist) {
this.userTokenTourist = userTokenTourist;
}
}
package com.pica.cloud.account.account.server.service;
import ch.qos.logback.core.rolling.helper.IntegerTokenConverter;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
......
......@@ -248,660 +248,662 @@ public class LoginServiceImpl implements LoginService {
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (productType == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
result.setEntireFlag(doctorInfo.getEntireFlag());
}
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, sourceType,
AccountTypeEnum.LOGIN_PWD.getCode(), request.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken);
picaLogUtils.info(entity);
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, sourceType,
AccountTypeEnum.LOGIN_PWD.getCode(), request.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(), newToken, 1, request.getUserTokenTourist());
picaLogUtils.info(entity);
// 密码登录成功以后,清除错误次数记录
String pwdErrorNum = Constants.PWD_ERROR_NUM_KEY.replace("{mobile}", mobile);
if (redisClient.exists(pwdErrorNum)) {
redisClient.del(pwdErrorNum);
// 密码登录成功以后,清除错误次数记录
String pwdErrorNum = Constants.PWD_ERROR_NUM_KEY.replace("{mobile}", mobile);
if (redisClient.exists(pwdErrorNum)) {
redisClient.del(pwdErrorNum);
}
}
return result;
}
@Override
public LoginResult loginAndRegister(BaseRequest baseRequest) {
String mobile = baseRequest.getMobile();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
logger.info("loginAndRegister-accountInfoEntity is null {}, clientIp:{}", (accountInfoEntity == null), baseRequest.getLoginIp());
if (accountInfoEntity == null) {
//说明是注册功能
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(), baseRequest.getFlag() + "", baseRequest.getAuthCode());
return registerService.register(baseRequest);
} else {
//登录功能
accountUtils.checkMobilePhoneAndAuthCode(baseRequest.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", baseRequest.getAuthCode());
return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
}
}
/**
* 登录逻辑处理
* 登录逻辑处理
*
* @param baseRequest
*/
private LoginResult processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType) {
return processLogin(baseRequest, acctId, loginType, null);
}
private LoginResult processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType, QueryMobileEntity queryMobileEntity) {
Date currentTime = new Date();
Long userId = accountUtils.getUserIdByAcctId(baseRequest.getProductType(), acctId);
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId);
account.setCreatTime(currentTime);
account.setMobilePhone(baseRequest.getMobile());
account.setRegisterSource(baseRequest.getSourceType());
String newToken = tokenUtils.generateToken(account);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setMobile(baseRequest.getMobile());
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
//是否完善过个人信息(云鹊医app才需要)
if (baseRequest.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
Doctor doctorEntity = doctorInfoMapper.selectByPrimaryKey(userId.intValue());
result.setEntireFlag(doctorEntity.getEntireFlag());
}
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, baseRequest.getProductType(), baseRequest.getSourceType(),
loginType, baseRequest.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(), AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken);
if (queryMobileEntity != null) {
entity.setQueryMobileEntity(queryMobileEntity);
@Override
public LoginResult loginAndRegister(BaseRequest baseRequest) {
String mobile = baseRequest.getMobile();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
logger.info("loginAndRegister-accountInfoEntity is null {}, clientIp:{}", (accountInfoEntity == null), baseRequest.getLoginIp());
if (accountInfoEntity == null) {
//说明是注册功能
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(), baseRequest.getFlag() + "", baseRequest.getAuthCode());
return registerService.register(baseRequest);
} else {
//登录功能
accountUtils.checkMobilePhoneAndAuthCode(baseRequest.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", baseRequest.getAuthCode());
return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
}
}
picaLogUtils.info(entity);
return result;
}
@Override
@Transactional
public LoginResult loginByWeChat(BaseRequest request) {
WeChatEntity weChatEntity = null;
if (null != request.getBizType() &&
request.getBizType().equals(1)) {
// h5微信登录 TODO 下次单独拆分出去一个新接口
weChatEntity = WeChatUtils.getAuthorizationInfo(appIdH5, appSecretH5, request.getWeChatCode());
} else {
// 原生微信登录
weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
/**
* 登录逻辑处理
* 登录逻辑处理
*
* @param baseRequest
*/
private LoginResult processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType) {
return processLogin(baseRequest, acctId, loginType, null);
}
if (weChatEntity == null || StringUtils.isEmpty(weChatEntity.getOpenid()) || StringUtils.isEmpty(weChatEntity.getAccess_token())) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getCode(), AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getMessage());
}
// 微信登录获取个人信息
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountUnionEntity accountUnionEntity = accountUnionMapper.selectByUnionId(unionId);
//是否绑定逻辑的判断
if (accountUnionEntity != null) {
Long acctId = accountUnionEntity.getAcctId();
Long userId = accountUtils.getUserIdByAcctId(request.getProductType(), acctId.intValue());
private LoginResult processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType, QueryMobileEntity queryMobileEntity) {
Date currentTime = new Date();
Long userId = accountUtils.getUserIdByAcctId(baseRequest.getProductType(), acctId);
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId.intValue());
account.setCreatTime(new Date());
//account.setMobilePhone(request.getMobile());
account.setMobilePhone("");
account.setRegisterSource(request.getSourceType());
account.setAcctId(acctId);
account.setCreatTime(currentTime);
account.setMobilePhone(baseRequest.getMobile());
account.setRegisterSource(baseRequest.getSourceType());
String newToken = tokenUtils.generateToken(account);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_SUCCESS.getCode() + "");
result.setMobile(baseRequest.getMobile());
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (request.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(userId);
result.setEntireFlag(doctor.getEntire_flag());
result.setMobile(AESUtil.decryptV0(doctor.getMobile_phone()));
//是否完善过个人信息(云鹊医app才需要)
if (baseRequest.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
Doctor doctorEntity = doctorInfoMapper.selectByPrimaryKey(userId.intValue());
result.setEntireFlag(doctorEntity.getEntireFlag());
}
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(
Integer.valueOf(String.valueOf(acctId)),
request.getProductType(), request.getSourceType(),
AccountTypeEnum.LOGIN_WE_CHAT.getCode(),
request.getLoginIp(),
AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken);
picaLogUtils.info(entity);
return result;
} else {
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
//如果微信信息表数据不存在,就把用户信息存储到微信信息表中。
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, baseRequest.getProductType(), baseRequest.getSourceType(),
loginType, baseRequest.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(), AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken,1,baseRequest.getUserTokenTourist());
if (queryMobileEntity != null) {
entity.setQueryMobileEntity(queryMobileEntity);
}
LoginResult result = new LoginResult();
result.setUnionId(unionId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode() + "");
picaLogUtils.info(entity);
return result;
}
}
@Override
public LoginResult loginByWeChatStep(BaseRequest request) {
//判断当前手机号是否注册过,注册过,直接登录;没有注册过,进行注册操操作
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
logger.info("loginByWeChatStep-accountInfoEntity is null {}, clientIp:{}", (accountInfoEntity == null), request.getLoginIp());
LoginResult result;
if (accountInfoEntity == null) {
accountUtils.checkRegisterMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_WE_CHAT.getCode() + "",
request.getAuthCode());
result = registerService.register(request);
if (doubleWritingMode) {
//双写模式下,要在doctor表存储unionId
if (result.getUserId() != null) {
Doctor doctor = new Doctor();
doctor.setId(result.getUserId().intValue());
doctor.setUnionid(request.getUnionId());
doctorInfoMapper.updateByPrimaryKeySelective(doctor);
@Override
@Transactional
public LoginResult loginByWeChat(BaseRequest request) {
WeChatEntity weChatEntity = null;
if (null != request.getBizType() &&
request.getBizType().equals(1)) {
// h5微信登录 TODO 下次单独拆分出去一个新接口
weChatEntity = WeChatUtils.getAuthorizationInfo(appIdH5, appSecretH5, request.getWeChatCode());
} else {
// 原生微信登录
weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
}
if (weChatEntity == null || StringUtils.isEmpty(weChatEntity.getOpenid()) || StringUtils.isEmpty(weChatEntity.getAccess_token())) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getCode(), AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getMessage());
}
// 微信登录获取个人信息
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountUnionEntity accountUnionEntity = accountUnionMapper.selectByUnionId(unionId);
//是否绑定逻辑的判断
if (accountUnionEntity != null) {
Long acctId = accountUnionEntity.getAcctId();
Long userId = accountUtils.getUserIdByAcctId(request.getProductType(), acctId.intValue());
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId.intValue());
account.setCreatTime(new Date());
//account.setMobilePhone(request.getMobile());
account.setMobilePhone("");
account.setRegisterSource(request.getSourceType());
String newToken = tokenUtils.generateToken(account);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_SUCCESS.getCode() + "");
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (request.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(userId);
result.setEntireFlag(doctor.getEntire_flag());
result.setMobile(AESUtil.decryptV0(doctor.getMobile_phone()));
}
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(
Integer.valueOf(String.valueOf(acctId)),
request.getProductType(), request.getSourceType(),
AccountTypeEnum.LOGIN_WE_CHAT.getCode(),
request.getLoginIp(),
AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken,1,request.getUserTokenTourist());
picaLogUtils.info(entity);
return result;
} else {
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
//如果微信信息表数据不存在,就把用户信息存储到微信信息表中。
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
}
LoginResult result = new LoginResult();
result.setUnionId(unionId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode() + "");
return result;
}
} else {
accountUtils.checkMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_WE_CHAT.getCode() + "",
request.getAuthCode());
result = processLogin(request, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_WE_CHAT.getCode());
}
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId(), request.getProductType());
return result;
}
@Override
@Transactional
public void unbindWeChat(long doctorId) {
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.updateUnbindByAcctId(map);
if (doubleWritingMode) {
doctorService.unbindWeChat(acctId);
@Override
public LoginResult loginByWeChatStep(BaseRequest request) {
//判断当前手机号是否注册过,注册过,直接登录;没有注册过,进行注册操操作
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
logger.info("loginByWeChatStep-accountInfoEntity is null {}, clientIp:{}", (accountInfoEntity == null), request.getLoginIp());
LoginResult result;
if (accountInfoEntity == null) {
accountUtils.checkRegisterMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_WE_CHAT.getCode() + "",
request.getAuthCode());
result = registerService.register(request);
if (doubleWritingMode) {
//双写模式下,要在doctor表存储unionId
if (result.getUserId() != null) {
Doctor doctor = new Doctor();
doctor.setId(result.getUserId().intValue());
doctor.setUnionid(request.getUnionId());
doctorInfoMapper.updateByPrimaryKeySelective(doctor);
}
}
} else {
accountUtils.checkMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_WE_CHAT.getCode() + "",
request.getAuthCode());
result = processLogin(request, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_WE_CHAT.getCode());
}
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId(), request.getProductType());
return result;
}
}
@Override
@Transactional
public String bindWeChat(long doctorId, BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
} else {
updateWechatInfoUser(entity, weChatUserInfoEntity);
@Override
@Transactional
public void unbindWeChat(long doctorId) {
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.updateUnbindByAcctId(map);
if (doubleWritingMode) {
doctorService.unbindWeChat(acctId);
}
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId, request.getProductType());
return weChatUserInfoEntity.getNickname();
}
/**
* 把unionId存储到联合登录表中
*
* @param acctId
* @param unionId
*/
private void processAccountUnion(Integer acctId, String unionId, Integer productType) {
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
AccountUnionEntity accountUnionResult = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionResult != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
}
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(map);
if (accountUnionEntityAccount != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setCreatedTime(new Date());
accountUnionEntity.setModifiedTime(new Date());
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
if (doubleWritingMode) { //双写模式
doctorService.bindWeChat(acctId, unionId);
@Override
@Transactional
public String bindWeChat(long doctorId, BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
} else {
updateWechatInfoUser(entity, weChatUserInfoEntity);
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId, request.getProductType());
return weChatUserInfoEntity.getNickname();
}
/**
* 把unionId存储到联合登录表中
*
* @param acctId
* @param unionId
*/
private void processAccountUnion(Integer acctId, String unionId, Integer productType) {
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
AccountUnionEntity accountUnionResult = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionResult != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
}
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(map);
if (accountUnionEntityAccount != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setCreatedTime(new Date());
accountUnionEntity.setModifiedTime(new Date());
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
if (doubleWritingMode) { //双写模式
doctorService.bindWeChat(acctId, unionId);
}
}
}
private void processWeChatInfoUser(WeChatUserInfoEntity weChatUserInfoEntity, int type) {
AccountWeChatInfoEntity accountWeChatInfoEntity = new AccountWeChatInfoEntity();
Date currentTime = new Date();
accountWeChatInfoEntity.setCreatedId(0);
accountWeChatInfoEntity.setCreatedTime(currentTime);
accountWeChatInfoEntity.setDeleteFlag(1);
accountWeChatInfoEntity.setGroupid(weChatUserInfoEntity.getGroupid() + "");
accountWeChatInfoEntity.setType(type);
accountWeChatInfoEntity.setModifiedId(0);
accountWeChatInfoEntity.setModifiedTime(currentTime);
accountWeChatInfoEntity.setOpenid(weChatUserInfoEntity.getOpenid());
accountWeChatInfoEntity.setUnionid(weChatUserInfoEntity.getUnionid());
accountWeChatInfoEntity.setPrivilege(weChatUserInfoEntity.getPrivilege());
accountWeChatInfoEntity.setRemark(weChatUserInfoEntity.getRemark());
accountWeChatInfoEntity.setSubscribe(weChatUserInfoEntity.getSubscribe());
accountWeChatInfoEntity.setSubscribeTime(weChatUserInfoEntity.getSubscribe_time());
accountWeChatInfoEntity.setTagidList(weChatUserInfoEntity.getTagid_list());
accountWeChatInfoEntity.setCity(weChatUserInfoEntity.getCity());
accountWeChatInfoEntity.setNickname(weChatUserInfoEntity.getNickname());
accountWeChatInfoEntity.setHeadImgUrl(weChatUserInfoEntity.getHeadimgurl());
accountWeChatInfoEntity.setCountry(weChatUserInfoEntity.getCountry());
accountWeChatInfoEntity.setSex(weChatUserInfoEntity.getSex());
accountWeChatInfoEntity.setProvince(weChatUserInfoEntity.getProvince());
accountWeChatInfoEntity.setLanguage(weChatUserInfoEntity.getLanguage());
accountWeChatInfoMapper.insertSelective(accountWeChatInfoEntity);
}
private void updateWechatInfoUser(AccountWeChatInfoEntity entity, WeChatUserInfoEntity weChatUserInfoEntity) {
String nickname = weChatUserInfoEntity.getNickname();
if (StringUtils.isNotEmpty(nickname) && !nickname.equals(entity.getNickname())) {
AccountWeChatInfoEntity info = new AccountWeChatInfoEntity();
info.setId(entity.getId());
info.setNickname(nickname);
accountWeChatInfoMapper.updateByPrimaryKeySelective(info);
private void processWeChatInfoUser(WeChatUserInfoEntity weChatUserInfoEntity, int type) {
AccountWeChatInfoEntity accountWeChatInfoEntity = new AccountWeChatInfoEntity();
Date currentTime = new Date();
accountWeChatInfoEntity.setCreatedId(0);
accountWeChatInfoEntity.setCreatedTime(currentTime);
accountWeChatInfoEntity.setDeleteFlag(1);
accountWeChatInfoEntity.setGroupid(weChatUserInfoEntity.getGroupid() + "");
accountWeChatInfoEntity.setType(type);
accountWeChatInfoEntity.setModifiedId(0);
accountWeChatInfoEntity.setModifiedTime(currentTime);
accountWeChatInfoEntity.setOpenid(weChatUserInfoEntity.getOpenid());
accountWeChatInfoEntity.setUnionid(weChatUserInfoEntity.getUnionid());
accountWeChatInfoEntity.setPrivilege(weChatUserInfoEntity.getPrivilege());
accountWeChatInfoEntity.setRemark(weChatUserInfoEntity.getRemark());
accountWeChatInfoEntity.setSubscribe(weChatUserInfoEntity.getSubscribe());
accountWeChatInfoEntity.setSubscribeTime(weChatUserInfoEntity.getSubscribe_time());
accountWeChatInfoEntity.setTagidList(weChatUserInfoEntity.getTagid_list());
accountWeChatInfoEntity.setCity(weChatUserInfoEntity.getCity());
accountWeChatInfoEntity.setNickname(weChatUserInfoEntity.getNickname());
accountWeChatInfoEntity.setHeadImgUrl(weChatUserInfoEntity.getHeadimgurl());
accountWeChatInfoEntity.setCountry(weChatUserInfoEntity.getCountry());
accountWeChatInfoEntity.setSex(weChatUserInfoEntity.getSex());
accountWeChatInfoEntity.setProvince(weChatUserInfoEntity.getProvince());
accountWeChatInfoEntity.setLanguage(weChatUserInfoEntity.getLanguage());
accountWeChatInfoMapper.insertSelective(accountWeChatInfoEntity);
}
private void updateWechatInfoUser(AccountWeChatInfoEntity entity, WeChatUserInfoEntity weChatUserInfoEntity) {
String nickname = weChatUserInfoEntity.getNickname();
if (StringUtils.isNotEmpty(nickname) && !nickname.equals(entity.getNickname())) {
AccountWeChatInfoEntity info = new AccountWeChatInfoEntity();
info.setId(entity.getId());
info.setNickname(nickname);
accountWeChatInfoMapper.updateByPrimaryKeySelective(info);
}
}
}
@Override
public PICAPDoctor queryDoctor(long doctorId) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(doctorId);
if (doctor == null) {
doctor = new PICAPDoctor();
@Override
public PICAPDoctor queryDoctor(long doctorId) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(doctorId);
if (doctor == null) {
doctor = new PICAPDoctor();
}
doctor.setAvatar_image_url(this.processDoctorAvatar(doctor.getAvatar_image_url()));
return doctor;
}
doctor.setAvatar_image_url(this.processDoctorAvatar(doctor.getAvatar_image_url()));
return doctor;
}
@Override
public LoginResult oneClickLogin(OneClickLoginReq req) {
QueryMobileEntity queryMobileEntity = oneClickProcessor.tokenExchangeMobile(req.getToken(), req.getSourceType());
if (queryMobileEntity == null || StringUtils.isBlank(queryMobileEntity.getMobile()) || !ValidateUtils.isMobile(queryMobileEntity.getMobile())) {
throw new PicaException(PicaResultCode.INTERFACE_INVOKE_EXCEPTION.code(), "获取手机号失败!");
}
queryMobileEntity.setSourceType(req.getSourceType());
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(queryMobileEntity.getMobile()));
BaseRequest baseRequest = new BaseRequest();
baseRequest.setMobile(queryMobileEntity.getMobile());
baseRequest.setSourceType(req.getSourceType());
baseRequest.setProductType(req.getProductType());
baseRequest.setLoginIp(req.getLoginIp());
LoginResult result;
if (accountInfoEntity == null) {
//说明是注册功能
result = registerService.register(baseRequest, queryMobileEntity);
} else {
//登录功能
result = processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_ONE_CLICK.getCode(), queryMobileEntity);
@Override
public LoginResult oneClickLogin(OneClickLoginReq req) {
QueryMobileEntity queryMobileEntity = oneClickProcessor.tokenExchangeMobile(req.getToken(), req.getSourceType());
if (queryMobileEntity == null || StringUtils.isBlank(queryMobileEntity.getMobile()) || !ValidateUtils.isMobile(queryMobileEntity.getMobile())) {
throw new PicaException(PicaResultCode.INTERFACE_INVOKE_EXCEPTION.code(), "获取手机号失败!");
}
queryMobileEntity.setSourceType(req.getSourceType());
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(queryMobileEntity.getMobile()));
BaseRequest baseRequest = new BaseRequest();
baseRequest.setMobile(queryMobileEntity.getMobile());
baseRequest.setSourceType(req.getSourceType());
baseRequest.setProductType(req.getProductType());
baseRequest.setLoginIp(req.getLoginIp());
baseRequest.setUserTokenTourist(req.getUserTokenTourist());
LoginResult result;
if (accountInfoEntity == null) {
//说明是注册功能
result = registerService.register(baseRequest, queryMobileEntity);
} else {
//登录功能
result = processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_ONE_CLICK.getCode(), queryMobileEntity);
}
return result;
}
return result;
}
private String processDoctorAvatar(String avatar_image_url) {
if (StringUtils.isEmpty(avatar_image_url)) {
return DEFAULT_DOCTOR_PICTURE_URL;
} else {
int pos = avatar_image_url.lastIndexOf(".");
if (pos < 0) {
private String processDoctorAvatar(String avatar_image_url) {
if (StringUtils.isEmpty(avatar_image_url)) {
return DEFAULT_DOCTOR_PICTURE_URL;
} else {
String ext = avatar_image_url.substring(pos + 1, avatar_image_url.length()).toLowerCase();
return !PIC_TYPE_MAP.containsKey(ext) ? DEFAULT_DOCTOR_PICTURE_URL : avatar_image_url;
int pos = avatar_image_url.lastIndexOf(".");
if (pos < 0) {
return DEFAULT_DOCTOR_PICTURE_URL;
} else {
String ext = avatar_image_url.substring(pos + 1, avatar_image_url.length()).toLowerCase();
return !PIC_TYPE_MAP.containsKey(ext) ? DEFAULT_DOCTOR_PICTURE_URL : avatar_image_url;
}
}
}
}
/**
* @Description 统一校验(传空则不会校验)
* @Author Chongwen.jiang
* @Date 2020/2/20 16:55
* @ModifyDate 2020/2/20 16:55
* @Params [request]
* @Return com.pica.cloud.foundation.entity.PicaResponse
*/
@Override
public void preLoginValidate(BaseRequest request) {
Integer bizType = request.getBizType();
String mobile = request.getMobile();
Integer sourceType = request.getSourceType();
if (null == bizType) {
logger.info("bizType is null");
throw new PicaWarnException(PicaResultCode.PARAM_IS_BLANK.code(),
PicaResultCode.PARAM_IS_BLANK.message());
}
/**
* @Description 统一校验(传空则不会校验)
* @Author Chongwen.jiang
* @Date 2020/2/20 16:55
* @ModifyDate 2020/2/20 16:55
* @Params [request]
* @Return com.pica.cloud.foundation.entity.PicaResponse
*/
@Override
public void preLoginValidate(BaseRequest request) {
Integer bizType = request.getBizType();
String mobile = request.getMobile();
Integer sourceType = request.getSourceType();
if (null == bizType) {
logger.info("bizType is null");
throw new PicaWarnException(PicaResultCode.PARAM_IS_BLANK.code(),
PicaResultCode.PARAM_IS_BLANK.message());
}
if (bizType.equals(2)) {
// 手机号规则校验
if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
}
} else if (bizType.equals(3)) {
// 手机号规则校验
if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
}
// 手机号是否注册
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfo == null) {
if (sourceType != null && SourceTypeEnum.H5.getCode().equals(sourceType)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_REGIST_H5.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_REGIST_H5.getMessage());
} else {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getMessage().replace("{mobile}", mobile));
if (bizType.equals(2)) {
// 手机号规则校验
if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
}
}
// 手机号是否设置了密码
if (StringUtils.isEmpty(accountInfo.getPassword())) {
if (sourceType != null && SourceTypeEnum.H5.getCode().equals(sourceType)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD_H5.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD_H5.getMessage());
} else {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getMessage().replace("{mobile}", mobile));
} else if (bizType.equals(3)) {
// 手机号规则校验
if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
}
// 手机号是否注册
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfo == null) {
if (sourceType != null && SourceTypeEnum.H5.getCode().equals(sourceType)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_REGIST_H5.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_REGIST_H5.getMessage());
} else {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getMessage().replace("{mobile}", mobile));
}
}
// 手机号是否设置了密码
if (StringUtils.isEmpty(accountInfo.getPassword())) {
if (sourceType != null && SourceTypeEnum.H5.getCode().equals(sourceType)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD_H5.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD_H5.getMessage());
} else {
throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getCode(),
AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getMessage().replace("{mobile}", mobile));
}
}
}
}
}
/**
* @Description 苹果登录授权
* @Author Chongwen.jiang
* @Date 2020/2/24 19:21
* @ModifyDate 2020/2/24 19:21
* @Params [request]
* @Return com.pica.cloud.account.account.server.entity.LoginResult
*/
@Transactional
@Override
public LoginResult loginByApple(BaseRequest request) {
long start = System.currentTimeMillis();
// 入参非空判断
if (StringUtils.isEmpty(request.getIdentifyToken())) {
throw new PicaException(AccountExceptionEnum.PICA_PARAMS_ERROR.getCode(),
AccountExceptionEnum.PICA_PARAMS_ERROR.getMessage());
}
// identifyToken校验
if(!checkIdentifyToken(request)){
throw new PicaException(
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getCode(),
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getMessage());
}
// apple授权登录用户信息入库
AccountUnionEntity accountUnion = accountUnionMapper.selectByUnionId(request.getAppleUserId());
//是否绑定逻辑的判断
if (accountUnion != null) {
Long acctId = accountUnion.getAcctId();
Long userId = accountUtils.getUserIdByAcctId(null, acctId.intValue());
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId.intValue());
account.setCreatTime(new Date());
account.setMobilePhone("");
account.setRegisterSource(request.getSourceType());
String newToken = tokenUtils.generateToken(account);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_SUCCESS.getCode() + "");
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (request.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(userId);
result.setEntireFlag(doctor.getEntire_flag());
result.setMobile(AESUtil.decryptV0(doctor.getMobile_phone()));
/**
* @Description 苹果登录授权
* @Author Chongwen.jiang
* @Date 2020/2/24 19:21
* @ModifyDate 2020/2/24 19:21
* @Params [request]
* @Return com.pica.cloud.account.account.server.entity.LoginResult
*/
@Transactional
@Override
public LoginResult loginByApple(BaseRequest request) {
long start = System.currentTimeMillis();
// 入参非空判断
if (StringUtils.isEmpty(request.getIdentifyToken())) {
throw new PicaException(AccountExceptionEnum.PICA_PARAMS_ERROR.getCode(),
AccountExceptionEnum.PICA_PARAMS_ERROR.getMessage());
}
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(
Integer.valueOf(String.valueOf(acctId)),
request.getProductType(), request.getSourceType(),
AccountTypeEnum.LOGIN_APPLE.getCode(),
request.getLoginIp(),
AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken);
picaLogUtils.info(entity);
// identifyToken校验
if(!checkIdentifyToken(request)){
throw new PicaException(
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getCode(),
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getMessage());
}
// apple授权登录用户信息入库
AccountUnionEntity accountUnion = accountUnionMapper.selectByUnionId(request.getAppleUserId());
//是否绑定逻辑的判断
if (accountUnion != null) {
Long acctId = accountUnion.getAcctId();
Long userId = accountUtils.getUserIdByAcctId(null, acctId.intValue());
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId.intValue());
account.setCreatTime(new Date());
account.setMobilePhone("");
account.setRegisterSource(request.getSourceType());
String newToken = tokenUtils.generateToken(account);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_SUCCESS.getCode() + "");
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (request.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(userId);
result.setEntireFlag(doctor.getEntire_flag());
result.setMobile(AESUtil.decryptV0(doctor.getMobile_phone()));
}
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(
Integer.valueOf(String.valueOf(acctId)),
request.getProductType(), request.getSourceType(),
AccountTypeEnum.LOGIN_APPLE.getCode(),
request.getLoginIp(),
AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken,1,request.getUserTokenTourist());
picaLogUtils.info(entity);
long end1 = System.currentTimeMillis();
logger.info("loginByApple1-duration {} millionSeconds", (end1-start));
return result;
} else {
AccountAppleInfo entity = accountAppleInfoMapper.selectByUserId(request.getAppleUserId());
//如果apple信息表数据不存在,就把用户信息存储到apple信息表中。
if (entity == null) {
processAppleInfoUser(request);
long end1 = System.currentTimeMillis();
logger.info("loginByApple1-duration {} millionSeconds", (end1-start));
return result;
} else {
AccountAppleInfo entity = accountAppleInfoMapper.selectByUserId(request.getAppleUserId());
//如果apple信息表数据不存在,就把用户信息存储到apple信息表中。
if (entity == null) {
processAppleInfoUser(request);
}
LoginResult result = new LoginResult();
result.setUnionId(request.getAppleUserId());
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode() + "");
long end1 = System.currentTimeMillis();
logger.info("loginByApple2-duration {} millionSeconds", (end1-start));
return result;
}
LoginResult result = new LoginResult();
result.setUnionId(request.getAppleUserId());
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode() + "");
long end1 = System.currentTimeMillis();
logger.info("loginByApple2-duration {} millionSeconds", (end1-start));
return result;
}
}
/**
* @Description apple登录--identifyToken校验
* @Author Chongwen.jiang
* @Date 2020/2/24 19:28
* @ModifyDate 2020/2/24 19:28
* @Params [identifyToekn]
* @Return boolean false:未通过token校验,true:通过校验
*/
private boolean checkIdentifyToken(BaseRequest request) {
String identifyToken = request.getIdentifyToken();
logger.info("checkIdentifyToken-identifyToken:{}", identifyToken);
// 向苹果后台获取公钥参数
String appleResp = null;
try {
appleResp = HttpClientCloudUtils.getHttpExecute(Constants.APPLE_GET_PUBLIC_KEY_URL);
logger.info("checkIdentifyToken-appleResp:{}", appleResp);
} catch (Exception e) {
logger.info("checkIdentifyToken-get apple public key fail " + e.getMessage());
throw new PicaException("get apple public key fail Exception", "get apple public key fail");
}
JSONObject appleRespJson = JSONObject.parseObject(appleResp);
String keys = appleRespJson.getString("keys");
JSONArray keysArr = JSONObject.parseArray(keys);
/**
* @Description apple登录--identifyToken校验
* @Author Chongwen.jiang
* @Date 2020/2/24 19:28
* @ModifyDate 2020/2/24 19:28
* @Params [identifyToekn]
* @Return boolean false:未通过token校验,true:通过校验
*/
private boolean checkIdentifyToken(BaseRequest request) {
String identifyToken = request.getIdentifyToken();
logger.info("checkIdentifyToken-identifyToken:{}", identifyToken);
// 向苹果后台获取公钥参数
String appleResp = null;
try {
appleResp = HttpClientCloudUtils.getHttpExecute(Constants.APPLE_GET_PUBLIC_KEY_URL);
logger.info("checkIdentifyToken-appleResp:{}", appleResp);
} catch (Exception e) {
logger.info("checkIdentifyToken-get apple public key fail " + e.getMessage());
throw new PicaException("get apple public key fail Exception", "get apple public key fail");
}
JSONObject appleRespJson = JSONObject.parseObject(appleResp);
String keys = appleRespJson.getString("keys");
JSONArray keysArr = JSONObject.parseArray(keys);
if (identifyToken.split("\\.").length < 2) {
throw new PicaException("get identifyToken fail Exception", "get identifyToken format Exception");
}
JSONObject useAppleAuth = new JSONObject();
String inAuth = new String(Base64.decodeBase64(identifyToken.split("\\.")[0]));
String inKid = JSONObject.parseObject(inAuth).get("kid").toString();
for(Object obj : keysArr){
JSONObject appleAuth = JSONObject.parseObject(obj.toString());
if(inKid.equals(appleAuth.getString("kid"))){
useAppleAuth = appleAuth;
logger.info("checkIdentifyToken-jsonObject1:{}", useAppleAuth);
break;
if (identifyToken.split("\\.").length < 2) {
throw new PicaException("get identifyToken fail Exception", "get identifyToken format Exception");
}
JSONObject useAppleAuth = new JSONObject();
String inAuth = new String(Base64.decodeBase64(identifyToken.split("\\.")[0]));
String inKid = JSONObject.parseObject(inAuth).get("kid").toString();
for(Object obj : keysArr){
JSONObject appleAuth = JSONObject.parseObject(obj.toString());
if(inKid.equals(appleAuth.getString("kid"))){
useAppleAuth = appleAuth;
logger.info("checkIdentifyToken-jsonObject1:{}", useAppleAuth);
break;
}
}
}
// 通过jar生成publicKey
PublicKey publicKey;
try {
Jwk jwa = Jwk.fromValues(useAppleAuth);
publicKey = jwa.getPublicKey();
} catch (Exception e) {
logger.info("checkIdentifyToken-generate publicKey fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-generate publicKey fail", "generate publicKey fail");
}
// 通过jar生成publicKey
PublicKey publicKey;
try {
Jwk jwa = Jwk.fromValues(useAppleAuth);
publicKey = jwa.getPublicKey();
} catch (Exception e) {
logger.info("checkIdentifyToken-generate publicKey fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-generate publicKey fail", "generate publicKey fail");
}
// 分割前台传过来的identifyToken(jwt格式的token)用base64解码使用
String aud;
String sub;
try {
String claim = new String(Base64.decodeBase64(identifyToken.split("\\.")[1]));
//logger.info("checkIdentifyToken-claim:{}", claim);
aud = JSONObject.parseObject(claim).get("aud").toString();
sub = JSONObject.parseObject(claim).get("sub").toString();
// appleUserId从token中解码取出后赋值
request.setAppleUserId(sub);
} catch (Exception e) {
logger.info("checkIdentifyToken-token decode fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-token decode fail Exception", "token decode fail");
// 分割前台传过来的identifyToken(jwt格式的token)用base64解码使用
String aud;
String sub;
try {
String claim = new String(Base64.decodeBase64(identifyToken.split("\\.")[1]));
//logger.info("checkIdentifyToken-claim:{}", claim);
aud = JSONObject.parseObject(claim).get("aud").toString();
sub = JSONObject.parseObject(claim).get("sub").toString();
// appleUserId从token中解码取出后赋值
request.setAppleUserId(sub);
} catch (Exception e) {
logger.info("checkIdentifyToken-token decode fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-token decode fail Exception", "token decode fail");
}
return this.verify(publicKey, identifyToken, aud, sub, request);
}
/**
* @Description 验证苹果公钥
* @Author Chongwen.jiang
* @Date 2020/2/24 19:49
* @ModifyDate 2020/2/24 19:49
* @Params [key, jwt, audience, subject]
* @Return boolean
*/
private boolean verify(PublicKey key, String jwt, String audience, String subject, BaseRequest request) {
JwtParser jwtParser = Jwts.parser().setSigningKey(key);
jwtParser.requireIssuer(Constants.APPLE_ISSUE_URL);
jwtParser.requireAudience(audience);
jwtParser.requireSubject(subject);
try {
logger.info("checkIdentifyToken-apple-verify-starting");
Jws<Claims> claim = jwtParser.parseClaimsJws(jwt);
logger.info("acheckIdentifyToken-apple-verify-claim:{}", JSON.toJSONString(claim));
//logger.info("apple-verify-claim.getBody:{}", JSON.toJSONString(claim.getBody()));
if (claim != null && claim.getBody().containsKey("auth_time")) {
request.setInfo(JSON.toJSONString(claim.getBody()));
JSONObject claimBody = JSONObject.parseObject(JSON.toJSONString(claim.getBody()), JSONObject.class);
request.setAppleId(claimBody.getString("email"));
return true;
}
return false;
} catch (ExpiredJwtException e) {
logger.info("checkIdentifyToken-apple token expired " + e.getMessage());
throw new PicaException("apple token expired Exception", "apple token expired");
} catch (Exception e) {
logger.info("checkIdentifyToken-apple token illegal " + e.getMessage());
throw new PicaException("apple token illegal Exception", "apple token illegal");
}
}
return this.verify(publicKey, identifyToken, aud, sub, request);
}
/**
* @Description 验证苹果公钥
* @Author Chongwen.jiang
* @Date 2020/2/24 19:49
* @ModifyDate 2020/2/24 19:49
* @Params [key, jwt, audience, subject]
* @Return boolean
*/
private boolean verify(PublicKey key, String jwt, String audience, String subject, BaseRequest request) {
JwtParser jwtParser = Jwts.parser().setSigningKey(key);
jwtParser.requireIssuer(Constants.APPLE_ISSUE_URL);
jwtParser.requireAudience(audience);
jwtParser.requireSubject(subject);
try {
logger.info("checkIdentifyToken-apple-verify-starting");
Jws<Claims> claim = jwtParser.parseClaimsJws(jwt);
logger.info("acheckIdentifyToken-apple-verify-claim:{}", JSON.toJSONString(claim));
//logger.info("apple-verify-claim.getBody:{}", JSON.toJSONString(claim.getBody()));
if (claim != null && claim.getBody().containsKey("auth_time")) {
request.setInfo(JSON.toJSONString(claim.getBody()));
JSONObject claimBody = JSONObject.parseObject(JSON.toJSONString(claim.getBody()), JSONObject.class);
request.setAppleId(claimBody.getString("email"));
return true;
}
return false;
} catch (ExpiredJwtException e) {
logger.info("checkIdentifyToken-apple token expired " + e.getMessage());
throw new PicaException("apple token expired Exception", "apple token expired");
} catch (Exception e) {
logger.info("checkIdentifyToken-apple token illegal " + e.getMessage());
throw new PicaException("apple token illegal Exception", "apple token illegal");
/**
* @Description apple用户信息入表
* @Author Chongwen.jiang
* @Date 2020/2/24 11:00
* @ModifyDate 2020/2/24 11:00
* @Params [request]
* @Return void
*/
private void processAppleInfoUser(BaseRequest request) {
AccountAppleInfo appleInfo = new AccountAppleInfo();
appleInfo.setCreatedId(0);
appleInfo.setModifiedId(0);
appleInfo.setAppleUserId(request.getAppleUserId());
appleInfo.setAppleId(request.getAppleId());
appleInfo.setInfo(request.getInfo());
accountAppleInfoMapper.insertSelective(appleInfo);
}
/**
* @Description 苹果登录绑定手机号
* @Author Chongwen.jiang
* @Date 2020/2/24 11:40
* @ModifyDate 2020/2/24 11:40
* @Params [request]
* @Return com.pica.cloud.account.account.server.entity.LoginResult
*/
@Override
public LoginResult loginByAppleStep(BaseRequest request) {
// 判断当前手机号是否注册过: 没有注册过,进行注册操操作, 注册过,直接登录;
AccountInfoEntity accountInfoDb = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
logger.info("loginByAppleStep-account is null {}, request:{}", accountInfoDb == null, JSON.toJSONString(request));
LoginResult result;
if (accountInfoDb == null) {
// 验证码校验
accountUtils.checkRegisterMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_APPLE.getCode() + "",
request.getAuthCode());
result = registerService.register(request);
logger.info("loginByAppleStep-register");
} else {
// 验证码校验
accountUtils.checkMobilePhoneAndAuthCode(request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_APPLE.getCode() + "",
request.getAuthCode());
result = processLogin(request, accountInfoDb.getId(),
AccountTypeEnum.LOGIN_APPLE.getCode());
logger.info("loginByAppleStep-processLogin");
}
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
// insert account_apple_info表数据
logger.info("loginByAppleStep-insert-account_apple_info-start");
processAccountUnionApple(acctId, request.getAppleUserId());
logger.info("loginByAppleStep-insert-account_apple_info-end");
return result;
}
}
/**
* @Description apple用户信息入表
* @Author Chongwen.jiang
* @Date 2020/2/24 11:00
* @ModifyDate 2020/2/24 11:00
* @Params [request]
* @Return void
*/
private void processAppleInfoUser(BaseRequest request) {
AccountAppleInfo appleInfo = new AccountAppleInfo();
appleInfo.setCreatedId(0);
appleInfo.setModifiedId(0);
appleInfo.setAppleUserId(request.getAppleUserId());
appleInfo.setAppleId(request.getAppleId());
appleInfo.setInfo(request.getInfo());
accountAppleInfoMapper.insertSelective(appleInfo);
}
/**
* @Description 苹果登录绑定手机号
* @Author Chongwen.jiang
* @Date 2020/2/24 11:40
* @ModifyDate 2020/2/24 11:40
* @Params [request]
* @Return com.pica.cloud.account.account.server.entity.LoginResult
*/
@Override
public LoginResult loginByAppleStep(BaseRequest request) {
// 判断当前手机号是否注册过: 没有注册过,进行注册操操作, 注册过,直接登录;
AccountInfoEntity accountInfoDb = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
logger.info("loginByAppleStep-account is null {}, request:{}", accountInfoDb == null, JSON.toJSONString(request));
LoginResult result;
if (accountInfoDb == null) {
// 验证码校验
accountUtils.checkRegisterMobilePhoneAndAuthCode(
request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_APPLE.getCode() + "",
request.getAuthCode());
result = registerService.register(request);
logger.info("loginByAppleStep-register");
} else {
// 验证码校验
accountUtils.checkMobilePhoneAndAuthCode(request.getMobile(),
AccountTypeEnum.SYSCODE_TYPE_APPLE.getCode() + "",
request.getAuthCode());
result = processLogin(request, accountInfoDb.getId(),
AccountTypeEnum.LOGIN_APPLE.getCode());
logger.info("loginByAppleStep-processLogin");
/**
* @Description account_apple_info insert
* @Author Chongwen.jiang
* @Date 2020/2/24 11:34
* @ModifyDate 2020/2/24 11:34
* @Params [acctId, appleUserId]
* @Return void
*/
private void processAccountUnionApple(Integer acctId, String appleUserId) {
AccountUnionEntity accountUnion = accountUnionMapper.selectByUnionId(appleUserId);
if (accountUnion != null) {
throw new PicaException(
AccountExceptionEnum.PICA_APPLE_BIND_OTHER.getCode(),
AccountExceptionEnum.PICA_APPLE_BIND_OTHER.getMessage());
}
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_APPLE.getCode());
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(map);
if (accountUnionEntityAccount != null) {
throw new PicaException(
AccountExceptionEnum.PICA_MOBILE_BIND_OTHER.getCode(),
AccountExceptionEnum.PICA_MOBILE_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setUnionId(appleUserId);
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_APPLE.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
}
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
// insert account_apple_info表数据
logger.info("loginByAppleStep-insert-account_apple_info-start");
processAccountUnionApple(acctId, request.getAppleUserId());
logger.info("loginByAppleStep-insert-account_apple_info-end");
return result;
}
/**
* @Description account_apple_info insert
* @Author Chongwen.jiang
* @Date 2020/2/24 11:34
* @ModifyDate 2020/2/24 11:34
* @Params [acctId, appleUserId]
* @Return void
*/
private void processAccountUnionApple(Integer acctId, String appleUserId) {
AccountUnionEntity accountUnion = accountUnionMapper.selectByUnionId(appleUserId);
if (accountUnion != null) {
throw new PicaException(
AccountExceptionEnum.PICA_APPLE_BIND_OTHER.getCode(),
AccountExceptionEnum.PICA_APPLE_BIND_OTHER.getMessage());
}
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_APPLE.getCode());
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(map);
if (accountUnionEntityAccount != null) {
throw new PicaException(
AccountExceptionEnum.PICA_MOBILE_BIND_OTHER.getCode(),
AccountExceptionEnum.PICA_MOBILE_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setUnionId(appleUserId);
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_APPLE.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
}
}
......@@ -139,7 +139,7 @@ public class RegisterServiceImpl implements RegisterService {
result.setMobile(mobile);
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, baseRequest.getSourceType(),
AccountTypeEnum.LOGIN_REGISTER.getCode(), baseRequest.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken);
AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),newToken,1,baseRequest.getUserTokenTourist());
if(queryMobileEntity != null){
entity.setQueryMobileEntity(queryMobileEntity);
}
......
......@@ -13,6 +13,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
/**
* Created on 2019/10/21 13:20
......@@ -26,7 +27,7 @@ public class AESUtil {
//算法
private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";
public static final String privateKey = "";
public static final String privateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAKdXMOUboMkHBOyfuMWuIo6bOp+b53i/LoO0qox+sQ+DqFTdt9tH1dF/CoAWtLj5CjDJum7JYJrsMXIqXQnIRr8ZKt+NtdKlqUUeGZYfTPSEIXWb9S+U8DQFqJgXL25xcX1SHxFoeRkZWZX5FtUhKTimOVl1FwrkRDmFyIEUa2AbAgMBAAECgYEAlEZHxtoiL74OePRVrqNLb3zQBxkHkxAj0QPGktK3ZP3Nq9UB0kTmisi8rx5vZ+8TPoOgtAWvmdZrQbOT2NUjCUYKkGS+Wi1fXpP0Az2UJwDIQK4aQTZtNbM04f3Rmi5i24eASmSdl1svjHEv0YS6IC6sR1cbElZs94uDFshUeqECQQDTrmZda8fo6ZNsHVYWcjTwr8JKTIgjaD/hPi0JP6hhL0GVEAVwb2rsfJf5o2TR5RsNT8ANUYgFPRaAymLLe+5zAkEAymA9V55K6IJhnSp7HmWfGVmxvTrwZFJIzPv7DLi/RAS3yFPfTpyJGLirAnBQfKO/vwjxhAuwD21aDYHMTrj1uQJBAJdAikw+cz1tiLU70QOA32sLaxyDytLh7qMXNj7hiYLHrWjBZeGM+y23aTArHCMOPWIpleTuWO7FU4r7EdSr3RkCQQCliu4CwyhRY33H210U81memgFLYnAMEEce7qxgrqs+T4Gqa/lJy8BVqZGxkAA2xJfwA7fUJN9i7zdvvxJJ/wB5AkA+OKfnTXTp8qF4lZiVMrGl3d5sgg87q1DhC5XruviH6a3u6JOLlRNQy2+TGxzWMYaJ1RwEfygqBYOgyvoqNR3Q";
private static final String charset = "UTF-8";
/**
......@@ -185,9 +186,13 @@ public class AESUtil {
* 测试
*/
public static void main(String[] args) throws Exception {
String KEY="zJJ$c5md3$yuuhWW";
System.out.println("-------------加密---------");
String content = "15607241351";
String content = "18709744120";
System.out.println("加密前:" + content);
......@@ -199,11 +204,38 @@ public class AESUtil {
String decrypt = aesDecrypt(encrypt, KEY);
System.out.println("解密后:" + decrypt);
//请求参数解密处理
// String key="am1pnysCRlz80Rl/eTDj/UE/Pe8zkxb2yP73jvrUWEk3x5/lK9hi104MSmsKbl45cPzJfJXBxO+VeItkA63ZqfaUNA0ezdMd7Ord7rGqvWK+4RqAm1T3Qo3lw/5bT0GwgWMWZBrDr30NHCYLmjg6vwVbv3YCEewwQK+rL7bUXu0=";
// List<String> list = new ArrayList<>();
//
// String str="13330782565,13638247234,15208346780,13665702440,13171898394,13526001352,15637729989,18282702080,17839157550,13733479385,13873347938,18192022131,17868481983,13389208740,15130643581,18743289267,15025550691,18706903023,15153299810,13400213017,13400213014,13809393727,15082898689,15181524146,13067777147,15936327251,13982581989,13055116890,13183128853,13526235120,13620258773,13470126432,15379993781,15612968111,15930496256,13504498834,13328506266,13405379887,18636815186,18638124991,18997577751,18742986968,13737844850,15249387846,13890801202,18294832224,15329652816,13453947981,17393142302,18219810087,15031950900,18670808468,18670508468,18670508568,15566394123,18719884109,13789221826,13939497532,13939925847,13791830377,18919411543,18893835167,18194329526,13207866808,13082126549,15802548543,15879451129,15390381641,13132431383,18279911958,13827920609,15209825253,15509825253,18184482231,13325225232,15908034636,15352111767,18709744120,15807269519,19971489100,13721734937,13765575183,15329652819,13883396206,18085581329,15090694439,15090694436,13782477033,13207995156,13630682016,15607241351,13830780802";
// String[] arr = str.split(",");
// for (int i = 0; i < arr.length; i++) {
// String KEY="zJJ$c5md3$yuuhWW";
// System.out.println("-------------加密---------");
// String content = arr[i];
// System.out.println("加密前:" + content);
// System.out.println("加密密钥和解密密钥:" + KEY);
//
// System.out.println("-------------解密---------");
// String encrypt = aesEncrypt(content, KEY);
// System.out.println("加密后:" + encrypt);
// String decrypt = aesDecrypt(encrypt, KEY);
// System.out.println("解密后:" + decrypt);
// list.add(encrypt);
// }
//
// for (int i = 0; i < list.size(); i++) {
// System.out.println(list.get(i));
// }
// 请求参数解密处理
// String key="HSBPIMChYBYHKMb/wmq0dYIKnUU5UvlzeWrWkmxWUJ0RI2cgEf9jcISPHfLsJurCjj5xwTz6KjPnm0Z+ylaiVDpiLT55vKWHC0HnPqVePSR6Sn6cdaESDCMMGbNdJb+crnjvfTo0v4zQwqvjUJBDR9KRc5C3Dr07dITbPQbJXJk=";
// String decrypt = RSAUtil.decrypt(key,privateKey);
// System.out.println(decrypt);
// String content="d9eKA7DGhNx7295N0g82rqzaUOeAvBeuR2gXtOX3Y+VV3ei+zW0BQn9moQgN4mRT8XIzq3x2n3qiqCuOzcDvrlGC0kIcUClM0gt8xDaBw+haVpMAw/7R4FgWNPeVRL5k";
// String content="L/05P603DA9u/as3uHbzsF+LqYhfxJonT80u0oH0YobLCta/wR1xEH//NccyJlQ";
// String result = AESUtil.aesDecrypt(content, decrypt);
// System.out.println(result);
......
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" monitorInterval="30">
<properties>
<property name="logPath" value="${sys:LOG_PATH:-/opt/tomcat-log}"/>
<property name="logPatternLayout"
value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%t] %class{36}.%M - %msg%xEx%n"/>
<property name="logRolloverSize" value="100M"/>
<property name="logKeepDays" value="15d"/>
<property name="logDirNumberOfFiles" value="300"/>
</properties>
<Appenders>
<!--CONSOLE-->
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
</Console>
<!--TRACE-->
<RollingFile name="TRACE" filename="${logPath}/trace.log"
filepattern="${logPath}/$${date:yyyy-MM-dd}/trace-%d{yyyyMMdd}-%i.log">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
<Filters>
<ThresholdFilter level="debug" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="${logRolloverSize}"/>
</Policies>
<DefaultRolloverStrategy max="${logDirNumberOfFiles}">
<Delete basePath="${logPath}" maxDepth="3">
<IfFileName glob="*/trace*.log"/>
<IfLastModified age="${logKeepDays}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--DEBUG-->
<RollingFile name="DEBUG" filename="${logPath}/debug.log"
filepattern="${logPath}/$${date:yyyy-MM-dd}/debug-%d{yyyyMMdd}-%i.log">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
<Filters>
<ThresholdFilter level="info" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="${logRolloverSize}"/>
</Policies>
<DefaultRolloverStrategy max="${logDirNumberOfFiles}">
<Delete basePath="${logPath}" maxDepth="3">
<IfFileName glob="*/debug*.log"/>
<IfLastModified age="${logKeepDays}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--INFO-->
<RollingFile name="INFO" filename="${logPath}/info.log"
filepattern="${logPath}/$${date:yyyy-MM-dd}/info-%d{yyyyMMdd}-%i.log">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
<Filters>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="${logRolloverSize}"/>
</Policies>
<DefaultRolloverStrategy max="${logDirNumberOfFiles}">
<Delete basePath="${logPath}" maxDepth="3">
<IfFileName glob="*/info*.log"/>
<IfLastModified age="${logKeepDays}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--WARN-->
<RollingFile name="WARN" filename="${logPath}/warn.log"
filepattern="${logPath}/$${date:yyyy-MM-dd}/warn-%d{yyyyMMdd}-%i.log">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
<Filters>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="${logRolloverSize}"/>
</Policies>
<DefaultRolloverStrategy max="${logDirNumberOfFiles}">
<Delete basePath="${logPath}" maxDepth="3">
<IfFileName glob="*/warn*.log"/>
<IfLastModified age="${logKeepDays}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--ERROR-->
<RollingFile name="ERROR" filename="${logPath}/error.log"
filepattern="${logPath}/$${date:yyyy-MM-dd}/error-%d{yyyyMMdd}-%i.log">
<PatternLayout charset="UTF-8" pattern="${logPatternLayout}"/>
<Filters>
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="${logRolloverSize}"/>
</Policies>
<DefaultRolloverStrategy max="${logDirNumberOfFiles}">
<Delete basePath="${logPath}" maxDepth="3">
<IfFileName glob="*/error*.log"/>
<IfLastModified age="${logKeepDays}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<CatAppender name="CatAppender"/>
</Appenders>
<Loggers>
<Root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="TRACE"/>
<appender-ref ref="DEBUG"/>
<appender-ref ref="INFO"/>
<appender-ref ref="WARN"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="CatAppender"/>
</Root>
  
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error"/>
        
<Logger name="org.apache.catalina.util.LifecycleBase" level="error"/>
        
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn"/>
        
<logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
        
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn"/>
        
<Logger name="org.crsh.plugin" level="warn"/>
        
<logger name="org.crsh.ssh" level="warn"/>
        
<Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error"/>
        
<Logger name="org.hibernate.validator.internal.util.Version" level="warn"/>
        
<logger name="org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration" level="warn"/>
        
<logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
        
<logger name="org.thymeleaf" level="warn"/>
</Loggers>
</Configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true" scanPeriod="30 seconds">
<property name="encoder.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{req.xForwardedFor} %X{req.method} %X{req.requestURL} %X{req.queryString} %X{req.userAgent} %-5level %logger{36} - %msg%n"/>
<property name="rollingPolicy.maxFileSize" value="5MB"/>
<property name="rollingPolicy.maxHistory" value="30"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>${encoder.pattern}</pattern>
</encoder>
</appender>
<appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${encoder.pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>TRACE</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/trace.%i.log</fileNamePattern>
<maxHistory>${rollingPolicy.maxHistory}</maxHistory>
<maxFileSize>${rollingPolicy.maxFileSize}</maxFileSize>
</rollingPolicy>
</appender>
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${encoder.pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/info.%i.log</fileNamePattern>
<maxHistory>${rollingPolicy.maxHistory}</maxHistory>
<maxFileSize>${rollingPolicy.maxFileSize}</maxFileSize>
</rollingPolicy>
</appender>
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${encoder.pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/debug.%i.log</fileNamePattern>
<maxHistory>${rollingPolicy.maxHistory}</maxHistory>
<maxFileSize>${rollingPolicy.maxFileSize}</maxFileSize>
</rollingPolicy>
</appender>
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${encoder.pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/warn.%i.log</fileNamePattern>
<maxHistory>${rollingPolicy.maxHistory}</maxHistory>
<maxFileSize>${rollingPolicy.maxFileSize}</maxFileSize>
</rollingPolicy>
</appender>
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${encoder.pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/error.%i.log</fileNamePattern>
<maxHistory>${rollingPolicy.maxHistory}</maxHistory>
<maxFileSize>${rollingPolicy.maxFileSize}</maxFileSize>
</rollingPolicy>
</appender>
<!--logger-->
<logger name="com.ibatis" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" />
<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" />
<logger name="java.sql.Connection" level="DEBUG" />
<logger name="java.sql.Statement" level="DEBUG" />
<logger name="java.sql.PreparedStatement" level="DEBUG" />
<!--root-->
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="INFO" />
<appender-ref ref="ERROR" />
</root>
</configuration>
\ No newline at end of file
......@@ -40,12 +40,12 @@
product_type, source_type, login_type,
login_ip, login_time, login_status,
create_id, create_time, modify_id,
modify_time, delete_flag,token)
modify_time, delete_flag,token,is_login,user_token_tourist)
values (#{acctId,jdbcType=INTEGER}, #{acctName,jdbcType=VARCHAR},
#{productType,jdbcType=TINYINT}, #{sourceType,jdbcType=TINYINT}, #{loginType,jdbcType=TINYINT},
#{loginIp,jdbcType=VARCHAR}, #{loginTime,jdbcType=TIMESTAMP}, #{loginStatus,jdbcType=TINYINT},
#{createId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=INTEGER},
#{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT},#{token})
#{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT},#{token},#{isLogin},#{userTokenTourist})
</insert>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册