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));
|
}
|
}
|