更换短信验证码
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -224,6 +224,13 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${pom.basedir}/src/main/resources/lib/aspose-words-22.10-jdk16.jar</systemPath>
|
<systemPath>${pom.basedir}/src/main/resources/lib/aspose-words-22.10-jdk16.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zmzm</groupId>
|
||||||
|
<artifactId>sms-http</artifactId>
|
||||||
|
<version>sms-http</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${pom.basedir}/src/main/resources/lib/http.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.lame</groupId>
|
<groupId>net.sourceforge.lame</groupId>
|
||||||
<artifactId>lame</artifactId>
|
<artifactId>lame</artifactId>
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public final class Base64Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] decode(String content) {
|
private static byte[] decode(String content) {
|
||||||
return Base64.decodeBase64(content);
|
return Base64.decodeBase64(content.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean validSize(byte[] data, long length) {
|
private static boolean validSize(byte[] data, long length) {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class HlsDecryptService {
|
|||||||
*/
|
*/
|
||||||
private byte[] decrypt(String ciphertext) {
|
private byte[] decrypt(String ciphertext) {
|
||||||
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(ciphertext);
|
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(ciphertext);
|
||||||
return Base64.decodeBase64(decryptKMSDataKeyResponseBody.getPlaintext());
|
return Base64.decodeBase64(decryptKMSDataKeyResponseBody.getPlaintext().getBytes());
|
||||||
// DecryptKMSDataKeyRequest request = new DecryptKMSDataKeyRequest();
|
// DecryptKMSDataKeyRequest request = new DecryptKMSDataKeyRequest();
|
||||||
// request.setCipherText(ciphertext);
|
// request.setCipherText(ciphertext);
|
||||||
// request.setProtocol(ProtocolType.HTTPS);
|
// request.setProtocol(ProtocolType.HTTPS);
|
||||||
|
|||||||
91
src/main/java/com/peanut/common/utils/SmsUtil.java
Normal file
91
src/main/java/com/peanut/common/utils/SmsUtil.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package com.peanut.common.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bcloud.msg.http.HttpSender;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SmsUtil {
|
||||||
|
|
||||||
|
@Value("${sms.domestic.account}")
|
||||||
|
private String account;
|
||||||
|
@Value("${sms.domestic.pswd}")
|
||||||
|
private String pswd;
|
||||||
|
@Value("${sms.domestic.content}")
|
||||||
|
private String content;
|
||||||
|
@Value("${sms.abroad.account}")
|
||||||
|
private String abroadAccount;
|
||||||
|
@Value("${sms.abroad.pswd}")
|
||||||
|
private String abroadPswd;
|
||||||
|
@Value("${sms.abroad.content}")
|
||||||
|
private String abroadContent;
|
||||||
|
|
||||||
|
public R sendSmsCode(String phone, String code) {
|
||||||
|
String uri = "http://116.62.212.142/msg/HttpBatchSendSM";//应用地址
|
||||||
|
String mobiles = phone;//手机号码,多个号码使用","分割
|
||||||
|
boolean needstatus = true;//是否需要状态报告,需要true,不需要false
|
||||||
|
String product = "";//产品ID
|
||||||
|
String extno = "";//扩展码
|
||||||
|
String respType = "json";//返回json格式响应
|
||||||
|
boolean encrypt = true;// 密码使用时间戳加密
|
||||||
|
try {
|
||||||
|
String returnString = HttpSender.send(uri, account, pswd, mobiles, content.replace("XXXXXX",code), needstatus, product, extno, respType, encrypt);
|
||||||
|
//{"result":108,"ts":"20250416115415"}
|
||||||
|
//{"result":0,"msgid":"2150416115442493200","ts":"20250416115442"}
|
||||||
|
JSONObject object = JSONObject.parseObject(returnString);
|
||||||
|
if ("0".equals(object.get("result").toString())){
|
||||||
|
return R.ok();
|
||||||
|
}else if ("104".equals(object.get("result").toString())){
|
||||||
|
return R.error("短信平台系统忙,请稍后重试。");
|
||||||
|
}else if ("107".equals(object.get("result").toString())){
|
||||||
|
return R.error("错误的手机号码。");
|
||||||
|
}else {
|
||||||
|
return R.error("系统错误,请联系管理员");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error("系统错误,请联系管理员");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public R sendSmsAbroad(String phone, String code){
|
||||||
|
try {
|
||||||
|
CloseableHttpClient client = HttpClients.createDefault();
|
||||||
|
HttpPost httpPost = new HttpPost("http://www.onesnok.net:9511/api/send-sms-single");
|
||||||
|
StringEntity entity = new StringEntity("" +
|
||||||
|
"sp_id="+abroadAccount+
|
||||||
|
"&password="+MD5Utils.getStrrMD5(abroadPswd)+
|
||||||
|
"&mobile="+phone+
|
||||||
|
"&content="+abroadContent.replace("XXXXXX",code));
|
||||||
|
httpPost.setEntity(entity);
|
||||||
|
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
String responseBody = EntityUtils.toString(client.execute(httpPost).getEntity());
|
||||||
|
System.out.println(responseBody);
|
||||||
|
JSONObject object = JSONObject.parseObject(responseBody);
|
||||||
|
if ("0".equals(object.get("code").toString())){
|
||||||
|
return R.ok();
|
||||||
|
}else if ("10000".equals(object.get("code").toString())){
|
||||||
|
return R.error("短信平台系统忙,请稍后重试。");
|
||||||
|
}else {
|
||||||
|
if ("WL:CDQC".equals(object.get("data").toString())){
|
||||||
|
return R.error("地区不支持。");
|
||||||
|
}else if ("WL:CWHM".equals(object.get("data").toString())){
|
||||||
|
return R.error("错误的手机号码。");
|
||||||
|
}else {
|
||||||
|
return R.error("系统错误,请联系管理员");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error("系统错误,请联系管理员");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -232,7 +232,6 @@ public class MyUserController {
|
|||||||
return R.error(500,"短信验证码频率过高,请稍后再试!");
|
return R.error(500,"短信验证码频率过高,请稍后再试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//生成随机六位数
|
//生成随机六位数
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
String i = random.nextInt(999999) + "";
|
String i = random.nextInt(999999) + "";
|
||||||
@@ -242,14 +241,10 @@ public class MyUserController {
|
|||||||
}
|
}
|
||||||
i = sb.toString() + i;
|
i = sb.toString() + i;
|
||||||
String code = i + "_"+System.currentTimeMillis();
|
String code = i + "_"+System.currentTimeMillis();
|
||||||
|
|
||||||
//redis 缓存验证码
|
//redis 缓存验证码
|
||||||
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
|
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
|
||||||
|
|
||||||
//发送
|
//发送
|
||||||
userService.sendCodeForRegister(phone,code,areacode);
|
return userService.sendCodeForRegister(phone,code,areacode);
|
||||||
|
|
||||||
return R.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.peanut.modules.book.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.peanut.common.utils.PageUtils;
|
import com.peanut.common.utils.PageUtils;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.modules.common.entity.BookForumArticlesEntity;
|
import com.peanut.modules.common.entity.BookForumArticlesEntity;
|
||||||
import com.peanut.modules.common.entity.MyUserEntity;
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -19,7 +20,7 @@ public interface MyUserService extends IService<MyUserEntity> {
|
|||||||
|
|
||||||
PageUtils queryPage(Map<String, Object> params);
|
PageUtils queryPage(Map<String, Object> params);
|
||||||
|
|
||||||
void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception;
|
R sendCodeForRegister(String phone, String code, Integer areaCode) throws Exception;
|
||||||
|
|
||||||
List<BookForumArticlesEntity> getForumsLimit(Integer book_id, Integer limit);
|
List<BookForumArticlesEntity> getForumsLimit(Integer book_id, Integer limit);
|
||||||
//充值花生币
|
//充值花生币
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SMSConfig smsConfig;
|
private SMSConfig smsConfig;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private SmsUtil smsUtil;
|
||||||
|
@Autowired
|
||||||
private UserEbookBuyService userEbookBuyService;
|
private UserEbookBuyService userEbookBuyService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private BookForumArticlesService bookForumArticlesService;
|
private BookForumArticlesService bookForumArticlesService;
|
||||||
@@ -45,9 +47,14 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception {
|
public R sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception {
|
||||||
String scode = code.split("_")[0];
|
String scode = code.split("_")[0];
|
||||||
sendCode(phone,scode,areaCode);
|
// sendCode(phone,scode,areaCode);
|
||||||
|
if (areaCode!=null&&areaCode>0&&areaCode!=86){
|
||||||
|
return smsUtil.sendSmsAbroad(""+areaCode+phone,scode);
|
||||||
|
}else {
|
||||||
|
return smsUtil.sendSmsCode(phone,scode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ public class UserController {
|
|||||||
//redis 缓存验证码
|
//redis 缓存验证码
|
||||||
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
|
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
|
||||||
//发送
|
//发送
|
||||||
userService.sendCodeForRegister(phone,code,areacode);
|
return userService.sendCodeForRegister(phone,code,areacode);
|
||||||
return R.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.peanut.modules.common.service;
|
package com.peanut.modules.common.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.modules.common.entity.MyUserEntity;
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
|
|
||||||
public interface MyUserService extends IService<MyUserEntity> {
|
public interface MyUserService extends IService<MyUserEntity> {
|
||||||
|
|
||||||
void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception;
|
R sendCodeForRegister(String phone, String code, Integer areaCode) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import com.aliyun.tea.TeaException;
|
|||||||
import com.aliyun.teautil.Common;
|
import com.aliyun.teautil.Common;
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bcloud.msg.http.HttpSender;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
|
import com.peanut.common.utils.SmsUtil;
|
||||||
import com.peanut.modules.app.config.SMSConfig;
|
import com.peanut.modules.app.config.SMSConfig;
|
||||||
import com.peanut.modules.app.config.Sample;
|
import com.peanut.modules.app.config.Sample;
|
||||||
import com.peanut.modules.common.dao.MyUserDao;
|
import com.peanut.modules.common.dao.MyUserDao;
|
||||||
@@ -22,11 +25,18 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SMSConfig smsConfig;
|
private SMSConfig smsConfig;
|
||||||
|
@Autowired
|
||||||
|
private SmsUtil smsUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCodeForRegister(String phone, String code, Integer areaCode) throws Exception {
|
public R sendCodeForRegister(String phone, String code, Integer areaCode){
|
||||||
String scode = code.split("_")[0];
|
String scode = code.split("_")[0];
|
||||||
sendCode(phone,scode,areaCode);
|
// sendCode(phone,scode,areaCode);
|
||||||
|
if (areaCode!=null&&areaCode>0&&areaCode!=86){
|
||||||
|
return smsUtil.sendSmsAbroad(""+areaCode+phone,scode);
|
||||||
|
}else {
|
||||||
|
return smsUtil.sendSmsCode(phone,scode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCode(String phone, String code, Integer areaCode) throws Exception {
|
private void sendCode(String phone, String code, Integer areaCode) throws Exception {
|
||||||
@@ -59,4 +69,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ public class VodAliController {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
if (!validRe) {
|
if (!validRe) {
|
||||||
return Base64.decodeBase64("Illegal access");
|
return Base64.decodeBase64("Illegal access".getBytes());
|
||||||
}
|
}
|
||||||
if (null == cipherText) {
|
if (null == cipherText) {
|
||||||
return Base64.decodeBase64("Illegal access !");
|
return Base64.decodeBase64("Illegal access !".getBytes());
|
||||||
}
|
}
|
||||||
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(cipherText);
|
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(cipherText);
|
||||||
return Base64.decodeBase64(decryptKMSDataKeyResponseBody.getPlaintext());
|
return Base64.decodeBase64(decryptKMSDataKeyResponseBody.getPlaintext().getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,16 @@ aliyun:
|
|||||||
templateCode: SMS_248840040
|
templateCode: SMS_248840040
|
||||||
sTemplateCode: SMS_463780139
|
sTemplateCode: SMS_463780139
|
||||||
|
|
||||||
|
sms:
|
||||||
|
domestic:
|
||||||
|
account: MXT802795
|
||||||
|
pswd: Zm802795
|
||||||
|
content: 【天津众妙之门科技】,你的验证码为:XXXXXX,您正在进行身份验证,请勿泄露于他人!
|
||||||
|
abroad:
|
||||||
|
account: 921689
|
||||||
|
pswd: 9de2a579
|
||||||
|
content: Tianjin Zhongmiao Gate Technology:Your verification code is:XXXXXX.
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 9200
|
port: 9200
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,16 @@ aliyun:
|
|||||||
templateCode: SMS_248840040
|
templateCode: SMS_248840040
|
||||||
sTemplateCode: SMS_463780139
|
sTemplateCode: SMS_463780139
|
||||||
|
|
||||||
|
sms:
|
||||||
|
domestic:
|
||||||
|
account: MXT802795
|
||||||
|
pswd: Zm802795
|
||||||
|
content: 【天津众妙之门科技】,你的验证码为:XXXXXX,您正在进行身份验证,请勿泄露于他人!
|
||||||
|
abroad:
|
||||||
|
account: 921689
|
||||||
|
pswd: 9de2a579
|
||||||
|
content: Tianjin Zhongmiao Gate Technology:Your verification code is:XXXXXX.
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 9200
|
port: 9200
|
||||||
|
|
||||||
|
|||||||
@@ -66,10 +66,20 @@ aliyun:
|
|||||||
sms:
|
sms:
|
||||||
accessKeyId: LTAI5tJbbw5fY97pnw635yq3
|
accessKeyId: LTAI5tJbbw5fY97pnw635yq3
|
||||||
accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi
|
accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi
|
||||||
singName: 疯子读书国际
|
singName: 天津众妙之门科技有限公司
|
||||||
templateCode: SMS_483250023
|
templateCode: SMS_483420156
|
||||||
sTemplateCode: SMS_463780139
|
sTemplateCode: SMS_463780139
|
||||||
|
|
||||||
|
sms:
|
||||||
|
domestic:
|
||||||
|
account: MXT802795
|
||||||
|
pswd: Zm802795
|
||||||
|
content: 【天津众妙之门科技】,你的验证码为:XXXXXX,您正在进行身份验证,请勿泄露于他人!
|
||||||
|
abroad:
|
||||||
|
account: 921689
|
||||||
|
pswd: 9de2a579
|
||||||
|
content: Tianjin Zhongmiao Gate Technology:Your verification code is:XXXXXX.
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 9100
|
port: 9100
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,16 @@ aliyun:
|
|||||||
templateCode: SMS_248840040
|
templateCode: SMS_248840040
|
||||||
sTemplateCode: SMS_463780139
|
sTemplateCode: SMS_463780139
|
||||||
|
|
||||||
|
sms:
|
||||||
|
domestic:
|
||||||
|
account: MXT802795
|
||||||
|
pswd: Zm802795
|
||||||
|
content: 【天津众妙之门科技】,你的验证码为:XXXXXX,您正在进行身份验证,请勿泄露于他人!
|
||||||
|
abroad:
|
||||||
|
account: 921689
|
||||||
|
pswd: 9de2a579
|
||||||
|
content: Tianjin Zhongmiao Gate Technology:Your verification code is:XXXXXX.
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 9200
|
port: 9200
|
||||||
|
|
||||||
|
|||||||
BIN
src/main/resources/lib/http.jar
Normal file
BIN
src/main/resources/lib/http.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user