xuhy
2024-12-11 5be07b1a021f596b003eac001f4cb77416ae6c7b
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
package com.ruoyi.web.controller.tool;
 
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.TAppUser;
import com.ruoyi.system.service.TAppUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
@RestController
 
public class MsgUtil {
    @Resource
    private RedisCache redisCache;
    @Resource
    private TAppUserService appUserService;
    @ApiOperation(value = "通用发送验证码,type:1=注册,2=登录,3=修改手机号,4=修改密码",tags = "通用发送验证码")
    @PostMapping("/common/send")
    public String send (String phone,Integer type){
        TAppUser one = appUserService.lambdaQuery().eq(TAppUser::getPhone, phone).one();
        switch (type){
            case 1:
                if (one!=null){
                    throw new ServiceException("当前手机号已注册");
                }
                break;
            case 2:
                if (Objects.isNull(one)){
                    throw new ServiceException("当前手机号未注册");
                }
                break;
            case 3:
                if (one!=null){
                    throw new ServiceException("当前手机号已存在");
                }
                break;
            case 4:
                if (Objects.isNull(one)){
                    throw new ServiceException("当前手机号不存在");
                }
                break;
        }
        String code = createCode();
        redisCache.setCacheObject(phone,code);
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("CorpID", "SCZT006959");
        paramMap.put("Pwd", "123456");
        paramMap.put("Mobile", phone);
        paramMap.put("Cell", "");
        paramMap.put("SendTime", "");
        paramMap.put("Content", java.net.URLEncoder.encode("您的验证码为"+code+"。如非本人操作,请注意账号安全。【职评网】"));
        String result3 = HttpUtil.post("http://sdk2.028lk.com/sdk2/BatchSend2.aspx", paramMap);
        if (result3 == null) {
            result3 = "";
        }
        result3 = StrUtil.trim(result3);
 
    return result3;
    }
    public static String createCode(){
        return String.valueOf(ThreadLocalRandom.current().nextInt(100000, 999999));
    }
}