Search in sources :

Example 1 with Client

use of com.aliyun.dysmsapi20170525.Client in project eladmin by lWoHvYe.

the class DySMSUtil method querySendDetails.

/**
 * 查询结果
 *
 * @param phoneNumbers
 * @param bizId
 * @date 2021/11/7 12:52 下午
 */
@SneakyThrows
public static void querySendDetails(@NotNull String phoneNumbers, String bizId) {
    Client client = DySMSUtil.createClient();
    // 3.查询结果
    for (String phoneNum : phoneNumbers.split(",")) {
        QuerySendDetailsRequest queryReq = new QuerySendDetailsRequest().setPhoneNumber(phoneNum.trim()).setBizId(bizId).setSendDate(DateUtil.today()).setPageSize(10L).setCurrentPage(1L);
        QuerySendDetailsResponse queryResp = client.querySendDetails(queryReq);
        var dtos = queryResp.body.smsSendDetailDTOs.smsSendDetailDTO;
        // 打印结果
        for (var dto : dtos) {
            if (ObjectUtil.equals(dto.sendStatus, 3L)) {
                log.info(" {} 发送成功,接收时间: {} ", dto.phoneNum, dto.receiveDate);
            } else if (ObjectUtil.equals(dto.sendStatus, 2L)) {
                log.info(" {} 发送失败", dto.phoneNum);
            } else {
                log.info(" {} 正在发送中...", dto.phoneNum);
            }
        }
    }
}
Also used : QuerySendDetailsResponse(com.aliyun.dysmsapi20170525.models.QuerySendDetailsResponse) QuerySendDetailsRequest(com.aliyun.dysmsapi20170525.models.QuerySendDetailsRequest) Client(com.aliyun.dysmsapi20170525.Client) SneakyThrows(lombok.SneakyThrows)

Example 2 with Client

use of com.aliyun.dysmsapi20170525.Client in project knife-starter by 1120023921.

the class KnifeSmsAliSenderContextImpl method buildClient.

private Client buildClient(AliAccount aliAccount) throws AliClientException {
    final Config config = new Config().setAccessKeyId(aliAccount.getAccessKeyId()).setAccessKeySecret(aliAccount.getAccessSecret());
    // 访问的域名
    config.endpoint = "dysmsapi.aliyuncs.com";
    try {
        return new Client(config);
    } catch (Exception e) {
        throw new AliClientException("构造阿里云短信Client失败");
    }
}
Also used : AliClientException(com.wingice.msg.ali.exception.AliClientException) Config(com.aliyun.teaopenapi.models.Config) Client(com.aliyun.dysmsapi20170525.Client) AliAccountNotFoundException(com.wingice.msg.ali.exception.AliAccountNotFoundException) MultiAliAccountException(com.wingice.msg.ali.exception.MultiAliAccountException) AliClientException(com.wingice.msg.ali.exception.AliClientException)

Example 3 with Client

use of com.aliyun.dysmsapi20170525.Client in project tansci by typ1805.

the class AliSmsServiceImpl method querySmsTemplate.

/**
 * @MonthName: querySmsTemplate
 * @Description: 查询短信模板的审核状态
 * @Author: tanyp
 * @Date: 2021/6/7 14:50
 * @Param: [template]
 * @return: MessageVo
 */
@Override
public MessageVo querySmsTemplate(SmsTemplateDto template) {
    try {
        log.info("======查询短信模板的审核状态,请求参数:{}", JSON.toJSON(template));
        Client client = createClient();
        QuerySmsTemplateRequest request = new QuerySmsTemplateRequest();
        request.setTemplateCode(template.getTemplateCode());
        QuerySmsTemplateResponse res = client.querySmsTemplate(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).state(res.body.getTemplateStatus()).templateCode(res.body.templateCode).reason(res.body.reason).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();
    }
}
Also used : Client(com.aliyun.dysmsapi20170525.Client)

Example 4 with Client

use of com.aliyun.dysmsapi20170525.Client in project tansci by typ1805.

the class AliSmsServiceImpl method addSmsTemplate.

/**
 * @MonthName: addSmsTemplate
 * @Description: 申请短信模板
 * @Author: tanyp
 * @Date: 2021/6/7 14:50
 * @Param: [template]
 * @return: MessageVo
 */
@Override
public MessageVo addSmsTemplate(SmsTemplateDto template) {
    try {
        log.info("======申请短信模板,请求参数:{}", JSON.toJSON(template));
        Client client = createClient();
        AddSmsTemplateRequest request = new AddSmsTemplateRequest();
        request.setTemplateType(template.getTemplateType());
        request.setTemplateName(template.getTemplateName());
        request.setTemplateContent(template.getTemplateContent());
        request.setRemark(template.getRemark());
        AddSmsTemplateResponse res = client.addSmsTemplate(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).templateCode(res.getBody().templateCode).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();
    }
}
Also used : Client(com.aliyun.dysmsapi20170525.Client)

Example 5 with Client

use of com.aliyun.dysmsapi20170525.Client in project tansci by typ1805.

the class AliSmsServiceImpl method deleteSmsTemplate.

/**
 * @MonthName: deleteSmsTemplate
 * @Description: 删除短信模板
 * @Author: tanyp
 * @Date: 2021/6/7 14:50
 * @Param: [template]
 * @return: MessageVo
 */
@Override
public MessageVo deleteSmsTemplate(SmsTemplateDto template) {
    try {
        log.info("======删除短信模板,请求参数:{}", JSON.toJSON(template));
        Client client = createClient();
        DeleteSmsTemplateRequest request = new DeleteSmsTemplateRequest();
        request.setTemplateCode(template.getTemplateCode());
        DeleteSmsTemplateResponse res = client.deleteSmsTemplate(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);
        return MessageVo.builder().code(Constants.NEWS_FAIL_CODE).message(Constants.NEWS_FAIL_MESSAGE).build();
    }
}
Also used : Client(com.aliyun.dysmsapi20170525.Client)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)7 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)3 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2