提交 9a94ce34 编写于 作者: peijun.zhao's avatar peijun.zhao

add 静默注册亚测接口v3

上级 154056e6
流水线 #29037 已失败 于阶段
in 0 second
......@@ -14,6 +14,7 @@ import com.pica.cloud.account.account.server.service.CaptchaService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.account.account.server.util.IntactUtil;
import com.pica.cloud.account.account.server.util.RegisterCodeKeyUtils;
import com.pica.cloud.foundation.completeness.client.utils.IntactUtils;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
......@@ -416,6 +417,145 @@ public class AccountController extends AccountBaseController {
}
}
@ApiOperation("yace /login-register/v3")
@PostMapping("/login-register/v3")
// @RepeatForbidden(uniqueKey = "content")
//当前版本存在性能问题 luo优化后上
public PicaResponse loginRegisterV3(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
this.checkMobilePhone(request.getMobile());
//接入新旭事务一致性
String batchNo = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"entity:"+ JSON.toJSONString(entity));
AccountReq req = new AccountReq();
req.setMobilePhone(request.getMobile());
// 登录或注册,只能使用验证码
req.setPassword(null);
req.setAuthCode(request.getAuthCode());
req.setFlag("0");
req.setUnionid(request.getUnionId());
// 判断账号是否已经存在
Account account = accountService.getByMobilePhone(req.getMobilePhone());
if (account != null) {
// 登录
PicaResponse response = null;
try {
this.checkMobilePhone(req.getMobilePhone());
logger.info("login:{}", JSONObject.toJSONString(req));
//接入新旭事务一致性
String batchNo1 = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"req:"+ JSON.toJSONString(req));
Account account1 = accountService.getByMobilePhone(req.getMobilePhone()); //获取账号信息
if (account1 == null) {
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"未注册,请验证码登录");
return PicaResponse.toResponse(null, PicaResultCode.RESULE_DATA_NONE.code(), "未注册,请验证码登录");
}
if (StringUtils.isBlank(req.getPassword())) {
//验证码登录
req.setFlag("0");
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"校验验证码前的返回,因为验证码可能校验不通过,就直接返回了");
//校验验证码
// this.checkAuthCode(req);
String flag = StringUtils.isBlank(req.getFlag()) ? "0" : req.getFlag();
String authCodeKey = this.getAuthCodeKey(req.getMobilePhone(), flag);
redisClient.del(authCodeKey); //清除验证码
} else { //密码登录
if (!StringUtils.equals(req.getPassword(), account1.getPassword())) {
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"请输入正确的密码");
return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的密码");
}
}
//更新最后登录时间
Account update = new Account();
update.setId(account1.getId());
update.setLastLoginTime(new Date());
if (StringUtils.isBlank(account1.getUnionid()) && StringUtils.isNotBlank(req.getUnionid())) {
update.setUnionid(req.getUnionid()); //绑定微信unionid
update.setModifyId(account1.getId());
update.setModifyTime(new Date());
}
accountService.updateAccountById(update);
//登录成功,清除旧token,生成新token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken = this.generateTokenWebLive(account1, deviceType);
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"req:"+ JSON.toJSONString(req));
response = PicaResponse.toResponse(newToken);
} catch (PicaException e) {
if(e.getCode().equals(PicaResultCode.PARAM_IS_INVALID.code()) || e.getCode().equals(PicaResultCode.RESULE_DATA_NONE.code())){
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"验证码错误或过期-不加入提醒,返回值:"+ JSON.toJSONString(response));
}
throw e;
}
if (response.getData() != null) {
LoginResult result = new LoginResult();
result.setToken(response.getData().toString());
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"登录成功,返回值:"+ JSON.toJSONString(response.getData()));
return PicaResponse.toResponse(result);
}
return response;
} else {
// 注册
PicaResponse<LoginResult> result = null;
try {
// result = this.register(req);
this.checkMobilePhone(req.getMobilePhone());
// accountUtils.checkRegisterMobilePhoneAndAuthCode(req.getMobilePhone(),req.getFlag(),req.getAuthCode());
String authCodeKey = RegisterCodeKeyUtils.getRegisterKey(req.getMobilePhone(), req.getAuthCode());
redisClient.del(authCodeKey);
//接入新旭事务一致性
String batchNo2 = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo2,"register",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"req:"+ JSON.toJSONString(req));
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
Account account2 = new Account();
account2.setMobilePhone(EncryptUtils.encryptContent(req.getMobilePhone(), EncryptConstants.ENCRYPT_TYPE_MOBILE));
switch (deviceType) { //注册来源
case "1":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_3); //pc
break;
case "2":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_1); //android
break;
case "3":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_2); //ios
break;
default:
account2.setRegisterSource(AccountTypeEnum.DEVICE_TYPE_H5.getCode()); //H5注册
}
//创建web live账号
accountService.createAccount(account2,AccountTypeEnum.PRODUCT_TYPE_ECO_LIVE.getCode());
//生成token并返回
String newToken = this.generateTokenWebLive(account2, deviceType);
LoginResult result1 = new LoginResult();
result1.setToken(newToken);
intactUtil.sendIntact(batchNo2,"register",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"req:"+ JSON.toJSONString(req));
// return PicaResponse.toResponse(result);
result = PicaResponse.toResponse(result1);
} catch (PicaException e) {
if(e.getCode().equals(PicaResultCode.PARAM_IS_INVALID.code()) || e.getCode().equals(PicaResultCode.RESULE_DATA_NONE.code())){
intactUtil.sendIntact(batchNo,"webLive--loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"验证码错误或过期-不加入提醒,返回值:"+ JSON.toJSONString(result));
}
throw e;
}
intactUtil.sendIntact(batchNo,"webLive--loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"注册成功,返回值:"+ JSON.toJSONString(result));
return result;
}
}
//手机格式校验
private void checkMobilePhone(String mobilePhone) {
if (StringUtils.isBlank(mobilePhone) || !ValidateUtils.isMobile(mobilePhone)) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册