xuhy
2024-12-11 5be07b1a021f596b003eac001f4cb77416ae6c7b
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/MsgUtil.java
@@ -2,22 +2,52 @@
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;
    @ApiOperation(value = "通用发送验证码",tags = "通用发送验证码")
    @Resource
    private TAppUserService appUserService;
    @ApiOperation(value = "通用发送验证码,type:1=注册,2=登录,3=修改手机号,4=修改密码",tags = "通用发送验证码")
    @PostMapping("/common/send")
    public  String send (String phone){
    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<>();