阿里云验证码
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.StringUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/phoneValidateCode")
|
||||
@RequiredArgsConstructor
|
||||
public class PhoneValidateCodeController {
|
||||
|
||||
private final ValidateCodeUtil validateCodeUtil;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
/**
|
||||
* 一分钟
|
||||
*/
|
||||
protected static final long ONE_MINUTE = 60;
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public Result verifyPhoneIsExist(@RequestParam String phone) {
|
||||
|
||||
String random = StringUtil.random(6);
|
||||
validateCodeUtil.requestValidateCodeAli(phone, random);
|
||||
//存入缓存
|
||||
try {
|
||||
redisUtils.set(phone,random,ONE_MINUTE,TimeUnit.SECONDS);
|
||||
}catch (Exception e){
|
||||
throw new MsgException("验证码发送失败");
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user