数据
This commit is contained in:
@@ -16,6 +16,7 @@ import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -75,6 +76,9 @@ public class AuthAppController {
|
||||
@Operation(summary = "获取注册验证码")
|
||||
@Log(title = "获取注册验证码", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
public R<Map<String,String>> registerCodeV2(@Validated @RequestBody RegisterCodeV2 code){
|
||||
if(StringUtils.isBlank(code.getUserIp())){
|
||||
code.setUserIp(ServletUtils.getClientIP());
|
||||
}
|
||||
boolean check = verificationCodeCheck.check(code.getTicket(), code.getUserIp(), code.getRandStr());
|
||||
if(!check){
|
||||
return R.fail(600,"验证码错误!");
|
||||
|
||||
@@ -12,6 +12,5 @@ public class RegisterCodeV2 {
|
||||
private String ticket;
|
||||
@NotEmpty(message = "腾讯验证码所属参数[randStr]")
|
||||
private String randStr;
|
||||
@NotEmpty(message = "腾讯验证码所属参数[客户端IP]")
|
||||
private String userIp;
|
||||
}
|
||||
|
||||
104
ruoyi-cai/src/main/java/com/ruoyi/cai/kit/DuanXinBaoSmsKit.java
Normal file
104
ruoyi-cai/src/main/java/com/ruoyi/cai/kit/DuanXinBaoSmsKit.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.cai.kit;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class DuanXinBaoSmsKit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean s = sendMessage("15302786929", RandomUtil.randomNumbers(4));
|
||||
log.info(s+"");
|
||||
}
|
||||
|
||||
private final static String USER_NAME = "huaxiang5201";
|
||||
private final static String TEST_PASSWORD = "qwe8848.";
|
||||
private final static String CONTENT = "【花香app】您的验证码是%s。如非本人操作,请忽略本短信";
|
||||
|
||||
private final static String HTTP_URL = "http://api.smsbao.com/sms";
|
||||
|
||||
public static boolean sendMessage(String phone,String number){
|
||||
StringBuffer httpArg = new StringBuffer();
|
||||
httpArg.append("u=").append(USER_NAME).append("&");
|
||||
httpArg.append("p=").append(md5(TEST_PASSWORD)).append("&");
|
||||
httpArg.append("m=").append(phone).append("&");
|
||||
String content = String.format(CONTENT, number);
|
||||
httpArg.append("c=").append(encodeUrlString(content, "UTF-8"));
|
||||
return Objects.equals(request(HTTP_URL, httpArg.toString()), "0");
|
||||
}
|
||||
|
||||
public static String request(String httpUrl, String httpArg) {
|
||||
BufferedReader reader = null;
|
||||
String result = null;
|
||||
StringBuffer sbf = new StringBuffer();
|
||||
httpUrl = httpUrl + "?" + httpArg;
|
||||
try {
|
||||
URL url = new URL(httpUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(2000);
|
||||
connection.setReadTimeout(2000);
|
||||
connection.connect();
|
||||
InputStream is = connection.getInputStream();
|
||||
reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
String strRead = reader.readLine();
|
||||
if (strRead != null) {
|
||||
sbf.append(strRead);
|
||||
while ((strRead = reader.readLine()) != null) {
|
||||
sbf.append("\n");
|
||||
sbf.append(strRead);
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
result = sbf.toString();
|
||||
} catch (Exception e) {
|
||||
log.info("短信发送失败",e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String md5(String plainText) {
|
||||
StringBuilder sb = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(plainText.getBytes());
|
||||
byte b[] = md.digest();
|
||||
int i;
|
||||
sb = new StringBuilder();
|
||||
for (int offset = 0; offset < b.length; offset++) {
|
||||
i = b[offset];
|
||||
if (i < 0)
|
||||
i += 256;
|
||||
if (i < 16)
|
||||
sb.append("0");
|
||||
sb.append(Integer.toHexString(i));
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.info(e.getMessage(),e);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String encodeUrlString(String str, String charset) {
|
||||
String strret = null;
|
||||
if (str == null)
|
||||
return str;
|
||||
try {
|
||||
strret = java.net.URLEncoder.encode(str, charset);
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
return strret;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.ruoyi.cai.domain.UserInfo;
|
||||
import com.ruoyi.cai.enums.CodeEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.kit.AliSmsKit;
|
||||
import com.ruoyi.cai.kit.DuanXinBaoSmsKit;
|
||||
import com.ruoyi.cai.manager.CodeManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.SmsVerifyMapper;
|
||||
@@ -120,13 +121,15 @@ public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify>
|
||||
smsVerify.setOperateIp(clientIP);
|
||||
smsVerify.setOverTime(LocalDateTime.now().plus(1, ChronoUnit.MINUTES));
|
||||
this.save(smsVerify);
|
||||
boolean boo = aliSmsKit.sendMessage(mobile, codeEnum.getAliTemplate(), code, true);
|
||||
// boolean boo = aliSmsKit.sendMessage(mobile, codeEnum.getAliTemplate(), code, true);
|
||||
boolean boo = DuanXinBaoSmsKit.sendMessage(mobile, code);
|
||||
if(!boo){
|
||||
this.removeById(smsVerify);
|
||||
}
|
||||
// String code = codeManager.put(codeEnum, mobile);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearSmsVerify(int days) {
|
||||
int index = 0;
|
||||
|
||||
Reference in New Issue
Block a user