| | |
| | | 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()); |
| | | // 复制代码运行请自行打印 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 { |
| | | // 复制代码运行请自行打印 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(); |
| | | // 复制代码运行请自行打印 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(); |
| | | // 复制代码运行请自行打印 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(); |
| | | // 复制代码运行请自行打印 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(); |
| | | // 复制代码运行请自行打印 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(); |
| | | // 复制代码运行请自行打印 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; |
| | | } |
| | | |
| | | |
| | | public 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); |
| | | } |
| | | } |