提交 3b876bd1 authored 作者: huyufan's avatar huyufan

交易密码相关

上级 5a881e97
......@@ -101,8 +101,12 @@ public enum PerformanceResultEnum implements ResultEnum {
USER_ID_IS_EMPTY(1900, "用户ID不能为空"),
MOBILE_IS_EMPTY(1901, "用户手机号不能为空"),
CAPTCHA_IS_EMPTY(1901, "验证码不能为空"),
USER_ACCOUNT_NOT_FOUND(1902, "用户账号未找到"),
CAPTCHA_IS_EMPTY(1902, "验证码不能为空"),
USER_ACCOUNT_NOT_FOUND(1903, "用户账号未找到"),
CAPTCHA_IS_EXPIRE(1904, "验证码已失效,请重新发送"),
CAPTCHA_MORE_COUNT(1905, "验证码发送过于频繁,请稍后再发"),
CAPTCHA_IS_FAIL(1906, "验证码错误"),
BUSINESS_NO_FAIL(1907, "营业执照校验不一致,请重新输入"),
;
......
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......@@ -8,20 +9,17 @@ import lombok.Setter;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Getter
@Setter
@NoArgsConstructor
@Data
public class CheckMobileParam {
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
@ApiModelProperty(value = "用户Id", example = "1")
@NotNull(message = "用户Id")
private Long userNo;
@ApiModelProperty(value = "验证码", example = "1")
@NotBlank(message = "验证码")
private String captcha;
@ApiModelProperty(value = "调用发送短信接口返回的token", example = "1")
private String token;
}
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class InformationParam {
@ApiModelProperty(value = "营业执照编号", example = "1")
@NotBlank(message = "营业执照编号")
private String businessLicenseNumber;
@ApiModelProperty(value = "验证手机号通过后Token", example = "1")
@NotBlank(message = "验证手机号通过后Token")
private String token;
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
}
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
public class SendMobileCaptchaParam {
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
}
package com.clx.performance.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ResetPassword {
//接口名称
String name() default "";
}
package com.clx.performance.aspect;
import cn.hutool.json.JSONUtil;
import com.clx.performance.annotation.ResetPassword;
import com.clx.performance.constant.RedisConstants;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Component
@Aspect
public class ResetPasswordAnnotationAop {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Pointcut("@annotation(com.clx.performance.annotation.ResetPassword)")
private void annotationPointCut() {
}
@Around("annotationPointCut()")
public Object annotationAround(ProceedingJoinPoint jp) throws Throwable {
//获取方法
Method method = ((MethodSignature) jp.getSignature()).getMethod();
// 获取AspectAnnotation注解
ResetPassword aspectAnnotation = method.getAnnotation(ResetPassword.class);
String mobile = "";
if (aspectAnnotation.name().equals("checkMobile")) {
CheckMobileParam bean = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), CheckMobileParam.class);
mobile = JSONUtil.parse(jp.getArgs()[0]).getByPath("mobile").toString();
String token = bean.getToken();
String redisVal = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile);
if (!StringUtils.equals(token, redisVal)) {
throw new RuntimeException("抛异常");
}
} else if (aspectAnnotation.name().equals("sendMobileCaptcha")) {
mobile = JSONUtil.parse(jp.getArgs()[0]).getByPath("mobile").toString();
String content = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_CAPTCHA_ID + mobile);
if (StringUtils.isNoneBlank(content)) {
String token = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, token);
redisTemplate.expire(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, 60, TimeUnit.SECONDS);
return token;
}
String count = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_CAPTCHA_MOBILE_COUNT + mobile);
if (StringUtils.isNotBlank(content) && Integer.parseInt(count) >= 10) {
throw new ServiceSystemException(PerformanceResultEnum.CAPTCHA_MORE_COUNT);
}
} else if (aspectAnnotation.name().equals("checkBusinessLicenseNumber")) {
InformationParam bean = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), InformationParam.class);
mobile = JSONUtil.parse(jp.getArgs()[0]).getByPath("mobile").toString();
String token = bean.getToken();
String redisVal = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile);
if (!StringUtils.equals(token, redisVal)) {
throw new RuntimeException("抛异常");
}
}
//执行方法前
Object returnVal = null;
returnVal = jp.proceed();
Result result = JSONUtil.toBean(JSONUtil.parse(returnVal).toString(), Result.class);
if (aspectAnnotation.name().equals("sendMobileCaptcha")) {
//执行方法后
redisTemplate.opsForValue().increment(RedisConstants.MESSAGE_CAPTCHA_MOBILE_COUNT + mobile);
redisTemplate.expire(RedisConstants.MESSAGE_CAPTCHA_MOBILE_COUNT + mobile, 60, TimeUnit.SECONDS);
}
redisTemplate.opsForValue().set(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, result.getData().toString());
redisTemplate.expire(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, 60, TimeUnit.SECONDS);
return returnVal;
}
private static Map<String, Object> getFieldsName(ProceedingJoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
String[] parameterNames = pnd.getParameterNames(method);
Map<String, Object> paramMap = new HashMap<>(8);
for (int i = 0; i < parameterNames.length; i++) {
paramMap.put(parameterNames[i], args[i]);
}
return paramMap;
}
}
......@@ -31,4 +31,10 @@ public class RedisConstants {
* 雪花
*/
public static final String ID_SNOWFLAKE = "clx-performance:idsnowflake";
public static final String MESSAGE_CAPTCHA_ID = "message:expire:";
public static final String MESSAGE_CAPTCHA_MOBILE_COUNT = "message:mobile:count:";
public static final String MESSAGE_RESET_PASSWORD_TOKEN = "message:resetpassword:token:";
}
package com.clx.performance.controller.app;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.annotation.ResetPassword;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.clx.performance.param.pc.PageAppPrepaidFreightAccountParam;
import com.clx.performance.service.OwnerAccountService;
import com.clx.performance.vo.pc.OwnerAccountRunningWaterRecordVO;
......@@ -40,8 +43,25 @@ public class AppOwnerAccountController {
@ApiOperation(value = "验证手机号验证码", notes = "<br>By:胡宇帆")
@PostMapping("/checkMobile")
@ResetPassword(name = "checkMobile")
public Result<String> checkMobile(@RequestBody CheckMobileParam param) {
String token = ownerAccountService.checkMobile(param);
return Result.ok(token);
}
@ApiOperation(value = "发送手机验证码", notes = "<br>By:胡宇帆")
@PostMapping("/sendMobileCaptcha")
@ResetPassword(name = "sendMobileCaptcha")
public Result<String> sendMobileCaptcha(@RequestBody SendMobileCaptchaParam param) {
String token = ownerAccountService.sendMobileCaptcha(param);
return Result.ok(token);
}
@ApiOperation(value = "验证营业执照编号", notes = "<br>By:胡宇帆")
@PostMapping("/checkBusinessLicenseNumber")
@ResetPassword(name = "checkBusinessLicenseNumber")
public Result<String> checkBusinessLicenseNumber(@RequestBody InformationParam param) {
String token = ownerAccountService.checkBusinessLicenseNumber(param);
return Result.ok(token);
}
}
......@@ -3,6 +3,8 @@ package com.clx.performance.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.model.OwnerTransferInfo;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.clx.performance.param.open.OpenOwnerBindCardParam;
import com.clx.performance.param.open.OpenOwnerCaseOutParam;
import com.clx.performance.param.open.OpenOwnerTopUpParam;
......@@ -92,4 +94,8 @@ public interface OwnerAccountService {
void ownerAccountThaw(ThawAccountParam param);
String checkMobile(CheckMobileParam param);
String sendMobileCaptcha(SendMobileCaptchaParam param);
String checkBusinessLicenseNumber(InformationParam param);
}
......@@ -2,16 +2,22 @@ package com.clx.performance.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.message.feign.ClxMessageOpenapiFeign;
import com.clx.message.req.message.AliSmsMessageReq;
import com.clx.performance.component.IdGenerateSnowFlake;
import com.clx.performance.config.ClxMessageConfig;
import com.clx.performance.constant.RedisConstants;
import com.clx.performance.dao.*;
import com.clx.performance.enums.IdTypeEnum;
import com.clx.performance.enums.OwnerAccountEnum;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.model.*;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.clx.performance.param.open.OpenOwnerBindCardParam;
import com.clx.performance.param.open.OpenOwnerCaseOutParam;
import com.clx.performance.param.open.OpenOwnerTopUpParam;
......@@ -28,12 +34,14 @@ import com.clx.performance.utils.excel.ExcelUtil;
import com.clx.performance.vo.pc.OwnerAccountAllVO;
import com.clx.performance.vo.pc.OwnerAccountRunningWaterRecordVO;
import com.clx.performance.vo.pc.OwnerAccountVO;
import com.clx.user.enums.driver.DriverTruckEnum;
import com.clx.user.feign.OwnerFeign;
import com.clx.user.feign.OwnerInfoFeign;
import com.clx.user.param.pc.owner.UpdateOwnerBindCardFeignParam;
import com.clx.user.vo.pc.driver.truck.DriverTruckVo;
import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.clx.user.vo.pc.owner.OwnerBindCardVO;
import com.msl.common.base.Optional;
import com.msl.common.enums.ResultCodeEnum;
import com.msl.common.enums.ResultEnum;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import com.msl.user.data.UserSessionData;
......@@ -42,12 +50,15 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Slf4j
@Service
......@@ -74,6 +85,12 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
private final ClxMessageOpenapiFeign clxMessageOpenapiFeign;
private final ClxMessageConfig messageConfig;
private final RedisTemplate<String,String> redisTemplate;
private final OwnerFeign ownerFeign;
@Override
public IPage<OwnerAccountVO> pageList(PageOwnerAccountListParam param) {
return ownerAccountDao.pageList(param);
......@@ -888,7 +905,7 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
@Override
public String checkMobile(CheckMobileParam param) {
Long userNo = param.getUserNo();
Long userNo = TokenUtil.getLoginUserInfo().getUserNo();
if (ObjectUtil.isNull(userNo)) {
throw new ServiceSystemException(PerformanceResultEnum.USER_ID_IS_EMPTY);
}
......@@ -901,12 +918,56 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
throw new ServiceSystemException(PerformanceResultEnum.CAPTCHA_IS_EMPTY);
}
List<OwnerAccount> accountList = ownerAccountDao.accountInfo(param.getUserNo());
List<OwnerAccount> accountList = ownerAccountDao.accountInfo(userNo);
if (CollectionUtil.isEmpty(accountList)) {
throw new ServiceSystemException(PerformanceResultEnum.USER_ACCOUNT_NOT_FOUND);
}
String content = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_CAPTCHA_ID + param.getMobile());
if (StringUtils.isBlank(content)) {
throw new ServiceSystemException(PerformanceResultEnum.CAPTCHA_IS_EXPIRE);
}
return null;
Object code = JSONUtil.parse(content).getByPath("code");
if (!ObjectUtil.equal(code,param.getCaptcha())) {
throw new ServiceSystemException(PerformanceResultEnum.CAPTCHA_IS_FAIL);
}
return UUID.randomUUID().toString();
}
@Override
public String sendMobileCaptcha(SendMobileCaptchaParam param) {
AliSmsMessageReq req = new AliSmsMessageReq();
req.setTemplateCode(messageConfig.getCaptchaTemplateCode());
JSONObject jsonObject = new JSONObject();
//随机生成4位数字
jsonObject.set("code", (int) (Math.random() * 9000) + 1000);
//默认3分钟
jsonObject.set("time", "3");
req.setChannelId(messageConfig.getChannelId());
req.setAppId(messageConfig.getAppId().toString());
req.setMobile(param.getMobile());
req.setContent(jsonObject.toString());
req.setExpire(300L);
clxMessageOpenapiFeign.sendAliSms(req);
return UUID.randomUUID().toString();
}
@Override
public String checkBusinessLicenseNumber(InformationParam param) {
Long userNo = TokenUtil.getLoginUserInfo().getUserNo();
OwnerInfoFeignVO ownerInfoFeignVO = Optional.ofNullable(ownerFeign.getUserCompany(userNo)).filter(Result::succeed).map(Result::getData).orElseThrow(ResultCodeEnum.FAIL);
String companyBusinessNo = ownerInfoFeignVO.getCompanyBusinessNo();
if (StringUtils.isBlank(companyBusinessNo)) {
throw new ServiceSystemException(PerformanceResultEnum.DATA_NOT_FIND);
}
if (!StringUtils.equals(companyBusinessNo, param.getBusinessLicenseNumber())) {
throw new ServiceSystemException(PerformanceResultEnum.BUSINESS_NO_FAIL);
}
return UUID.randomUUID().toString();
}
}
......@@ -318,9 +318,9 @@ public class OrderGoodsSqlProvider {
WHERE("a.residue_transport_weight >=35");
if (ObjectUtil.isNotNull(param.getSearchType())) {
if (1 == param.getSearchType()) {
WHERE("a.send_address = "+ param.getSearchName());
WHERE("a.send_address_shorter = "+ param.getSearchName());
}else if (2 == param.getSearchType()) {
WHERE("a.receive_address = "+ param.getSearchName());
WHERE("a.receive_address_shorter = "+ param.getSearchName());
}
}
ORDER_BY("a.pending_order_time desc");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论