Search in sources :

Example 6 with Config

use of com.aliyun.teaopenapi.models.Config in project lilishop by lilishop.

the class SmsUtilAliImplService method createClient.

/**
 * 初始化账号Client
 *
 * @return Client 短信操作util
 */
public com.aliyun.dysmsapi20170525.Client createClient() {
    try {
        Setting setting = settingService.get(SettingEnum.SMS_SETTING.name());
        if (StrUtil.isBlank(setting.getSettingValue())) {
            throw new ServiceException(ResultCode.ALI_SMS_SETTING_ERROR);
        }
        SmsSetting smsSetting = new Gson().fromJson(setting.getSettingValue(), SmsSetting.class);
        Config config = new Config();
        // 您的AccessKey ID
        config.accessKeyId = smsSetting.getAccessKeyId();
        // 您的AccessKey Secret
        config.accessKeySecret = smsSetting.getAccessSecret();
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    } catch (Exception e) {
        log.error("短信初始化错误", e);
    }
    return null;
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) SmsSetting(cn.lili.modules.system.entity.dto.SmsSetting) Config(com.aliyun.teaopenapi.models.Config) SmsSetting(cn.lili.modules.system.entity.dto.SmsSetting) Setting(cn.lili.modules.system.entity.dos.Setting) Gson(com.google.gson.Gson) ServiceException(cn.lili.common.exception.ServiceException)

Example 7 with Config

use of com.aliyun.teaopenapi.models.Config in project cloud-sdk by mizhousoft.

the class AliyunSendSmsClient method init.

public void init(AliyunSmsProfile profile) throws CloudSDKException {
    AssertUtils.notNull(profile.getAccessKeyId(), "Access key id is null.");
    AssertUtils.notNull(profile.getAccessKeySecret(), "Access key secret is null.");
    AssertUtils.notNull(profile.getEndpoint(), "Endpoint is null.");
    Config config = new Config().setAccessKeyId(profile.getAccessKeyId()).setAccessKeySecret(profile.getAccessKeySecret()).setEndpoint(profile.getEndpoint());
    try {
        this.client = new com.aliyun.dysmsapi20170525.Client(config);
    } catch (Exception e) {
        throw new CloudSDKException("Init sms client failed.", e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) Config(com.aliyun.teaopenapi.models.Config) Client(com.aliyun.dysmsapi20170525.Client) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException)

Example 8 with Config

use of com.aliyun.teaopenapi.models.Config in project dingtalk-app-server by nju-softeng.

the class BaseApi method createClient.

/**
 * 使用 Token 初始化账号Client
 * @return Client
 * @throws Exception
 */
public com.aliyun.dingtalkdrive_1_0.Client createClient() throws Exception {
    Config config = new Config();
    config.protocol = "https";
    config.regionId = "central";
    return new com.aliyun.dingtalkdrive_1_0.Client(config);
}
Also used : Config(com.aliyun.teaopenapi.models.Config) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) OSSClient(com.aliyun.oss.OSSClient)

Example 9 with Config

use of com.aliyun.teaopenapi.models.Config in project rocketmq-connect by apache.

the class RocketMQSinkConnector 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))) {
        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 !");
        }
    } catch (Exception e) {
        log.error("RocketMQSinkTask | validate | error => ", e);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : OnsTopicListResponse(com.aliyun.ons20190214.models.OnsTopicListResponse) Config(com.aliyun.teaopenapi.models.Config) OnsTopicListRequest(com.aliyun.ons20190214.models.OnsTopicListRequest) Client(com.aliyun.ons20190214.Client)

Example 10 with Config

use of com.aliyun.teaopenapi.models.Config 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)

Aggregations

Config (com.aliyun.teaopenapi.models.Config)13 Client (com.aliyun.dysmsapi20170525.Client)4 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2 AliyunConfig (com.baiyi.opscloud.common.datasource.AliyunConfig)2 ServiceException (cn.lili.common.exception.ServiceException)1 Setting (cn.lili.modules.system.entity.dos.Setting)1 SmsSetting (cn.lili.modules.system.entity.dto.SmsSetting)1 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)1 OnsGroupListRequest (com.aliyun.ons20190214.models.OnsGroupListRequest)1 OnsGroupListResponse (com.aliyun.ons20190214.models.OnsGroupListResponse)1 OSSClient (com.aliyun.oss.OSSClient)1 DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)1 DingTalkClient (com.dingtalk.api.DingTalkClient)1 Gson (com.google.gson.Gson)1 AliCloudConfig (com.lwohvye.config.AliCloudConfig)1 CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)1 SmsConfig (com.tansci.config.SmsConfig)1 AliAccountNotFoundException (com.wingice.msg.ali.exception.AliAccountNotFoundException)1