CaptchaController.java
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.order.erp.controller;
import com.order.erp.common.annotation.AnonymousAccess;
import com.order.erp.common.constant.ServerResult;
import com.order.erp.common.utils.ImgCaptchaUtils;
import com.order.erp.common.utils.SmsUtils;
import com.order.erp.domain.vo.CaptchaMessageVO;
import com.wf.captcha.ArithmeticCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* (Member)验证码
*
* @author makejava
* @since 2023-08-22 17:02:39
*/
@RestController
@Api(tags = "验证码")
@RequestMapping("/order/erp/captcha")
public class CaptchaController {
@Resource
private SmsUtils smsUtils;
@Resource
private ImgCaptchaUtils imgCaptchaUtils;
/**
* 获取验证码
*
* @param msgVo 查询条件
* @return 查询结果
*/
@AnonymousAccess
@ApiOperation("获取验证码")
@PostMapping("/send_captcha_code")
public ServerResult sendCaptchaCode(@RequestBody @Validated CaptchaMessageVO msgVo) {
return smsUtils.sendCaptchaCode(msgVo);
}
/**
* 获取图片验证码
*
* @return 查询结果
*/
@AnonymousAccess
@ApiOperation("获取图片验证码")
@PostMapping("/get_img_captcha_code")
public ServerResult getImgCaptchaCode() {
// 算术类型 https://gitee.com/whvse/EasyCaptcha
ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36);
// 几位数运算,默认是两位
captcha.setLen(2);
// 获取运算的结果
String result = captcha.text();
String uuid = imgCaptchaUtils.setImgCaptcha4uuid(result);
// 验证码信息
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
put("img", captcha.toBase64());
put("uuid", uuid);
}};
return ServerResult.success(imgResult);
}
}