Search in sources :

Example 6 with Credential

use of com.tencentcloudapi.common.Credential in project easyj by easyj-projects.

the class DefaultTencentCloudIdCardOcrServiceImpl method newOcrClient.

private OcrClient newOcrClient(TencentCloudIdCardOcrConfig config) {
    // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
    // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
    Credential cred = this.newCredential(config);
    // 实例化一个HTTP选项,可选的,没有特殊需求可以跳过
    HttpProfile httpProfile = this.newHttpProfile(config);
    // 实例化一个client选项,可选的,没有特殊需求可以跳过
    ClientProfile clientProfile = this.newClientProfile(httpProfile, config);
    // 实例化要请求产品的client对象,clientProfile是可选的
    return new OcrClient(cred, config.getRegion(), clientProfile);
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient)

Example 7 with Credential

use of com.tencentcloudapi.common.Credential in project longmarch by yuyueqty.

the class MsgUtil method sendSms.

public static List<MessageResultInfoVO> sendSms(String code, String[] phoneNumber, MsgConf conf) {
    List<MessageResultInfoVO> messageResultInfoVOList = new ArrayList<>();
    /* * 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey */
    // 密钥对在腾讯云搜索即可找到
    Credential cred = new Credential(conf.getSecretId(), conf.getSecretKey());
    // 实例化一个http选项,可选,没有特殊需求可以跳过
    HttpProfile httpProfile = new HttpProfile();
    /* SDK默认使用POST方法。
         * 如果你一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */
    httpProfile.setReqMethod("POST");
    /* SDK有默认的超时时间,非必要请不要进行调整*/
    httpProfile.setConnTimeout(60);
    /* SDK会自动指定域名。通常是不需要特地指定域名的,但是如果你访问的是金融区的服务
         * 则必须手动指定域名,例如sms的上海金融区域名: sms.ap-shanghai-fsi.tendentious.com */
    httpProfile.setEndpoint(conf.getDomain());
    /* 非必要步骤:
         * 实例化一个客户端配置对象,可以指定超时时间等配置 */
    ClientProfile clientProfile = new ClientProfile();
    /* SDK默认用TC3-HMAC-SHA256进行签名
         * 非必要请不要修改这个字段 */
    clientProfile.setSignMethod("HmacSHA256");
    clientProfile.setHttpProfile(httpProfile);
    /* 实例化要请求产品(以sms为例)的client对象
         * 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,或者引用预设的常量 */
    SmsClient client = new SmsClient(cred, conf.getRegionId(), clientProfile);
    /* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数 */
    SendSmsRequest req = new SendSmsRequest();
    /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
    req.setSmsSdkAppId(conf.getSdkAppId());
    /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,签名信息可登录 [短信控制台] 查看 */
    req.setSignName(conf.getSignName());
    /* 国际/港澳台短信 SenderId: 国内短信填空,默认未开通,如需开通请联系 [sms helper] */
    req.setSenderId("");
    /* 用户的 session 内容: 可以携带用户侧 ID 等上下文信息,server 会原样返回  这个参数需要带上*/
    req.setSessionContext("");
    /* 短信号码扩展号: 默认未开通,如需开通请联系 [sms helper]*/
    req.setExtendCode("");
    /* 模板 ID: 必须填写已审核通过的模板 ID。模板ID可登录 [短信控制台] 查看 */
    req.setTemplateId(conf.getTemplateCode());
    /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
         * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */
    req.setPhoneNumberSet(phoneNumber);
    /* 模板参数: 若无模板参数,则设置为空 */
    String[] templateParamSet = { code, conf.getExpireMinute() };
    System.out.println(code);
    req.setTemplateParamSet(templateParamSet);
    /* 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
         * 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应 */
    try {
        messageResultInfoVOList = MessageResultInfoVO.build(client.SendSms(req));
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
    return messageResultInfoVOList;
}
Also used : SmsClient(com.tencentcloudapi.sms.v20210111.SmsClient) Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) ArrayList(java.util.ArrayList) SendSmsRequest(com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)

Example 8 with Credential

use of com.tencentcloudapi.common.Credential in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method init.

public void init(VodProfile profile) throws CloudSDKException {
    VodProfileValidator.validate(profile);
    Credential cred = new Credential(profile.getAccessKey(), profile.getSecretKey());
    HttpProfile httpProfile = new HttpProfile();
    httpProfile.setEndpoint(profile.getEndpoint());
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    VodClient client = new VodClient(cred, profile.getRegion(), clientProfile);
    this.vodClient = client;
    LOG.info("Init vod client successfully.");
}
Also used : VodClient(com.tencentcloudapi.vod.v20180717.VodClient) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile)

Example 9 with Credential

use of com.tencentcloudapi.common.Credential in project cloud-sdk by mizhousoft.

the class TencentOCRServiceImpl method init.

public void init(OCRProfile config) throws CloudSDKException {
    validate(config);
    Credential cred = new Credential(config.getAccessKey(), config.getSecretKey());
    StsClient cosClient = new StsClient(cred, config.getRegion());
    HttpProfile httpProfile = new HttpProfile();
    httpProfile.setEndpoint("ocr.tencentcloudapi.com");
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    OcrClient ocrClient = new OcrClient(cred, config.getRegion(), clientProfile);
    this.cosClient = cosClient;
    this.ocrClient = ocrClient;
    LOG.info("Init sts and ocr client successfully.");
}
Also used : StsClient(com.tencentcloudapi.sts.v20180813.StsClient) TempCredential(com.mizhousoft.cloudsdk.TempCredential) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient)

Example 10 with Credential

use of com.tencentcloudapi.common.Credential in project ranger by apache.

the class RangerTencentKMSProvider method createKMSClient.

public static KmsClient createKMSClient(Configuration conf) throws Exception {
    String tencentClientId = conf.get(TENCENT_CLIENT_ID);
    if (StringUtils.isEmpty(tencentClientId)) {
        throw new Exception("Tencent KMS is enabled, but client id is not configured");
    }
    String tencentClientSecret = conf.get(TENCENT_CLIENT_SECRET);
    String tencentClientRegion = conf.get(TENCENT_CLIENT_REGION);
    return new KmsClient(new Credential(tencentClientId, tencentClientSecret), tencentClientRegion);
}
Also used : Credential(com.tencentcloudapi.common.Credential) KmsClient(com.tencentcloudapi.kms.v20190118.KmsClient) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException)

Aggregations

Credential (com.tencentcloudapi.common.Credential)55 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)41 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)39 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)39 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)12 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)12 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)10 CommonClient (com.tencentcloudapi.common.CommonClient)9 Test (org.junit.Test)8 TciClient (com.tencentcloudapi.tci.v20190318.TciClient)6 SoeClient (com.tencentcloudapi.soe.v20180724.SoeClient)5 OcrClient (com.tencentcloudapi.ocr.v20181119.OcrClient)3 SmsClient (com.tencentcloudapi.sms.v20210111.SmsClient)3 HashMap (java.util.HashMap)3 CmqConfig (com.qcloud.cmq.entity.CmqConfig)2 DescribeZonesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesRequest)2 DescribeZonesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesResponse)2 Filter (com.tencentcloudapi.cvm.v20170312.models.Filter)2 EccClient (com.tencentcloudapi.ecc.v20181213.EccClient)2 SendSmsRequest (com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)2