|
@@ -10,6 +10,7 @@ import com.fdage.controller.BaseController;
|
|
import fdage.back.sdk.base.entity.Result;
|
|
import fdage.back.sdk.base.entity.Result;
|
|
import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
import fdage.back.sdk.base.exception.CommonBaseException;
|
|
import fdage.back.sdk.base.exception.CommonBaseException;
|
|
|
|
+import fdage.back.sdk.core.alibabaUtils.AlibabaSmsService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
@@ -18,8 +19,12 @@ import lombok.extern.log4j.Log4j2;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 2 * @Author: Abner
|
|
* 2 * @Author: Abner
|
|
@@ -32,9 +37,17 @@ import org.springframework.web.bind.annotation.*;
|
|
@Log4j2
|
|
@Log4j2
|
|
public class AppOrderController extends BaseController {
|
|
public class AppOrderController extends BaseController {
|
|
|
|
|
|
|
|
+ public static String MSG_AUTH_CODE_REDIS_kEY = "msg:auth:code:";
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private TmOrderServiceImpl tmOrderService;
|
|
private TmOrderServiceImpl tmOrderService;
|
|
|
|
|
|
|
|
+ @Value("${sms.template.id}")
|
|
|
|
+ private String smsTemplateId;
|
|
|
|
+
|
|
|
|
+ @Value("${sms.common.sign}")
|
|
|
|
+ private String smsCommonSign;
|
|
|
|
+
|
|
@GetMapping("/listByUser")
|
|
@GetMapping("/listByUser")
|
|
@ApiOperation(value = "拉取用户所有订单列表")
|
|
@ApiOperation(value = "拉取用户所有订单列表")
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParams({
|
|
@@ -64,6 +77,7 @@ public class AppOrderController extends BaseController {
|
|
})
|
|
})
|
|
public Result<TmOrder> getOneById(@RequestParam(name = "orderId") String orderId){
|
|
public Result<TmOrder> getOneById(@RequestParam(name = "orderId") String orderId){
|
|
if(StringUtils.isBlank(orderId)){
|
|
if(StringUtils.isBlank(orderId)){
|
|
|
|
+
|
|
return Result.failure("订单ID缺失");
|
|
return Result.failure("订单ID缺失");
|
|
}
|
|
}
|
|
TmOrder tmOrder = tmOrderService.getById(orderId);
|
|
TmOrder tmOrder = tmOrderService.getById(orderId);
|
|
@@ -95,7 +109,8 @@ public class AppOrderController extends BaseController {
|
|
return Result.failure("短信验证码缺失");
|
|
return Result.failure("短信验证码缺失");
|
|
}
|
|
}
|
|
//校验短信验证码
|
|
//校验短信验证码
|
|
- String redisCOde = (String) redisTemplate.opsForValue().get(orderAppReqDto.getReserveUserPhone());
|
|
|
|
|
|
+ String redisAuthCodeKey = MSG_AUTH_CODE_REDIS_kEY + orderAppReqDto.getReserveUserPhone();
|
|
|
|
+ String redisCOde = (String) redisTemplate.opsForValue().get(redisAuthCodeKey);
|
|
if(!StringUtils.equals(redisCOde , orderAppReqDto.getMsgCode())){
|
|
if(!StringUtils.equals(redisCOde , orderAppReqDto.getMsgCode())){
|
|
return Result.failure("验证码非法或者已经过了有效期");
|
|
return Result.failure("验证码非法或者已经过了有效期");
|
|
}
|
|
}
|
|
@@ -105,4 +120,33 @@ public class AppOrderController extends BaseController {
|
|
return Result.success(newOrder);
|
|
return Result.success(newOrder);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @GetMapping("/getMsgAuthCode")
|
|
|
|
+ @ApiOperation(value = "获取短信验证码")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "phoneNum", value = "手机号", paramType = "query", required = true, dataType = "String")
|
|
|
|
+ })
|
|
|
|
+ public Result<Object> getMsgAuthCode(@RequestParam(name = "phoneNum") String phoneNum){
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isBlank(phoneNum)){
|
|
|
|
+ return Result.failure("手机号缺失");
|
|
|
|
+ }
|
|
|
|
+ if(!Pattern.matches("^[1][3-5,7-8]\\d{9}$" , phoneNum)){
|
|
|
|
+ return Result.failure("手机号非法");
|
|
|
|
+ }
|
|
|
|
+ String code = String.valueOf((int)((Math.random()*9+1)*100000));
|
|
|
|
+ String param = "{\"code\":\"" + code + "\"}";
|
|
|
|
+ boolean smsResult = AlibabaSmsService.sendSmsWithSignName(phoneNum , param , smsTemplateId , smsCommonSign);
|
|
|
|
+ if(smsResult){
|
|
|
|
+ log.info("给用户[{}]发送验证码[{}]的短信成功" , phoneNum , code);
|
|
|
|
+ String redisKey = MSG_AUTH_CODE_REDIS_kEY + phoneNum;
|
|
|
|
+ if(redisTemplate.hasKey(redisKey)){
|
|
|
|
+ redisTemplate.delete(redisKey);
|
|
|
|
+ }
|
|
|
|
+ redisTemplate.opsForValue().set(redisKey , code , 300L , TimeUnit.SECONDS);
|
|
|
|
+ }else{
|
|
|
|
+ log.info("给用户[{}]发送验证码[{}]的短信失败" , phoneNum , code);
|
|
|
|
+ }
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|