Search in sources :

Example 6 with Client

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();
    }
}
Also used : Client(com.aliyun.dysmsapi20170525.Client)

Example 7 with Client

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();
    }
}
Also used : TemplateDetails(com.tansci.domain.message.TemplateDetails) Client(com.aliyun.dysmsapi20170525.Client) MessageVo(com.tansci.domain.message.vo.MessageVo)

Example 8 with Client

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);
}
Also used : Config(com.aliyun.teaopenapi.models.Config) SmsConfig(com.tansci.config.SmsConfig) Client(com.aliyun.dysmsapi20170525.Client)

Example 9 with Client

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());
}
Also used : Client(org.orcid.jaxb.model.client_v2.Client) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 10 with Client

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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

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)6 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 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 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)2 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