buli
2022-04-08 c31e788728a556f9010b124ec32d3472f1e090a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Author: Bubba Li
 * Created Date: 01/25/2022
 * Purpose: Utility class for AWS Servicw
 * Test Class: AWSServiceTool
 * History: 
 *      01/25/2022 - Bubba Li - Initial Code.
 * 
 * */
public without sharing class AWSServiceTool {
    public static String getAWSToken(){
        AWS_Integration_Info__mdt awsConfiguration = [SELECT App_Id__c,Token_URL__c,App_Secret__c,Host_URL__c FROM AWS_Integration_Info__mdt  WHERE DeveloperName = 'AWS_Default_Configuration'];
        if (awsConfiguration == null) {
            System.debug('AWS_Integration_Info__mdt没配置');
            return null;
        }
        String awsAppId = awsConfiguration.App_Id__c;
        String awsAppSecret = awsConfiguration.App_Secret__c;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        String url = awsConfiguration.Token_URL__c;
        request.setEndpoint(url);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
        String token = (String)results.get('object');
        return token;
    }
}