1.update request body

main
Gary 11 months ago
parent 86d0a04ded
commit c40930e3a6

@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import constants.Constants;
import controller.BaseController;
import com.luoo.user.dto.request.SendSmsReq;
import com.luoo.user.dto.response.CountryCodeDTO;
import com.luoo.user.dto.response.CreateImageCode;
import com.luoo.user.pojo.UserInfo;
@ -73,30 +74,23 @@ public class LoginController extends BaseController {
*
*/
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送50个请求")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86", required = false, defaultValue = "+86"),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "imageCheckCode", value = "图形验证码", required = false) })
@PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
public Result<Void> sendSms(@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam(name = "countryCode", defaultValue = "+86") String countryCode,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
@VerifyParam(required = false) @RequestParam("imageCheckCode") String imageCheckCode) {
if (!StringTools.isEmpty(imageCheckCode)) {
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
// 得到缓存中的验证码
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
if (!redisImageCheckCode.equalsIgnoreCase(sendSmsReq.getImageCheckCode())) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
redisTemplate.delete(redisImageCheckCodeKey);
}
userInfoService.sendSms(deviceId, mobile);
userInfoService.sendSms(sendSmsReq.getDeviceId(), sendSmsReq.getMobile());
return Result.success();
}

@ -0,0 +1,33 @@
package com.luoo.user.dto.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import annotation.VerifyParam;
import enums.VerifyRegexEnum;
/**
*
*/
@Getter
@Setter
@ApiModel
public class SendSmsReq implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(name = "mobile", value = "手机号", required = true)
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE)
private String mobile;
@ApiModelProperty(name = "deviceId", value = "设备id", required = true)
@VerifyParam(required = true)
private String deviceId;
@ApiModelProperty(name = "countryCode", value = "国家码,默认为‘+86", required = false, example="+86")
private String countryCode = "+86";
@ApiModelProperty(name = "imageCheckCode", value = "图形验证码", required = false)
private String imageCheckCode;
}
Loading…
Cancel
Save