All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.com.antcloud.api.AntFinTechApiClient Maven / Gradle / Ivy

Go to download

Ant Fin Tech API SDK For Java Copyright (c) 2015-present Alipay.com, https://www.alipay.com

The newest version!
/*
 * Copyright (c) 2015-present Alipay.com, https://www.alipay.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.com.antcloud.api;

import cn.com.antcloud.api.acapi.AntCloudHttpClient;
import cn.com.antcloud.api.antcloud.*;
import cn.com.antcloud.api.antcloud.rest.AntCloudRestClient;
import cn.com.antcloud.api.antcloud.rest.AntCloudRestClientRequest;
import cn.com.antcloud.api.antcloud.rest.AntCloudRestClientResponse;
import cn.com.antcloud.api.product.*;

import java.util.Map;

/**
 * 对外client
 */
public class AntFinTechApiClient {

    private AntCloudClient     antCloudClient;
    private AntCloudProdClient antCloudProdClient;
    private AntCloudRestClient antCloudRestClient;

    /**
     * 构造对应的client
     */
    public AntFinTechApiClient(AntFinTechProfile profile) {
        AntCloudHttpClient client;
        if (profile.getHttpClient() == null){
            client = new AntCloudHttpClient(profile.getHttpConfig());
        }else{
            client = profile.getHttpClient();
        }
        String securityToken = profile.getStsConfig() != null ? profile.getStsConfig().getSecurityToken() : null;

        // set basic params
        AntCloudClient.Builder antCloudClientBuilder = AntCloudClient.newBuilder()
            .setEndpoint(profile.getBaseUrl() + "gateway.do")
            .setAccess(profile.getAccessKey(), profile.getAccessSecret())
            .setCheckSign(profile.isCheckSign()).setEnableAutoRetry(profile.isEnableAutoRetry())
            .setAutoRetryLimit(profile.getAutoRetryLimit())
            .setHttpClient(client).setSecurityToken(securityToken).setClientId(profile.getClientId());
        AntCloudProdClient.Builder antCloudProdClientBuilder = AntCloudProdClient.newBuilder()
            .setEndpoint(profile.getBaseUrl() + "gateway.do")
            .setAccess(profile.getAccessKey(), profile.getAccessSecret())
            .setCheckSign(profile.isCheckSign()).setEnableAutoRetry(profile.isEnableAutoRetry())
            .setAutoRetryLimit(profile.getAutoRetryLimit())
            .setHttpClient(client).setSecurityToken(securityToken).setClientId(profile.getClientId());
        AntCloudRestClient.Builder antCloudRestClientBuilder = AntCloudRestClient.newBuilder()
            .setEndpoint(profile.getBaseUrl() + "api")
            .setAccess(profile.getAccessKey(), profile.getAccessSecret())
            .setCheckSign(profile.isCheckSign()).setEnableAutoRetry(profile.isEnableAutoRetry())
            .setAutoRetryLimit(profile.getAutoRetryLimit())
            .setHttpClient(client).setSecurityToken(securityToken);

        // build clients
        antCloudClient = antCloudClientBuilder.build();
        antCloudProdClient = antCloudProdClientBuilder.build();
        antCloudRestClient = antCloudRestClientBuilder.build();
    }

    /**
     * 执行
     * @param request
     * @param 
     * @return
     * @throws Exception
     */
    public  T execute(AntCloudRequest request) throws Exception {
        return antCloudClient.execute(request);
    }

    /**
     * 执行
     * @param request
     * @return
     * @throws Exception
     */
    public AntCloudClientResponse execute(AntCloudClientRequest request) throws Exception {
        return antCloudClient.execute(request);
    }

    /**
     * 执行
     * @param request
     * @param 
     * @return
     * @throws Exception
     */
    public  T execute(AntCloudProdRequest request) throws Exception {
        return antCloudProdClient.execute(request);
    }

    /**
     * 执行
     * @param request
     * @param headers
     * @param 
     * @return
     * @throws Exception
     */
    public  T execute(AntCloudProdRequest request, Map headers) throws Exception {
        return antCloudProdClient.execute(request, headers);
    }

    /**
     * 执行
     * @param request
     * @return
     * @throws Exception
     */
    public AntCloudProdClientResponse execute(AntCloudProdClientRequest request) throws Exception {
        return antCloudProdClient.execute(request);
    }

    /**
     * 执行
     * @param request
     * @return
     */
    public AntCloudRestClientResponse execute(AntCloudRestClientRequest request) {
        return antCloudRestClient.execute(request);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy