|
@@ -4,12 +4,14 @@ import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
|
import com.aliyun.tea.TeaException;
|
|
import com.aliyun.tea.TeaException;
|
|
import com.aliyun.teautil.models.RuntimeOptions;
|
|
import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
|
+import com.rongwei.bscommon.system.config.AliyunSmsConfig;
|
|
import com.rongwei.bscommon.system.service.AliyunSmsService;
|
|
import com.rongwei.bscommon.system.service.AliyunSmsService;
|
|
import com.rongwei.bscommon.system.service.SendRecordService;
|
|
import com.rongwei.bscommon.system.service.SendRecordService;
|
|
import com.rongwei.bscommon.system.utils.QHSEUtils;
|
|
import com.rongwei.bscommon.system.utils.QHSEUtils;
|
|
import com.rongwei.bsentity.domain.SendRecordDo;
|
|
import com.rongwei.bsentity.domain.SendRecordDo;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -20,14 +22,8 @@ import java.util.Map;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
|
|
|
|
- @Value("${aliyun-sms.access-key-id:#{null}}")
|
|
|
|
- private String accessKeyId;
|
|
|
|
- @Value("${aliyun-sms.access-key-secret:#{null}}")
|
|
|
|
- private String accessKeySecret;
|
|
|
|
- @Value("${aliyun-sms.endpoint:#{null}}")
|
|
|
|
- private String endpoint;
|
|
|
|
- @Value("${aliyun-sms.sign-name:#{null}}")
|
|
|
|
- private String signName;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private AliyunSmsConfig aliyunSmsConfig;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SendRecordService sendRecordService;
|
|
private SendRecordService sendRecordService;
|
|
@@ -37,10 +33,10 @@ public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
|
|
com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
|
|
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
|
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
|
.setCredential(credential);
|
|
.setCredential(credential);
|
|
- config.accessKeyId = accessKeyId;
|
|
|
|
- config.accessKeySecret = accessKeySecret;
|
|
|
|
|
|
+ config.accessKeyId = aliyunSmsConfig.getAccessKeyId();
|
|
|
|
+ config.accessKeySecret = aliyunSmsConfig.getAccessKeySecret();
|
|
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
|
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
|
- config.endpoint = endpoint;
|
|
|
|
|
|
+ config.endpoint = aliyunSmsConfig.getEndpoint();
|
|
return new com.aliyun.dysmsapi20170525.Client(config);
|
|
return new com.aliyun.dysmsapi20170525.Client(config);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -54,33 +50,29 @@ public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public SendSmsResponse sendSms(String templateId,
|
|
public SendSmsResponse sendSms(String templateId,
|
|
- Map<String, String> templateParamMap, String phone) throws Exception {
|
|
|
|
|
|
+ Map<String, String> templateParamMap, String phone) {
|
|
String templateParam = com.aliyun.teautil.Common.toJSONString(templateParamMap);
|
|
String templateParam = com.aliyun.teautil.Common.toJSONString(templateParamMap);
|
|
- com.aliyun.dysmsapi20170525.Client client = createClient();
|
|
|
|
- // 创建请求
|
|
|
|
- SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
|
|
|
- sendSmsRequest.setSignName(signName);
|
|
|
|
- sendSmsRequest.setTemplateCode(templateId);
|
|
|
|
- sendSmsRequest.setTemplateParam(templateParam);
|
|
|
|
- sendSmsRequest.setPhoneNumbers(phone);
|
|
|
|
- RuntimeOptions runtime = new RuntimeOptions();
|
|
|
|
SendSmsResponse resp = null;
|
|
SendSmsResponse resp = null;
|
|
try {
|
|
try {
|
|
|
|
+ com.aliyun.dysmsapi20170525.Client client = createClient();
|
|
|
|
+ // 创建请求
|
|
|
|
+ SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
|
|
|
+ sendSmsRequest.setSignName(aliyunSmsConfig.getSignName());
|
|
|
|
+ sendSmsRequest.setTemplateCode(templateId);
|
|
|
|
+ sendSmsRequest.setTemplateParam(templateParam);
|
|
|
|
+ sendSmsRequest.setPhoneNumbers(phone);
|
|
|
|
+ RuntimeOptions runtime = new RuntimeOptions();
|
|
resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
|
resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
|
log.info("发送短信结果:{}", com.aliyun.teautil.Common.toJSONString(resp));
|
|
log.info("发送短信结果:{}", com.aliyun.teautil.Common.toJSONString(resp));
|
|
// 保存发送记录
|
|
// 保存发送记录
|
|
saveSendRecord(resp, sendSmsRequest);
|
|
saveSendRecord(resp, sendSmsRequest);
|
|
} catch (TeaException error) {
|
|
} catch (TeaException error) {
|
|
- log.error("发送短信结果:{}", error.getMessage());
|
|
|
|
log.error("诊断地址:{}", error.getData().get("Recommend"));
|
|
log.error("诊断地址:{}", error.getData().get("Recommend"));
|
|
log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, error.getMessage(), error.getClass().getSimpleName(), error);
|
|
log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, error.getMessage(), error.getClass().getSimpleName(), error);
|
|
- throw new RuntimeException(error.getMessage());
|
|
|
|
|
|
+ throw new RuntimeException("短信发送异常!请联系系统管理员");
|
|
} catch (Exception _error) {
|
|
} catch (Exception _error) {
|
|
- TeaException error = new TeaException(_error.getMessage(), _error);
|
|
|
|
- log.error("发送短信结果:{}", error.getMessage());
|
|
|
|
- log.error("诊断地址:{}", error.getData().get("Recommend"));
|
|
|
|
- log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, error.getMessage(), error.getClass().getSimpleName(), error);
|
|
|
|
- throw new RuntimeException(error.getMessage());
|
|
|
|
|
|
+ log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, _error.getMessage(), _error.getClass().getSimpleName(), _error);
|
|
|
|
+ throw new RuntimeException("短信发送异常!请联系系统管理员");
|
|
}
|
|
}
|
|
return resp;
|
|
return resp;
|
|
}
|
|
}
|