短信验证码
This commit is contained in:
parent
47976b80de
commit
fe64a32608
|
|
@ -8,6 +8,7 @@ import com.aliyun.teautil.models.RuntimeOptions;
|
|||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.CacheUtils;
|
||||
import com.ruoyi.common.utils.ExceptionUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.NoticeRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
@ -36,7 +37,7 @@ public class NoticeController {
|
|||
String code = String.valueOf((int)((Math.random() * 9 + 1) * Math.pow(10,5)));
|
||||
|
||||
// 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
|
||||
Client client = createClient("LTAI5tLDuQRdfyHASSxehs9m", "accessKeySecret");
|
||||
Client client = createClient("LTAI5tLDuQRdfyHASSxehs9m", "CraRUliWZNMJhhSRIZ0nVWrxFkGTOH");
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setSignName("保无忧")
|
||||
.setTemplateCode("SMS_275375715")
|
||||
|
|
@ -53,6 +54,19 @@ public class NoticeController {
|
|||
return AjaxResult.success("操作成功!");
|
||||
}
|
||||
|
||||
@PostMapping("/checkSms")
|
||||
@ResponseBody
|
||||
public AjaxResult checkSms(@RequestBody @Valid NoticeRequest request){
|
||||
if(StringUtils.isNotEmpty(request.getCode())){
|
||||
Object obj = CacheUtils.get(request.getPhone());
|
||||
if(obj != null && request.getCode().equals(obj.toString())){
|
||||
CacheUtils.remove(request.getPhone());
|
||||
return AjaxResult.success("操作成功!");
|
||||
}
|
||||
}
|
||||
return AjaxResult.error("操作失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId
|
||||
|
|
|
|||
|
|
@ -17,4 +17,9 @@ public class NoticeRequest {
|
|||
@NotNull
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
* */
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue