Search in sources :

Example 21 with HttpProfile

use of com.tencentcloudapi.common.profile.HttpProfile in project tencentcloud-sdk-java by TencentCloud.

the class STSCredential method updateCredential.

private void updateCredential() throws TencentCloudSDKException {
    Credential cred = new Credential(secretId, secretKey);
    HttpProfile httpProfile = new HttpProfile();
    httpProfile.setEndpoint("sts.tencentcloudapi.com");
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    CommonClient client = new CommonClient("sts", "2018-08-13", cred, "ap-guangzhou", clientProfile);
    String resp = client.call("AssumeRole", "{\"RoleArn\":\"" + roleArn + "\"," + "\"RoleSessionName\":\"" + roleSessionName + "\"}");
    Map<String, Object> map = new Gson().fromJson(resp, new TypeToken<HashMap<String, Object>>() {
    }.getType());
    Map<String, Object> respmap = (Map<String, Object>) map.get("Response");
    Map<String, String> credmap = (Map<String, String>) respmap.get("Credentials");
    tmpSecretId = credmap.get("TmpSecretId");
    tmpSecretKey = credmap.get("TmpSecretKey");
    token = credmap.get("Token");
    expiredTime = ((Double) respmap.get("ExpiredTime")).intValue();
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) TypeToken(com.google.gson.reflect.TypeToken) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) Gson(com.google.gson.Gson) Map(java.util.Map) HashMap(java.util.HashMap) CommonClient(com.tencentcloudapi.common.CommonClient)

Example 22 with HttpProfile

use of com.tencentcloudapi.common.profile.HttpProfile in project tencentcloud-sdk-java by TencentCloud.

the class SignatureTest method testGetHmacSHA1.

@Test
public void testGetHmacSHA1() {
    Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
    HttpProfile httpProfile = new HttpProfile();
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    clientProfile.setSignMethod("HmacSHA1");
    httpProfile.setReqMethod("GET");
    CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
    DescribeInstancesRequest req = new DescribeInstancesRequest();
    try {
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        Assert.assertTrue(resp.getTotalCount() >= 0);
    } catch (TencentCloudSDKException e) {
        fail(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse) Test(org.junit.Test)

Example 23 with HttpProfile

use of com.tencentcloudapi.common.profile.HttpProfile in project tencentcloud-sdk-java-intl-en by TencentCloud.

the class DescribeInstances method main.

public static void main(String[] args) {
    try {
        Credential cred = new Credential("your-secret-id", "your-secret-key");
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setReqMethod("GET");
        httpProfile.setConnTimeout(30);
        httpProfile.setEndpoint("cvm.ap-shanghai.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setSignMethod("HmacSHA256");
        clientProfile.setHttpProfile(httpProfile);
        CvmClient client = new CvmClient(cred, "ap-shanghai", clientProfile);
        DescribeInstancesRequest req = new DescribeInstancesRequest();
        Filter respFilter = new Filter();
        respFilter.setName("zone");
        respFilter.setValues(new String[] { "ap-shanghai-1", "ap-shanghai-2" });
        req.setFilters(new Filter[] { respFilter });
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        System.out.println(DescribeInstancesResponse.toJsonString(resp));
        System.out.println(resp.getTotalCount());
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) Filter(com.tencentcloudapi.cvm.v20170312.models.Filter) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)

Example 24 with HttpProfile

use of com.tencentcloudapi.common.profile.HttpProfile in project MaxKey by dromara.

the class SmsOtpAuthnTencentCloud method produce.

@Override
public boolean produce(UserInfo userInfo) {
    // 手机号
    String mobile = userInfo.getMobile();
    if (mobile != null && !mobile.equals("")) {
        try {
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
            String token = this.genToken(userInfo);
            String params = "{\"PhoneNumberSet\":[\"" + mobile + "\"]," + "\"TemplateID\":\"" + templateId + "\",\"Sign\":\"" + sign + "\"," + "\"TemplateParamSet\":[\"" + token + "\",\"" + this.interval + "\"]," + "\"SmsSdkAppid\":\"" + smsSdkAppid + "\"}";
            SendSmsRequest req = SendSmsRequest.fromJsonString(params, SendSmsRequest.class);
            SendSmsResponse resp = client.SendSms(req);
            logger.debug("responseString " + SendSmsRequest.toJsonString(resp));
            if (resp.getSendStatusSet()[0].getCode().equalsIgnoreCase("Ok")) {
                this.optTokenStore.store(userInfo, token, userInfo.getMobile(), OtpTypes.SMS);
                return true;
            }
        } catch (Exception e) {
            logger.error(" produce code error ", e);
        }
    }
    return false;
}
Also used : SmsClient(com.tencentcloudapi.sms.v20190711.SmsClient) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) SendSmsRequest(com.tencentcloudapi.sms.v20190711.models.SendSmsRequest) SendSmsResponse(com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)

Example 25 with HttpProfile

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

the class SensitiveWordsRecognitionServiceImpl method init.

public void init(NLPProfile profile) throws CloudSDKException {
    NLPProfileValidator.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);
    NlpClient client = new NlpClient(cred, profile.getRegion(), clientProfile);
    this.nlpClient = client;
    LOG.info("Init nlp client successfully.");
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) NlpClient(com.tencentcloudapi.nlp.v20190408.NlpClient)

Aggregations

HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)41 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)40 Credential (com.tencentcloudapi.common.Credential)39 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)26 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)8 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)8 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)8 TciClient (com.tencentcloudapi.tci.v20190318.TciClient)6 SoeClient (com.tencentcloudapi.soe.v20180724.SoeClient)5 Test (org.junit.Test)5 OcrClient (com.tencentcloudapi.ocr.v20181119.OcrClient)3 HashMap (java.util.HashMap)3 Bean (org.springframework.context.annotation.Bean)3 CmqConfig (com.qcloud.cmq.entity.CmqConfig)2 CommonClient (com.tencentcloudapi.common.CommonClient)2 Filter (com.tencentcloudapi.cvm.v20170312.models.Filter)2 EccClient (com.tencentcloudapi.ecc.v20181213.EccClient)2 SmsClient (com.tencentcloudapi.sms.v20190711.SmsClient)2 SendSmsRequest (com.tencentcloudapi.sms.v20190711.models.SendSmsRequest)2 SendSmsResponse (com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)2