use of com.aliyun.ons20190214.Client in project tansci by typ1805.
the class AliSmsServiceImpl method modifySmsTemplate.
/**
* @MonthName: modifySmsTemplate
* @Description: 修改未通过审核的短信模板
* @Author: tanyp
* @Date: 2021/6/7 14:50
* @Param: [template]
* @return: MessageVo
*/
@Override
public MessageVo modifySmsTemplate(SmsTemplateDto template) {
try {
log.info("======修改未通过审核的短信模板,请求参数:{}", JSON.toJSON(template));
Client client = createClient();
ModifySmsTemplateRequest request = new ModifySmsTemplateRequest();
request.setTemplateType(template.getTemplateType());
request.setTemplateName(template.getTemplateName());
request.setTemplateCode(template.getTemplateCode());
request.setTemplateContent(template.getTemplateContent());
request.setRemark(template.getRemark());
ModifySmsTemplateResponse res = client.modifySmsTemplate(request);
if (Objects.equals(Constants.NEWS_SUCCESS_CODE, res.body.getCode())) {
log.info("======修改未通过审核的短信模板,返回值:{}", JSON.toJSON(res.body));
return MessageVo.builder().code(Constants.NEWS_SUCCESS_CODE).message(Constants.NEWS_SUCCESS_MESSAGE).build();
} else {
log.info("======修改未通过审核的短信模板,返回值:{}", JSON.toJSON(res.body));
return MessageVo.builder().code(Constants.NEWS_FAIL_CODE).message(Constants.NEWS_FAIL_MESSAGE).build();
}
} catch (Exception e) {
log.error("======修改未通过审核的短信模板,异常:{}", e.getMessage());
e.printStackTrace();
return MessageVo.builder().code(Constants.NEWS_FAIL_CODE).message(Constants.NEWS_FAIL_MESSAGE).build();
}
}
use of com.aliyun.ons20190214.Client in project tansci by typ1805.
the class AliSmsServiceImpl method send.
/**
* @MonthName: send
* @Description: 发短信
* @Author: tanyp
* @Date: 2021/6/7 14:50
* @Param: [dto]
* @return: MessageVo
*/
@Override
public MessageVo send(MessageDto dto) {
try {
log.info("======发送短信开始,请求参数:{}", JSON.toJSON(dto));
Client client = createClient();
// 组装请求对象
SendSmsRequest request = new SendSmsRequest();
// 外部流水扩展字段
String outId = UUID.randomUUID().toString();
request.setOutId(outId);
// 支持对多个手机号码发送短信,手机号码之间以英文逗号(,)分隔。上限为1000个手机号码。批量调用相对于单条调用及时性稍有延迟。
request.setPhoneNumbers(dto.getPhone());
// 短信签名名称
request.setSignName(smsConfig.getSignName());
// 短信模板ID
request.setTemplateCode(dto.getCode());
// 短信模板变量对应的实际值,JSON格式。如果JSON中需要带换行符,请参照标准的JSON协议处理。
request.setTemplateParam(JSON.toJSONString(dto.getParam()));
// 发送短信
SendSmsResponse res = client.sendSms(request);
TemplateDetails details = new TemplateDetails();
MessageVo message = MessageVo.builder().build();
if (Objects.equals(Constants.NEWS_SUCCESS_CODE, res.body.getCode())) {
log.info("======发送短信成功,返回值:{}", JSON.toJSON(res.body));
message.setCode(Constants.NEWS_SUCCESS_CODE);
message.setMessage(Constants.NEWS_SUCCESS_MESSAGE);
details.setState(0);
} else {
log.info("======发送短信失败,返回值:{}", JSON.toJSON(res.body));
message.setCode(Constants.NEWS_FAIL_CODE);
message.setMessage(Constants.NEWS_FAIL_MESSAGE);
details.setState(1);
}
details.setCode(dto.getCode());
details.setContent(JSON.toJSONString(request));
details.setSendTime(LocalDateTime.now());
templateDetailsService.save(details);
return message;
} catch (Exception e) {
log.error("======发送短信异常:{}", e.getMessage());
e.printStackTrace();
return MessageVo.builder().code(Constants.NEWS_FAIL_CODE).message(Constants.NEWS_FAIL_MESSAGE).build();
}
}
use of com.aliyun.ons20190214.Client in project tansci by typ1805.
the class AliSmsServiceImpl method createClient.
/**
* @MonthName: createClient
* @Description: SK初始化账号Client
* @Author: tanyp
* @Date: 2021/6/7 15:44
* @Param: [accessId, accessKey, endpoint]
* @return: com.aliyun.teaopenapi.Client
*/
public Client createClient() throws Exception {
Config config = new Config();
config.accessKeyId = smsConfig.getAccessId();
config.accessKeySecret = smsConfig.getAccessKey();
config.endpoint = smsConfig.getEndpoint();
return new Client(config);
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientDetailsManagerTest method testGetClient.
@Test
public void testGetClient() {
Client client = clientDetailsManager.getClient("APP-6666666666666666");
assertNotNull(client);
assertEquals("Source Client 2", client.getName());
assertEquals("A test source client", client.getDescription());
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class JpaJaxbClientAdapterTest method toEntity_withExistingEntityTest.
@Test
public void toEntity_withExistingEntityTest() {
Client client = getClient();
ClientDetailsEntity existingEntity = getClientDetailsEntity();
existingEntity = adapter.toEntity(client, existingEntity);
assertEquals(getClientDetailsEntity(), existingEntity);
}
Aggregations