fix: 短信验证码问题

This commit is contained in:
TS-QD1 2025-06-10 15:21:36 +08:00
parent 795479921a
commit aa244c1c58

View File

@ -1,5 +1,8 @@
package cn.com.tenlion.operator.service.verify.code;
import cn.com.tenlion.operator.util.TenlionSMS;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.base.SystemException;
@ -10,9 +13,13 @@ import ink.wgink.module.sms.manager.VerifyCodeManager;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.properties.sms.SmsProperties;
import ink.wgink.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class VerifyCodeService extends DefaultBaseService {
@ -32,26 +39,14 @@ public class VerifyCodeService extends DefaultBaseService {
String currentTimeStr = String.valueOf(System.currentTimeMillis());
String code = currentTimeStr.substring(currentTimeStr.length() - 6);
LOG.info(">>>>> 向手机号:{},发送验证码:{}", phone, code);
SmsVO smsVO = new SmsVO();
smsVO.setPhone(phone);
smsVO.setContent(code);
try {
if (smsProperties.getActive()) {
ISmsSend smsSend = new TencentSmsSendImpl(smsProperties.getTencentSms());
smsSend.code(phone, code);
}
Map<String, String> templateParams = new HashMap<>();
templateParams.put("code", code);
templateParams.put("time", "2");
JSONArray phoneArray = new JSONArray();
JSONObject phoneObject = new JSONObject();
phoneObject.put("phone", phone);
phoneArray.add(phoneObject);
TenlionSMS.sendMessage(UUIDUtil.getUUID(), "M00001", templateParams, phoneArray);
verifyCodeManager.setVerificationCode(phone, code);
smsVO.setSendStatus(1);
} catch (Exception e) {
LOG.error(e.getMessage());
String errorMessage = e.getMessage();
smsVO.setSendStatus(0);
smsVO.setErrorMessage(errorMessage);
throw new SystemException("短信发送失败");
} finally {
smsService.save(smsVO);
}
}
}