|
@@ -11,13 +11,13 @@ import com.rongwei.bscommon.system.utils.QHSEUtils;
|
|
|
import com.rongwei.bsentity.domain.SendRecordDo;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
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.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.rongwei.bscommon.system.utils.QHSEConstant.OK_LOWER_CASE;
|
|
|
+
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
@@ -49,32 +49,42 @@ public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
|
* @return 发送结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public SendSmsResponse sendSms(String templateId,
|
|
|
- Map<String, String> templateParamMap, String phone) {
|
|
|
+ public void sendSms(String templateId,
|
|
|
+ Map<String, Object> templateParamMap, String phone) {
|
|
|
String templateParam = com.aliyun.teautil.Common.toJSONString(templateParamMap);
|
|
|
SendSmsResponse resp = null;
|
|
|
+ SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
|
|
+ RuntimeOptions runtime = null;
|
|
|
+ com.aliyun.dysmsapi20170525.Client client = null;
|
|
|
try {
|
|
|
- com.aliyun.dysmsapi20170525.Client client = createClient();
|
|
|
+ client = createClient();
|
|
|
// 创建请求
|
|
|
- SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
|
|
sendSmsRequest.setSignName(aliyunSmsConfig.getSignName());
|
|
|
sendSmsRequest.setTemplateCode(templateId);
|
|
|
sendSmsRequest.setTemplateParam(templateParam);
|
|
|
sendSmsRequest.setPhoneNumbers(phone);
|
|
|
- RuntimeOptions runtime = new RuntimeOptions();
|
|
|
+ runtime = new RuntimeOptions();
|
|
|
resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
|
|
- log.info("发送短信结果:{}", com.aliyun.teautil.Common.toJSONString(resp));
|
|
|
- // 保存发送记录
|
|
|
- saveSendRecord(resp, sendSmsRequest);
|
|
|
} catch (TeaException error) {
|
|
|
log.error("诊断地址:{}", error.getData().get("Recommend"));
|
|
|
log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, error.getMessage(), error.getClass().getSimpleName(), error);
|
|
|
+ // 保存发送记录
|
|
|
+ saveSendRecord(resp, sendSmsRequest, "ERROR");
|
|
|
throw new RuntimeException("短信发送异常!请联系系统管理员");
|
|
|
} catch (Exception _error) {
|
|
|
log.error("短信发送异常 模板编号为:{},参数:{},手机号:{} - 原因: {} | 异常类型: {}", templateId, templateParam, phone, _error.getMessage(), _error.getClass().getSimpleName(), _error);
|
|
|
+ saveSendRecord(resp, sendSmsRequest, "ERROR");
|
|
|
throw new RuntimeException("短信发送异常!请联系系统管理员");
|
|
|
}
|
|
|
- return resp;
|
|
|
+ String sendCode = resp.body.code;
|
|
|
+ if (OK_LOWER_CASE.equals(sendCode)) {
|
|
|
+ log.info("短信发送成功");
|
|
|
+ saveSendRecord(resp, sendSmsRequest, "SUCCESS");
|
|
|
+ } else {
|
|
|
+ log.info("短信发送失败,错误码为:{}", sendCode);
|
|
|
+ saveSendRecord(resp, sendSmsRequest, "ERROR");
|
|
|
+ throw new RuntimeException("短信发送失败!" + resp.body.message);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,13 +93,14 @@ public class AliyunSmsServiceImpl implements AliyunSmsService {
|
|
|
* @param resp 发送结果
|
|
|
* @param sendSmsRequest 发送请求
|
|
|
*/
|
|
|
- private void saveSendRecord(SendSmsResponse resp, SendSmsRequest sendSmsRequest) {
|
|
|
+ private void saveSendRecord(SendSmsResponse resp, SendSmsRequest sendSmsRequest, String state) {
|
|
|
SendRecordDo sendRecordDo = new SendRecordDo();
|
|
|
sendRecordDo.setResult(com.aliyun.teautil.Common.toJSONString(resp));
|
|
|
sendRecordDo.setTemplateCode(sendSmsRequest.getTemplateCode());
|
|
|
sendRecordDo.setTemplateParam(sendSmsRequest.getTemplateParam());
|
|
|
sendRecordDo.setPhoneNumber(sendSmsRequest.getPhoneNumbers());
|
|
|
sendRecordDo.setSignName(sendSmsRequest.getSignName());
|
|
|
+ sendRecordDo.setRoption(state);
|
|
|
SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
QHSEUtils.initModelGeneralParameters(sendRecordDo, currentUser);
|
|
|
sendRecordService.save(sendRecordDo);
|