Search in sources :

Example 41 with Client

use of com.aliyun.dysmsapi20170525.Client in project rocketmq-connect by apache.

the class RocketMQSourceConnector method validate.

@Override
public void validate(KeyValue config) {
    if (StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_ID)) || StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_SECRET)) || StringUtils.isBlank(config.getString(RocketMQConstant.NAMESRV_ADDR)) || StringUtils.isBlank(config.getString(RocketMQConstant.TOPIC)) || StringUtils.isBlank(config.getString(RocketMQConstant.CONSUMER_GROUP))) {
        throw new RuntimeException("rocketmq required parameter is null !");
    }
    try {
        Config onsConfig = new Config().setAccessKeyId(config.getString(RocketMQConstant.ACCESS_KEY_ID)).setAccessKeySecret(config.getString(RocketMQConstant.ACCESS_KEY_SECRET));
        onsConfig.endpoint = OnsUtils.parseEndpoint(config.getString(RocketMQConstant.NAMESRV_ADDR));
        final Client client = new Client(onsConfig);
        OnsTopicListRequest onsTopicListRequest = new OnsTopicListRequest().setTopic(config.getString(RocketMQConstant.TOPIC)).setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID));
        final OnsTopicListResponse onsTopicListResponse = client.onsTopicList(onsTopicListRequest);
        if (onsTopicListResponse.getBody().getData().getPublishInfoDo().isEmpty()) {
            throw new RuntimeException("rocketmq required parameter topic does not exist !");
        }
        OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest().setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID)).setGroupId(config.getString(RocketMQConstant.CONSUMER_GROUP));
        final OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
        if (onsGroupListResponse.getBody().getData().getSubscribeInfoDo().isEmpty()) {
            throw new RuntimeException("rocketmq required parameter consumerGroup does not exist !");
        }
    } catch (Exception e) {
        log.error("RocketMQSinkTask | validate | error => ", e);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : OnsTopicListResponse(com.aliyun.ons20190214.models.OnsTopicListResponse) OnsGroupListRequest(com.aliyun.ons20190214.models.OnsGroupListRequest) Config(com.aliyun.teaopenapi.models.Config) OnsTopicListRequest(com.aliyun.ons20190214.models.OnsTopicListRequest) OnsGroupListResponse(com.aliyun.ons20190214.models.OnsGroupListResponse) Client(com.aliyun.ons20190214.Client)

Example 42 with Client

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

the class KnifeSmsAliServiceImpl method sendSms.

@Override
public AliSmsResult sendSms(AliSms aliSms) {
    try {
        final Client client = knifeSmsAliSenderContext.getClient();
        final SendSmsRequest sendSmsRequest = new SendSmsRequest();
        BeanUtils.copyProperties(aliSms, sendSmsRequest);
        final SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        return AliSmsResult.builder().msgId(aliSms.getMsgId()).code(sendSmsResponse.getBody().getCode()).errMsg(sendSmsResponse.getBody().getMessage()).build();
    } catch (Exception e) {
        return AliSmsResult.builder().msgId(aliSms.getMsgId()).code("-1").errMsg(e.getMessage()).build();
    }
}
Also used : SendSmsRequest(com.aliyun.dysmsapi20170525.models.SendSmsRequest) Client(com.aliyun.dysmsapi20170525.Client) SendSmsResponse(com.aliyun.dysmsapi20170525.models.SendSmsResponse)

Example 43 with Client

use of com.aliyun.dysmsapi20170525.Client in project ChatSystem by Dofmor.

the class ClientDriver method main.

public static void main(String[] args) throws ClassNotFoundException, IOException {
    System.out.println("Enter ip address: ");
    Scanner input = new Scanner(System.in);
    String ip = input.nextLine();
    ip = ip.trim();
    // Enter in own IP address when starting client to connect mutlitple clients
    Client client = new Client(ip);
    client.run();
    input.close();
}
Also used : Scanner(java.util.Scanner) Client(Client)

Example 44 with Client

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

the class DySMSUtil method createClient.

@SneakyThrows
public static Client createClient() {
    Config config = new Config();
    config.accessKeyId = AliCloudConfig.ACCESS_KEY_ID;
    config.accessKeySecret = AliCloudConfig.ACCESS_KEY_SECRET;
    return new Client(config);
}
Also used : AliCloudConfig(com.lwohvye.config.AliCloudConfig) Config(com.aliyun.teaopenapi.models.Config) Client(com.aliyun.dysmsapi20170525.Client) SneakyThrows(lombok.SneakyThrows)

Example 45 with Client

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

the class DySMSUtil method sendSms.

/**
 * 发送短信
 *
 * @param phoneNumbers
 * @param signName
 * @param templateCode
 * @param templateParam
 * @return java.lang.String
 * @date 2021/11/7 12:53 下午
 */
@SneakyThrows
public static String sendSms(String phoneNumbers, String signName, String templateCode, String templateParam) {
    Client client = DySMSUtil.createClient();
    // 1.发送短信
    SendSmsRequest sendReq = new SendSmsRequest().setPhoneNumbers(phoneNumbers).setSignName(signName).setTemplateCode(templateCode).setTemplateParam(templateParam);
    SendSmsResponse sendResp = client.sendSms(sendReq);
    String code = sendResp.body.code;
    if (!StrUtil.equals(code, "OK")) {
        log.error("错误信息: {} ", sendResp.body.message);
        return null;
    }
    return sendResp.body.bizId;
}
Also used : SendSmsRequest(com.aliyun.dysmsapi20170525.models.SendSmsRequest) Client(com.aliyun.dysmsapi20170525.Client) SendSmsResponse(com.aliyun.dysmsapi20170525.models.SendSmsResponse) SneakyThrows(lombok.SneakyThrows)

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