提交 4dbf8f79 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

1.协议名称获取

2.首次唤起app签订协议接口
3.统一校验接口
4.微信授权登录接口增加入参区分
上级 c5ee68c9
流水线 #21855 已失败 于阶段
in 1 second
......@@ -151,6 +151,12 @@
<artifactId>xxl-job-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.pica.cloud.patient</groupId>
<artifactId>pica-cloud-smartcontract-client</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<dependencyManagement>
......
......@@ -45,4 +45,9 @@ public class Constants {
*/
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/** 密码登录错误次数缓存key */
public static final String PWD_ERROR_NUM_KEY = "pwd-error-{mobile}";
/** 密码登录错误次数缓存时长*/
public static final int PWD_ERROR_NUM_SECONDS = 24 * 60 * 60;
}
......@@ -15,6 +15,7 @@ import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.entity.DeviceInfo;
import com.pica.cloud.foundation.utils.utils.CommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -206,4 +207,15 @@ public class LoginController extends AccountBaseController {
}
return PicaResponse.toResponse(resultWeb);
}
@ApiOperation(value = "统一校验(传空则不会校验)")
@PostMapping("/unifiedVerification")
public PicaResponse unifiedVerification(@RequestBody EncryptEntity entity) throws Exception{
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
return PicaResponse.toResponse(loginService.preLoginValidate(
request,
super.getDeviceInfo("deviceId"),
super.getIpAddr()));
}
}
// Copyright 2016-2101 Pica.
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.service.ProtocolService;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.patient.smartcontract.common.req.BatchSignReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @ClassName ProtocolController
* @Description 协议相关
* @Author Chongwen.jiang
* @Date 2020/2/20 10:48
* @ModifyDate 2020/2/20 10:48
* @Version 1.0
*/
@Api(description = "协议相关")
@RequestMapping("/protocol")
@RestController
public class ProtocolController extends AccountBaseController {
@Autowired
private ProtocolService protocolService;
@ApiOperation(value = "批量查询指定类型协议")
@GetMapping("/names")
public PicaResponse get(){
return PicaResponse.toResponse(
protocolService.getProtocolNames());
}
@ApiOperation(value = "首次唤起App签订协议")
@PostMapping("/firstCallApp")
public PicaResponse firstCallApp(@RequestBody BatchSignReq req){
String appVersion = super.getDeviceInfo("appVersion");
protocolService.firstCallAppSignProtocol(req, appVersion);
return PicaResponse.toResponse();
}
}
......@@ -29,7 +29,13 @@ public enum AccountExceptionEnum {
PICA_WECHAT_CODE_ERROR("216521", "微信登录授权code不正确"),
PICA_WECHAT_UNBIND("216522", "该微信号已绑定其他云鹊医账户,你可以使用微信登录云鹊医,在「设置」页解除绑定"),
PICA_WECHAT_BIND_OTHER("216524", "该手机号已绑定其他微信号,你可以在「设置」页解除绑定"),
PICA_WECHAT_UNBIND_CURRENT("216523", "正在绑定中,请稍等");
PICA_WECHAT_UNBIND_CURRENT("216523", "正在绑定中,请稍等"),
PICA_PASSWORD_RULE_ERROR("216525","请设置正确的密码格式"),
PICA_PWD_ERROR("216526", "密码错误,请重试"),
PICA_PWD_ERROR_2("216527", "密码错误次数过多,请前往找回密码"),
PICA_APPLE_BIND_OTHER("216528", "该手机号已绑定其他苹果账号"),
xxx_xxx("","");
private String code;
......
package com.pica.cloud.account.account.server.enums;
/**
* @Description 统一校验业务类型枚举类
* @Author Chongwen.jiang
* @Date 2020/2/20 18:19
* @ModifyDate 2020/2/20 18:19
* @Params
* @Return
*/
public enum BizTypeEnum {
LOGIN_AUTH_CODE(1, "验证码登录"),
LOGIN_PWD(2, "密码登录"),
FIND_PASSWORD(3, "找回密码"),
LOGIN_WE_CHAT(4, "微信登录"),
LOGIN_APPLE(5, "苹果登录"),
XXX(10, "xxxxxx");
private Integer code;
private String type;
BizTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.pica.cloud.account.account.server.enums;
/**
* @Description 统一校验响应枚举类
* @Author Chongwen.jiang
* @Date 2020/2/20 18:19
* @ModifyDate 2020/2/20 18:19
* @Params
* @Return
*/
public enum BizTypeRespEnum {
MOBILE_REG_FALSE(1, "请输入正确的手机号"),
MOBILE_REG_TRUE(2, "手机号符合规则"),
RC_TRIGGER(3, "需要触发风控滑动验证"),
RC_NOT_TRIGGER(4, "不需要触发风控滑动验证"),
MOBILE_NOT_REGIST(5, "该手机号{mobile}尚未设置密码,请先设置密码。"),
MOBILE_REGISTED(6, "手机号已注册"),
MOBILE_NOT_SETED_PASSWORD(7, "该手机号{mobile}尚未设置密码,请先设置密码。"),
MOBILE_SETED_PASSWORD(8, "手机号未设置密码"),
PWD_REG_FALSE(9, "请设置正确的密码格式"),
PWD_REG_TRUE(10, "密码格式正确"),
PWD_MATCH_DB(11, "密码正确"),
PWD_MISMATCH_4(12, "密码错误,请重试"),
PWD_MISMATCH_5(13, "密码错误次数过多,请前往找回密码"),
MOBILE_BINDED_WECHAT(14, "该手机号已绑定其他微信号,你可以在「设置」页解除绑定"),
MOBILE_NOT_BINDED_WECHAT(15, "该手机号未绑定微信"),
MOBILE_BINDED_APPLE(16, "该手机号已绑定其他苹果账号"),
MOBILE_NOT_BINDED_APPLE(17, "该手机号未绑定苹果账号"),
LOGIN_PWD(2, "密码登录"),
FIND_PASSWORD(3, "找回密码"),
LOGIN_WE_CHAT(4, "微信登录"),
LOGIN_APPLE(5, "苹果登录"),
XXX(10, "xxxxxx");
private Integer code;
private String msg;
BizTypeRespEnum(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setType(String msg) {
this.msg = msg;
}
}
......@@ -34,6 +34,10 @@ public class BaseRequest {
private String captchaToken;
@ApiModelProperty("图片验证码答案")
private String captchaAnswer;
@ApiModelProperty("苹果用户id")
private String appleUserId;
@ApiModelProperty("业务类型,1-验证码登录,2-密码登录,3-找回密码,4-微信登录,5-Apple登录")
private Integer bizType;
public String getCaptchaToken() {
return captchaToken;
......@@ -146,4 +150,20 @@ public class BaseRequest {
public void setWeChatLoginType(Integer weChatLoginType) {
this.weChatLoginType = weChatLoginType;
}
public String getAppleUserId() {
return appleUserId;
}
public void setAppleUserId(String appleUserId) {
this.appleUserId = appleUserId;
}
public Integer getBizType() {
return bizType;
}
public void setBizType(Integer bizType) {
this.bizType = bizType;
}
}
// Copyright 2016-2101 Pica.
package com.pica.cloud.account.account.server.resp;
import io.swagger.annotations.ApiModel;
/**
* @ClassName UnifiedVerificationResp
* @Description 统一验证响应类
* @Author Chongwen.jiang
* @Date 2020/2/20 20:48
* @ModifyDate 2020/2/20 20:48
* @Version 1.0
*/
@ApiModel(value = "UnifiedVerificationResp", description = "统一验证响应类")
public class UnifiedVerificationResp {
private Integer bizCode;
private String bizMsg;
public Integer getBizCode() {
return bizCode;
}
public void setBizCode(Integer bizCode) {
this.bizCode = bizCode;
}
public String getBizMsg() {
return bizMsg;
}
public void setBizMsg(String bizMsg) {
this.bizMsg = bizMsg;
}
}
......@@ -3,6 +3,10 @@ package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.entity.LoginResult;
import com.pica.cloud.account.account.server.entity.PICAPDoctor;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.resp.UnifiedVerificationResp;
import com.pica.cloud.foundation.entity.PicaResponse;
import java.util.Map;
public interface LoginService {
/**
......@@ -52,4 +56,14 @@ public interface LoginService {
String bindWeChat(long doctorId, BaseRequest request);
PICAPDoctor queryDoctor(long doctorId);
/**
* @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
*/
UnifiedVerificationResp preLoginValidate(BaseRequest request,String deviceId, String ip);
}
// Copyright 2016-2101 Pica.
package com.pica.cloud.account.account.server.service;
import com.pica.cloud.patient.smartcontract.common.req.BatchSignReq;
import com.pica.cloud.patient.smartcontract.common.resp.ProtocolResp;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @ClassName ProtocolService
* @Description 协议相关接口
* @Author Chongwen.jiang
* @Date 2020/2/20 11:00
* @ModifyDate 2020/2/20 11:00
* @Version 1.0
*/
public interface ProtocolService {
/**
* @Description 批量查询指定类型协议
* @Author Chongwen.jiang
* @Date 2020/2/20 11:27
* @ModifyDate 2020/2/20 11:27
* @Params [protocolTypes, appVersion]
* @Return java.util.List<com.pica.cloud.patient.smartcontract.common.resp.ProtocolResp>
*/
List<ProtocolResp> getProtocolNames();
/**
* @Description 首次唤起app签订协议
* @Author Chongwen.jiang
* @Date 2020/2/20 11:31
* @ModifyDate 2020/2/20 11:31
* @Params [req]
* @Return void
*/
void firstCallAppSignProtocol(@RequestBody BatchSignReq req, String appVersion);
}
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.constants.Constants;
import com.pica.cloud.account.account.server.entity.*;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import com.pica.cloud.account.account.server.enums.AccountTypeEnum;
import com.pica.cloud.account.account.server.enums.BizTypeEnum;
import com.pica.cloud.account.account.server.enums.BizTypeRespEnum;
import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.mapper.*;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.resp.UnifiedVerificationResp;
import com.pica.cloud.account.account.server.service.DoctorService;
import com.pica.cloud.account.account.server.service.LoginService;
import com.pica.cloud.account.account.server.service.RegisterService;
......@@ -19,14 +23,15 @@ import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -67,7 +72,6 @@ public class LoginServiceImpl implements LoginService {
private DoctorService doctorService;
@Autowired
private ICacheClient redisClient;
@Value("${doubleWritingMode}")
......@@ -79,9 +83,14 @@ public class LoginServiceImpl implements LoginService {
private String appSecret;
@Value("${weChatURL}")
private String weChatURL;
@Value("${weChatAppIDH5}")
private String appIdH5;
@Value("${weChatAppSecretH5}")
private String appSecretH5;
private static final String DEFAULT_DOCTOR_PICTURE_URL = "/File/doctor_default.png";
public static Map<String, String> PIC_TYPE_MAP = new HashMap();
static {
PIC_TYPE_MAP.put("jpg", "FFD8FF");
PIC_TYPE_MAP.put("jpeg", "FFD8FF");
......@@ -107,7 +116,7 @@ public class LoginServiceImpl implements LoginService {
Integer acctId = accountInfoEntity.getId();
int productType = request.getProductType();
int sourceType = request.getSourceType();
Doctor doctorInfo=doctorInfoMapper.getDoctorInfoByMobile(encrypt);
Doctor doctorInfo = doctorInfoMapper.getDoctorInfoByMobile(encrypt);
Integer userId = 0;
if (productType == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
userId = doctorInfo.getId();
......@@ -126,7 +135,7 @@ public class LoginServiceImpl implements LoginService {
result.setToken(newToken);
result.setUserId(userId.longValue());
result.setMobile(mobile);
result.setDoctorId(EncryptUtils.encryptContent(userId+"", EncryptConstants.ENCRYPT_TYPE_ID));
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
if (productType == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
result.setEntireFlag(doctorInfo.getEntireFlag());
}
......@@ -152,7 +161,7 @@ public class LoginServiceImpl implements LoginService {
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfoEntity == null) {
//说明是注册功能
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(),baseRequest.getFlag()+"",baseRequest.getAuthCode());
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(), baseRequest.getFlag() + "", baseRequest.getAuthCode());
return registerService.register(baseRequest);
} else {
//登录功能
......@@ -180,7 +189,7 @@ public class LoginServiceImpl implements LoginService {
result.setToken(newToken);
result.setUserId(userId);
result.setMobile(baseRequest.getMobile());
result.setDoctorId(EncryptUtils.encryptContent(userId+"", EncryptConstants.ENCRYPT_TYPE_ID));
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
//是否完善过个人信息(云鹊医app才需要)
if (baseRequest.getProductType() == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
Doctor doctorEntity = doctorInfoMapper.selectByPrimaryKey(userId.intValue());
......@@ -193,11 +202,17 @@ public class LoginServiceImpl implements LoginService {
return result;
}
@Override
@Transactional
public LoginResult loginByWeChat(BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
WeChatEntity weChatEntity = null;
if (request.getFlag() == 1) {
// h5微信登录
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());
}
......@@ -224,8 +239,8 @@ public class LoginServiceImpl implements LoginService {
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));
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());
......@@ -240,7 +255,7 @@ public class LoginServiceImpl implements LoginService {
}
LoginResult result = new LoginResult();
result.setUnionId(unionId);
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode()+"");
result.setBindFlag(AccountTypeEnum.BIND_STATUS_FAILURE.getCode() + "");
return result;
}
}
......@@ -254,7 +269,7 @@ public class LoginServiceImpl implements LoginService {
result = registerService.register(request);
if (doubleWritingMode) {
//双写模式下,要在doctor表存储unionId
if (result.getUserId()!=null) {
if (result.getUserId() != null) {
Doctor doctor = new Doctor();
doctor.setId(result.getUserId().intValue());
doctor.setUnionid(request.getUnionId());
......@@ -267,7 +282,7 @@ public class LoginServiceImpl implements LoginService {
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId(),request.getProductType());
processAccountUnion(acctId, request.getUnionId(), request.getProductType());
return result;
}
......@@ -298,7 +313,7 @@ public class LoginServiceImpl implements LoginService {
updateWechatInfoUser(entity, weChatUserInfoEntity);
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId,request.getProductType());
processAccountUnion(acctId, unionId, request.getProductType());
return weChatUserInfoEntity.getNickname();
}
......@@ -308,14 +323,14 @@ public class LoginServiceImpl implements LoginService {
* @param acctId
* @param unionId
*/
private void processAccountUnion(Integer acctId, String unionId,Integer productType) {
private void processAccountUnion(Integer acctId, String unionId, Integer productType) {
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
AccountUnionEntity accountUnionResult = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionResult!=null){
if (accountUnionResult != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
}
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(acctId);
if (accountUnionEntityAccount!=null){
if (accountUnionEntityAccount != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
......@@ -370,6 +385,7 @@ public class LoginServiceImpl implements LoginService {
}
}
@Override
public PICAPDoctor queryDoctor(long doctorId) {
PICAPDoctor doctor = doctorInfoMapper.queryDoctor(doctorId);
if (doctor == null) {
......@@ -392,4 +408,187 @@ public class LoginServiceImpl implements LoginService {
}
}
}
/**
* @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 UnifiedVerificationResp preLoginValidate(BaseRequest request,
String deviceId,
String ip) {
UnifiedVerificationResp resp = new UnifiedVerificationResp();
Integer bizType = request.getBizType();
String mobile = request.getMobile();
String password = request.getPassword();
// 手机号规则校验
if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) {
resp.setBizCode(BizTypeRespEnum.MOBILE_REG_FALSE.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_REG_FALSE.getMsg());
} else {
resp.setBizCode(BizTypeRespEnum.MOBILE_REG_TRUE.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_REG_TRUE.getMsg());
}
if (null == bizType) {
logger.info("bizType is null");
return resp;
}
if (BizTypeEnum.LOGIN_AUTH_CODE.getCode().equals(bizType)) {
// TODO 局域网ip
invokeRCInterface(resp, mobile, ip, deviceId, "");
} else if (BizTypeEnum.LOGIN_PWD.getCode().equals(bizType)) {
// 密码登录相关校验
pwdLoginPreValidate(resp, mobile, password);
} else if (BizTypeEnum.FIND_PASSWORD.getCode().equals(bizType)) {
if (StringUtils.isNotEmpty(password)) {
// 判断密码格式是否正确
if (AccountUtils.checkPasswordRule(password)) {
resp.setBizCode(BizTypeRespEnum.PWD_REG_FALSE.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_REG_FALSE.getMsg());
} else {
resp.setBizMsg(BizTypeRespEnum.PWD_REG_TRUE.getMsg());
resp.setBizCode(BizTypeRespEnum.PWD_REG_TRUE.getCode());
// TODO 局域网ip
invokeRCInterface(resp, mobile, ip, deviceId, "");
}
}
} else if (BizTypeEnum.LOGIN_WE_CHAT.getCode().equals(bizType)) {
if(StringUtils.isNotEmpty(mobile)) {
// 判断手机号是否绑定了微信
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(
AESUtil.encryptV0(mobile));
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(accountInfo.getId());
if (accountUnionEntityAccount != null) {
resp.setBizCode(BizTypeRespEnum.MOBILE_BINDED_WECHAT.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_BINDED_WECHAT.getMsg());
} else {
resp.setBizCode(BizTypeRespEnum.MOBILE_NOT_BINDED_WECHAT.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_NOT_BINDED_WECHAT.getMsg());
// TODO 局域网ip
invokeRCInterface(resp, mobile, ip, deviceId, "");
}
}
} else if (BizTypeEnum.LOGIN_APPLE.getCode().equals(bizType)) {
if(StringUtils.isNotEmpty(mobile)) {
// 判断手机号是否绑定了苹果
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(
AESUtil.encryptV0(mobile));
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(accountInfo.getId());
if (accountUnionEntityAccount != null) {
resp.setBizCode(BizTypeRespEnum.MOBILE_BINDED_APPLE.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_BINDED_APPLE.getMsg());
} else {
resp.setBizCode(BizTypeRespEnum.MOBILE_BINDED_APPLE.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_BINDED_APPLE.getMsg());
// TODO 局域网ip
invokeRCInterface(resp, mobile, ip, deviceId, "");
}
}
}
return resp;
}
/**
* @Description 密码登录相关校验
* @Author Chongwen.jiang
* @Date 2020/2/20 22:35
* @ModifyDate 2020/2/20 22:35
* @Params [resp, mobile, password]
* @Return void
*/
private void pwdLoginPreValidate(UnifiedVerificationResp resp, String mobile, String password) {
if (StringUtils.isNotEmpty(mobile)) {
// 判断手机号是否注册(未注册,提示去找回密码,找回密码页有注册逻辑)
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfo == null) {
// 手机未注册
resp.setBizCode(BizTypeRespEnum.MOBILE_NOT_REGIST.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_NOT_REGIST.getMsg()
.replace("{mobile}", mobile));
} else {
resp.setBizCode(BizTypeRespEnum.MOBILE_REGISTED.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_REGISTED.getMsg());
// 判断手机号是否设置密码
if (StringUtils.isEmpty(accountInfo.getPassword())) {
// 未设置密码
resp.setBizCode(BizTypeRespEnum.MOBILE_NOT_SETED_PASSWORD.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_NOT_SETED_PASSWORD.getMsg()
.replace("{mobile}", mobile));
}
}
}
if (StringUtils.isNotEmpty(password)) {
// 入参密码格式校验
if (AccountUtils.checkPasswordRule(password)) {
resp.setBizCode(BizTypeRespEnum.PWD_REG_FALSE.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_REG_FALSE.getMsg());
} else {
resp.setBizCode(BizTypeRespEnum.PWD_REG_TRUE.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_REG_TRUE.getMsg());
}
// 判断密码是否正确
if (StringUtils.isNotEmpty(mobile)) {
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfo != null) {
if (!password.equals(accountInfo.getPassword())) {
// 从缓存取出当前账号密码错误次数
String key = Constants.PWD_ERROR_NUM_KEY.replace("{mobile}", mobile);
if(redisClient.exists(key)) {
int errorCount = Integer.parseInt(redisClient.get(key));
if (errorCount <= 4) {
resp.setBizCode(BizTypeRespEnum.PWD_MISMATCH_4.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_MISMATCH_4.getMsg());
} else if (errorCount > 4) {
resp.setBizCode(BizTypeRespEnum.PWD_MISMATCH_5.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_MISMATCH_5.getMsg());
}
}else{
redisClient.set(key, 1, Constants.PWD_ERROR_NUM_SECONDS);
}
} else {
// 密码正确
resp.setBizCode(BizTypeRespEnum.PWD_MATCH_DB.getCode());
resp.setBizMsg(BizTypeRespEnum.PWD_MATCH_DB.getMsg());
}
}
}
}
}
/**
* @Description 调用风控接口
* @Author Chongwen.jiang
* @Date 2020/2/20 22:24
* @ModifyDate 2020/2/20 22:24
* @Params [resp, mobile, ip(出口ip), deviceId, intranetIp(局域网ip)]
* @Return void
*/
private void invokeRCInterface(UnifiedVerificationResp resp,
String mobile, String ip,
String deviceId, String intranetIp) {
// TODO 调用风控接口
String processCode = "200";
if ("200".equals(processCode)) {
resp.setBizCode(BizTypeRespEnum.RC_NOT_TRIGGER.getCode());
resp.setBizMsg(BizTypeRespEnum.RC_NOT_TRIGGER.getMsg());
} else {
resp.setBizCode(BizTypeRespEnum.RC_TRIGGER.getCode());
resp.setBizMsg(BizTypeRespEnum.RC_TRIGGER.getMsg());
}
}
}
// Copyright 2016-2101 Pica.
package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSON;
import com.pica.cloud.account.account.server.service.ProtocolService;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.patient.smartcontract.client.SmartContractClient;
import com.pica.cloud.patient.smartcontract.common.req.BatchSignReq;
import com.pica.cloud.patient.smartcontract.common.resp.ProtocolResp;
import com.pica.cloud.patient.smartcontract.common.utils.ReturnUtil;
import groovy.util.logging.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* @ClassName ProtocolServiceImpl
* @Description 协议相关业务层
* @Author Chongwen.jiang
* @Date 2020/2/20 11:01
* @ModifyDate 2020/2/20 11:01
* @Version 1.0
*/
@Service
public class ProtocolServiceImpl implements ProtocolService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private SmartContractClient smartContractClient;
/**
* @Description 批量查询指定类型协议
* @Author Chongwen.jiang
* @Date 2020/2/20 11:26
* @ModifyDate 2020/2/20 11:26
* @Params [protocolTypes, appVersion]
* @Return java.util.List<com.pica.cloud.patient.smartcontract.common.resp.ProtocolResp>
*/
@Override
public List<ProtocolResp> getProtocolNames() {
List<Integer> protocolTypes = new ArrayList<>();
// 用户协议
protocolTypes.add(2);
// 隐私协议
protocolTypes.add(3);
// 运营商认证协议
protocolTypes.add(12);
BatchSignReq req = new BatchSignReq();
req.setTypes(protocolTypes);
PicaResponse picaResponse = smartContractClient.queryProtocol(req);
if(Objects.isNull(picaResponse)){
throw new PicaWarnException(
PicaResultCode.INTERFACE_INVOKE_EXCEPTION.code(),
PicaResultCode.INTERFACE_INVOKE_EXCEPTION.message());
}
if(!PicaResultCode.SUCCESS.code().equals(picaResponse.getCode())){
throw new PicaWarnException(
picaResponse.getCode(),
picaResponse.getMessage());
}
List<ProtocolResp> resp = JSON.parseArray(
JSON.toJSONString(picaResponse.getData()),
ProtocolResp.class);
return resp;
}
/**
* @Description 首次唤起app签订协议
* @Author Chongwen.jiang
* @Date 2020/2/20 11:31
* @ModifyDate 2020/2/20 11:31
* @Params [req]
* @Return void
*/
@Override
public void firstCallAppSignProtocol(BatchSignReq req, String appVersion) {
if(StringUtils.isEmpty(appVersion)) {
logger.info("firstCallAppSignProtocol-appVersion is null ");
return;
}
PicaResponse resp = smartContractClient.firstCallAppSignProtocol(req);
logger.info("firstCallAppSignProtocol-resp:{}", JSON.toJSONString(resp));
if(Objects.isNull(resp)){
throw new PicaWarnException(
PicaResultCode.INTERFACE_INVOKE_EXCEPTION.code(),
PicaResultCode.INTERFACE_INVOKE_EXCEPTION.message());
}
if(!PicaResultCode.SUCCESS.code().equals(resp.getCode())){
throw new PicaWarnException(
resp.getCode(),
resp.getMessage());
}
}
}
......@@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.regex.Pattern;
/**
* 账户工具类
*/
......@@ -36,20 +38,29 @@ public class AccountUtils {
private static final String AUTH_CODE_PREFIX = "authCode-";
private static final String AUTH_CODE_COUNT_PREFIX = "authCode-count-";
//手机格式校验
//手机非空和格式校验
public static void checkMobilePhone(String mobilePhone) {
if (StringUtils.isBlank(mobilePhone) || !ValidateUtils.isMobile(mobilePhone)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的手机号");
}
}
//手机格式校验
//密码非空判断
public static void checkPassword(String password) {
if (StringUtils.isBlank(password)) {
throw new PicaException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), AccountExceptionEnum.PICA_NOT_EMPTY.getMessage());
}
}
public static boolean checkPasswordRule(String password){
String regex = "^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,16})$";
boolean pass = password.matches(regex);
if(password.length() < 6 || password.length() > 16 || !pass){
return false;
}
return true;
}
//获取验证码redis key
public static String getAuthCodeKey(String mobilePhone, String flag) {
return AUTH_CODE_PREFIX + flag + "-" + AESUtil.encryptV0(mobilePhone);
......
......@@ -26,7 +26,6 @@ public class TokenUtils {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ICacheClient cacheClient;
@Autowired
......
......@@ -36,6 +36,9 @@ memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
#h5使用的云鹊医公众号
weChatAppIDH5=wx08b383d002c73f26
weChatAppSecretH5=b3a6be25c9f62423b88a3d0611f060d1
weChatURL=https://api.weixin.qq.com/sns/userinfo?
#是否开启双写模式,是否需要向p_doctor表写数据
......
......@@ -40,6 +40,8 @@ memcached.url=172.19.121.31:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatAppIDH5=wx2c577552a2d28550
weChatAppSecretH5=397a92bda46180efa2c2a235b74a409a
weChatURL=https://api.weixin.qq.com/sns/userinfo?
#是否开启双写模式,是否需要向p_doctor表写数据
......
......@@ -39,6 +39,8 @@ memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatAppIDH5=wxcaad75b7fff5659c
weChatAppSecretH5=3d6eea715bc34489b49925b3dbde9c8b
weChatURL=https://api.weixin.qq.com/sns/userinfo?
#是否开启双写模式,是否需要向p_doctor表写数据
......
......@@ -39,6 +39,8 @@ memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatAppIDH5=wx342ef0e5afee54a7
weChatAppSecretH5=3859052f07d3f87cda644bf073927ef1
weChatURL=https://api.weixin.qq.com/sns/userinfo?
#是否开启双写模式,是否需要向p_doctor表写数据
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册