|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.paper.library.common.util;
|
|
|
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.boot.core.sms.model.SmsSendRequest;
|
|
|
import com.qmth.boot.core.sms.model.SmsSendResponse;
|
|
|
import com.qmth.boot.core.sms.service.SmsService;
|
|
@@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -18,7 +20,8 @@ import java.util.Map;
|
|
|
*/
|
|
|
@Component
|
|
|
public class SmsSendUtil {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(SmsSendUtil.class);
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SmsSendUtil.class);
|
|
|
|
|
|
@Resource
|
|
|
private SmsService smsService;
|
|
@@ -35,13 +38,14 @@ public class SmsSendUtil {
|
|
|
* @param templateParam 模版变量
|
|
|
* @return bizId 本次操作业务标识
|
|
|
*/
|
|
|
- public String sendSms(String phoneNumber, String templateCode, Map<String, Object> templateParam) {
|
|
|
+ public String sendSms(String phoneNumber, String templateCode, Map<String, Object> templateParam) throws UnsupportedEncodingException {
|
|
|
validDictionaryConfig(dictionaryConfig);
|
|
|
SmsSendRequest smsSendRequest = new SmsSendRequest();
|
|
|
// 必填,发送手机号
|
|
|
smsSendRequest.setPhoneNumber(phoneNumber);
|
|
|
// 必填,短信签名
|
|
|
- smsSendRequest.setSignName(dictionaryConfig.smsDomain().getSmsSignName());
|
|
|
+ String signName = dictionaryConfig.smsDomain().getSmsSignName();
|
|
|
+ smsSendRequest.setSignName(signName);
|
|
|
// 必填,短信模版编号
|
|
|
smsSendRequest.setTemplateCode(templateCode);
|
|
|
//模版变量,可选
|
|
@@ -49,11 +53,15 @@ public class SmsSendUtil {
|
|
|
smsSendRequest.setTemplateParam(templateParam);
|
|
|
}
|
|
|
|
|
|
- SmsSendResponse smsSendResponse = smsService.sendSms(smsSendRequest);
|
|
|
- if (smsSendResponse == null) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("短信发送失败");
|
|
|
+ try {
|
|
|
+ SmsSendResponse smsSendResponse = smsService.sendSms(smsSendRequest);
|
|
|
+ if (smsSendResponse == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("短信发送失败");
|
|
|
+ }
|
|
|
+ return smsSendResponse.getBizId();
|
|
|
+ } catch (ApiException e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
- return smsSendResponse.getBizId();
|
|
|
}
|
|
|
|
|
|
/**
|