package com.hfkj.common.alipay;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;

/**
 * 支付宝配置
 * @className: AlipayConfig
 * @author: HuRui
 * @date: 2023/2/13
 **/
public class AlipayUtils {
    private final static String serverUrl = "https://openapi.alipay.com/gateway.do";
    private final static String appId = "2021004149636316";
    private final static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCBObA50oioZEmUGTsSPJghAUf/lRT+TC+9HNyu0To3bSkLZSlEide2kszQnJk32+60QM26OudBaUnUCHkzv0++232hKPzSXHVVUykvu74itAtH66YxO2RqLt/OuTRBnFpiYPs0lXEoNeAsUQ92I6TOCrS8db/76Tvuye0nSH5lAJ6mwq8Hgo/+RQNRvIq3RFvWQOMD5lTp2lWsZ7x4FONtSmPCXd4fdYbKd1QrBHMZCQjBAn12YA+X+lmSNlnFo/xOu5rvKwMGJgvFLYxFdNHXgZUZfrjzOKA+sqq8lRfyVo4YHqRDi5bH1Ln2VUqZL9HidIHZx0YSKlfvdeuzR8abAgMBAAECggEAOOpwrLcGy6wIIDuQofKgSoEm9fHyoiJqMFAC/thWXM0uc79lkrNnmBlGLmeasFik5S1Zrzl8W3oFM2dcAqezdutzhMTpvblNUHxlOonlL6G/CjlHJI31JzNoDcPSuUclJAl0+u8LPNul1b8KIU2Hq9xZSFxQZ6KNbBnx4whx6wfZBvV06oy7hu7vfnWvobidooiGAxJuffRKuWQS8w6BPC7h2vz8AbiADHMA1YgCwIwroPbhU8QFY07PGeirAyJnrphZOIKSKwY9m8RK/AyBKL0iDopX/7nhdJ1LEiVbBlw50ej2VMAqfb0bA7z7zhhxwYCi6LN9DZfLQW9/Z3W8mQKBgQDyHdT/tex+s07zg4TUgAmTTqSyqp64j9Qbgdde2tTHUPjmOXXOpL5PvvT6xOu6dTwq5TwwqdsyVLh5T/cnYzqqXaZZzv6iWi1qajbLElf1r7bPquF2KCa0n2ZdxcYBH78bvIIuD7kGfmJDSA5a+1cgHJYZVer7MvYFf2id6H617wKBgQCIoqlgvYzTVDdXevI5LcOr1CfsBsuXoUdc8aUyFa1D6rj41wHXonqtmr/3tlo03HbUAQT0u/CjMf8raoW/2D1Sv7EnL3udb51qzYYj082x0DNUAs9CQq+AO8qhs8h4sXJGki7rjtJUtOfs1VFg84I5Z7IT9xKQMvsp2gmErpTGFQKBgQDIQYBxWEmZqjl9FKUDFjvVSVDULmdFhEEN12EJpbokeYbE9XXJS13Vm74IxGOtP1ZarGwSXAtfH8/NFyT3wQ0+6GK1GY5nPmsd/2f+otd58LImJdKB5kfNUaJboT9aoqVxDYQnEP4aruIbgDfPbN/tQXes0PGgf9AZT/55zVkwpQKBgFD9kkbctKADuHYrU28fOHAe5rcaZA3yNHncZt5kSPsMJC6kS9xE3FERfJ7ZwWi6Edmi7QwgZwhlN2rFzpgkFl15cQnYNH7izT2kq9GK18+BqRswOyh8nMj3KCpnhfo8vI8mUZehZf196kfRPlaooNVkKQN6nc9J2OU68A9s6JTtAoGBAOTabPjBoxWeNQwF2pR4E5SfXaMBKC7a6/+AMn9oUb9lvTPZtxXkIZkvn5iRz2UmrygLw4UCWKC3T7ujFIO0lHWktzVv2qPbINbfW10p0S/ioFvNxzP+ZDfSFrN03Zoh05H+0NXj1e4REMtIrbx5R+sJn6CVftpYfFcQd/lXy8MR";
    private final static String APP_CERT_PATH = "/home/project/oil/cert/alipay/appCertPublicKey_2021004149636316.crt";
    private final static String ALIPAY_CERT_PATH = "/home/project/oil/cert/alipay/alipayCertPublicKey_RSA2.crt";
    private final static String ALIPAY_ROOT_CERT_PATH = "/home/project/oil/cert/alipay/alipayRootCert.crt";

    /**
     * 初始化客户端请求
     * @return
     */
    public static AlipayClient initClient() throws Exception {
        AlipayConfig alipayConfig = new AlipayConfig();
        // 设置网关地址
        alipayConfig.setServerUrl(serverUrl);
        // 设置应用APPID
        alipayConfig.setAppId(appId);
        // 设置应用私钥
        alipayConfig.setPrivateKey(APP_PRIVATE_KEY);
        // 设置应用公钥证书路径
        alipayConfig.setAppCertPath(APP_CERT_PATH);
        // 设置支付宝公钥证书路径
        alipayConfig.setAlipayPublicCertPath(ALIPAY_CERT_PATH);
        // 设置支付宝根证书路径
        alipayConfig.setRootCertPath(ALIPAY_ROOT_CERT_PATH);
        // 设置请求格式，固定值json
        alipayConfig.setFormat("json");
        // 设置字符集
        alipayConfig.setCharset("utf-8");
        // 设置签名类型
        alipayConfig.setSignType("RSA2");
        return new DefaultAlipayClient(alipayConfig);
    }


}
