From 907641e56c2085aaa81f267946dc3e3e9fca73e7 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期三, 18 九月 2024 09:39:02 +0800
Subject: [PATCH] 代码提交
---
smartor/src/main/java/com/smartor/service/impl/BaseSmsaccountServiceImpl.java | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 214 insertions(+), 25 deletions(-)
diff --git a/smartor/src/main/java/com/smartor/service/impl/BaseSmsaccountServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/BaseSmsaccountServiceImpl.java
index ff65db8..b11049d 100644
--- a/smartor/src/main/java/com/smartor/service/impl/BaseSmsaccountServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/BaseSmsaccountServiceImpl.java
@@ -1,96 +1,285 @@
package com.smartor.service.impl;
-import java.util.List;
+import com.aliyun.dysmsapi20170525.Client;
+import com.aliyun.dysmsapi20170525.models.*;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teaopenapi.models.Config;
+import com.aliyun.teautil.Common;
+import com.aliyun.teautil.models.RuntimeOptions;
import com.ruoyi.common.utils.DateUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.smartor.mapper.BaseSmsaccountMapper;
+import com.smartor.domain.BaseSmsRequest;
import com.smartor.domain.BaseSmsaccount;
+import com.smartor.domain.BatchBaseSmsRequest;
+import com.smartor.domain.TemplateSmsRequest;
+import com.smartor.mapper.BaseSmsaccountMapper;
import com.smartor.service.IBaseSmsaccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* 鐭俊璐﹀彿Service涓氬姟灞傚鐞�
- *
+ *
* @author smartor
* @date 2023-03-06
*/
@Service
-public class BaseSmsaccountServiceImpl implements IBaseSmsaccountService
-{
+public class BaseSmsaccountServiceImpl implements IBaseSmsaccountService {
@Autowired
private BaseSmsaccountMapper baseSmsaccountMapper;
+ @Value("${accessKeyId}")
+ private String accessKeyId;
+
+ @Value("${accessKeySecret}")
+ private String accessKeySecret;
+
+ @Value("${signName}")
+ private String signName;
+
/**
* 鏌ヨ鐭俊璐﹀彿
- *
+ *
* @param smsacountid 鐭俊璐﹀彿涓婚敭
* @return 鐭俊璐﹀彿
*/
@Override
- public BaseSmsaccount selectBaseSmsaccountBySmsacountid(Long smsacountid)
- {
+ public BaseSmsaccount selectBaseSmsaccountBySmsacountid(Long smsacountid) {
return baseSmsaccountMapper.selectBaseSmsaccountBySmsacountid(smsacountid);
}
/**
* 鏌ヨ鐭俊璐﹀彿鍒楄〃
- *
+ *
* @param baseSmsaccount 鐭俊璐﹀彿
* @return 鐭俊璐﹀彿
*/
@Override
- public List<BaseSmsaccount> selectBaseSmsaccountList(BaseSmsaccount baseSmsaccount)
- {
+ public List<BaseSmsaccount> selectBaseSmsaccountList(BaseSmsaccount baseSmsaccount) {
return baseSmsaccountMapper.selectBaseSmsaccountList(baseSmsaccount);
}
/**
* 鏂板鐭俊璐﹀彿
- *
+ *
* @param baseSmsaccount 鐭俊璐﹀彿
* @return 缁撴灉
*/
@Override
- public int insertBaseSmsaccount(BaseSmsaccount baseSmsaccount)
- {
+ public int insertBaseSmsaccount(BaseSmsaccount baseSmsaccount) {
baseSmsaccount.setCreateTime(DateUtils.getNowDate());
return baseSmsaccountMapper.insertBaseSmsaccount(baseSmsaccount);
}
/**
* 淇敼鐭俊璐﹀彿
- *
+ *
* @param baseSmsaccount 鐭俊璐﹀彿
* @return 缁撴灉
*/
@Override
- public int updateBaseSmsaccount(BaseSmsaccount baseSmsaccount)
- {
+ public int updateBaseSmsaccount(BaseSmsaccount baseSmsaccount) {
baseSmsaccount.setUpdateTime(DateUtils.getNowDate());
return baseSmsaccountMapper.updateBaseSmsaccount(baseSmsaccount);
}
/**
* 鎵归噺鍒犻櫎鐭俊璐﹀彿
- *
+ *
* @param smsacountids 闇�瑕佸垹闄ょ殑鐭俊璐﹀彿涓婚敭
* @return 缁撴灉
*/
@Override
- public int deleteBaseSmsaccountBySmsacountids(Long[] smsacountids)
- {
+ public int deleteBaseSmsaccountBySmsacountids(Long[] smsacountids) {
return baseSmsaccountMapper.deleteBaseSmsaccountBySmsacountids(smsacountids);
}
/**
* 鍒犻櫎鐭俊璐﹀彿淇℃伅
- *
+ *
* @param smsacountid 鐭俊璐﹀彿涓婚敭
* @return 缁撴灉
*/
@Override
- public int deleteBaseSmsaccountBySmsacountid(Long smsacountid)
- {
+ public int deleteBaseSmsaccountBySmsacountid(Long smsacountid) {
return baseSmsaccountMapper.deleteBaseSmsaccountBySmsacountid(smsacountid);
}
+
+
+ /**
+ * 鐭俊鍙戦��
+ *
+ * @param baseSmsRequest
+ * @return
+ */
+ @Override
+ public SendSmsResponseBody sendMsg(BaseSmsRequest baseSmsRequest) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ SendSmsRequest sendSmsRequest = new SendSmsRequest().setPhoneNumbers(baseSmsRequest.getPhoneNumber()).setSignName(this.signName).setTemplateCode(baseSmsRequest.getTemplateCode()).setTemplateParam(baseSmsRequest.getTemplateParam());
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
+ return sendSmsResponse.getBody();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 鎵归噺鍙戦�佺煭淇�
+ *
+ * @param batchBaseSmsRequest
+ * @return
+ */
+ public SendBatchSmsResponseBody batchSendMsg(BatchBaseSmsRequest batchBaseSmsRequest) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ List<String> signNameJson = new ArrayList<>();
+ for (int i = 0; i < batchBaseSmsRequest.getPhoneNumber().size(); i++) {
+ signNameJson.add("\"" + this.signName + "\"");
+ }
+ SendBatchSmsRequest sendBatchSmsRequest = new SendBatchSmsRequest().setSignNameJson(signNameJson.toString()).setPhoneNumberJson(batchBaseSmsRequest.getPhoneNumber().toString()).setTemplateCode(batchBaseSmsRequest.getTemplateCode());
+ RuntimeOptions runtime = new RuntimeOptions();
+ try {
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ SendBatchSmsResponse sendBatchSmsResponse = client.sendBatchSmsWithOptions(sendBatchSmsRequest, runtime);
+ return sendBatchSmsResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public AddSmsTemplateResponseBody addSmsTemplate(TemplateSmsRequest templateSmsRequest) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ AddSmsTemplateRequest addSmsTemplateRequest = new AddSmsTemplateRequest().setTemplateType(templateSmsRequest.getTemplateType()).setTemplateName(templateSmsRequest.getTemplateName()).setTemplateContent(templateSmsRequest.getTemplateContent()).setRemark(templateSmsRequest.getRemark());
+ RuntimeOptions runtime = new RuntimeOptions();
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ AddSmsTemplateResponse addSmsTemplateResponse = client.addSmsTemplateWithOptions(addSmsTemplateRequest, runtime);
+ return addSmsTemplateResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ }
+ return null;
+ }
+
+ @Override
+ public ModifySmsTemplateResponseBody delSmsTemplate(String templateCode) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ ModifySmsTemplateRequest modifySmsTemplateRequest = new ModifySmsTemplateRequest();
+ modifySmsTemplateRequest.setTemplateCode(templateCode);
+ RuntimeOptions runtime = new RuntimeOptions();
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ ModifySmsTemplateResponse modifySmsTemplateResponse = client.modifySmsTemplateWithOptions(modifySmsTemplateRequest, runtime);
+ return modifySmsTemplateResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ }
+ return null;
+ }
+
+ @Override
+ public ModifySmsTemplateResponseBody updateSmsTemplate(TemplateSmsRequest templateSmsRequest) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ ModifySmsTemplateRequest modifySmsTemplateRequest = new ModifySmsTemplateRequest().setTemplateType(1).setTemplateName("AAA").setTemplateCode("SMS_279456451").setTemplateContent("ASD").setRemark("ASFD");
+ RuntimeOptions runtime = new RuntimeOptions();
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ ModifySmsTemplateResponse modifySmsTemplateResponse = client.modifySmsTemplateWithOptions(modifySmsTemplateRequest, runtime);
+ return modifySmsTemplateResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ }
+ return null;
+ }
+
+ @Override
+ public QuerySmsTemplateListResponseBody querySmsTemplate(Integer pageIndex, Integer pageSize) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ QuerySmsTemplateListRequest querySmsTemplateListRequest = new QuerySmsTemplateListRequest().setPageIndex(pageIndex).setPageSize(pageSize);
+ RuntimeOptions runtime = new RuntimeOptions();
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ QuerySmsTemplateListResponse querySmsTemplateListResponse = client.querySmsTemplateListWithOptions(querySmsTemplateListRequest, runtime);
+ return querySmsTemplateListResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ }
+ return null;
+ }
+
+ @Override
+ public QuerySmsTemplateResponseBody querySmsTemplateStatus(String templateCode) {
+ Client client = null;
+ try {
+ client = this.createClient();
+ QuerySmsTemplateRequest querySmsTemplateRequest = new QuerySmsTemplateRequest().setTemplateCode(templateCode);
+ RuntimeOptions runtime = new RuntimeOptions();
+ // 澶嶅埗浠g爜杩愯璇疯嚜琛屾墦鍗� API 鐨勮繑鍥炲��
+ QuerySmsTemplateResponse querySmsTemplateResponse = client.querySmsTemplateWithOptions(querySmsTemplateRequest, runtime);
+ return querySmsTemplateResponse.getBody();
+ } catch (TeaException error) {
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 濡傛湁闇�瑕侊紝璇锋墦鍗� error
+ Common.assertAsString(error.message);
+ }
+ return null;
+ }
+
+
+ private Client createClient() throws Exception {
+ Config config = new Config()
+ // 蹇呭~锛屾偍鐨� AccessKey ID
+ .setAccessKeyId(this.accessKeyId)
+ // 蹇呭~锛屾偍鐨� AccessKey Secret
+ .setAccessKeySecret(this.accessKeySecret);
+ // 璁块棶鐨勫煙鍚�
+ config.endpoint = "dysmsapi.aliyuncs.com";
+ return new Client(config);
+ }
}
--
Gitblit v1.9.3