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();
}
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());
}
}
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());
}
}
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;
}
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.");
}
Aggregations