package com.hfkj.channel.alipay.utils;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 支付宝配置
 * @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 = "2021003176605875";
    private final static String APP_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQD8W2fFUHki5Qyt6m9LO00u6AoW/XjsLtVP1uvwYbRRcRDnTk3lTEAPcopULgqjUgMIIY7xaEan3EnVQbrV+OAXA2Xs0CmBTC5kR5zfZnytUameAmkJlo5ixAfT8om6gkKOTIm0PmqcW7WvcOZtHl28G8RXFH676YBnaCS58/j3w+N9vom4tqADcHLfg9HkhFnRn2mfXbvmasgXIIPSP5XgrirLoYz3YK7OXhChFHUaip675oTHMSGe/iYcaNXfOENpI2z8RDyGwXHVFojdLX45gRkS0odGPeskuMh27wfMf9BGfeGrSSs7xjcjtauG1g8fcRpnnW1aBUD5tA0C370DAgMBAAECggEAW0tCDkrfl/UfEifWnXPVp1uAkvKd9Wu39cs9zde64R+zSsq0OXjNUAlS68NAS/dWa3GggcsEjKOP/ltqGRCRGSI8lGB2M3V47wRNRzCPeDAr2aLrlvFlj2t1nYKHuvZ2133u70sJTImM/+wrIFy08mFlNU+PzbFap44wgyk074Sxdxh3tj1a6NRfLOiBFwqI54wxoXMtvbS+YJ4rTR2PWBtv3NQrGs2AvcNHhZHsnyRDaSz0RmJ+4ifi9rGhOhfSfAvn53+r+ycJ/5rTDqZ67TWd51LkO2KyqEkPqFzN7J8cZ3tnR5+Mmlkz3QPmDsCL1n5vmZO9n2pL7I/hiDDZIQKBgQD/W92MoX+tCqPht3CjO+XQPn0h3tYrUYdyIofKUu89fw2kHhwi+nagUqEu5mrEKyC8rhlNu+KQPCEutZeflgd6CIlsJV2EINfTh5hXWlRSMW6bumAHOTEBgEnu1jNkvRhw78S8K38Wa1JWvgh5b23Zrj4hbwgN2Mzo7q6YmR5HUQKBgQD8/ZxJIWVjTtePFJP0TXhYz9vFJfbSMGD8g9/p+bS8eoSSSwv8LUJiwXJi2SwJnXYOhkFssZecVrUiAK0rqgBPXbQfiFp3G2MtDPft1mexpOxD08/ZorSsoBWpo4kMEqoO26H/wCJRFmbJn2nvzErjDmBrJ8asNYppp8soVSDSEwKBgE2iy2/XJe8hPgQA9oDaVBuE9BxZGHohFnHv56LupgfnWelcsic8SNajaJfOvAUaK6DRuaW1isNZVKlT0l5Vib5jXAyCK7VhGt0X64wbTWmT19IGzu1DSQ/wxgmUHBnzl7u2WfTvsHrLdEQlEISDCT3WSNN3Y1Z6ZIopDvIcE2WRAoGBAM+uwiWmrLyhdIOYuPzMvAbsW9W0HLLf1D53Y9GHk79GNJ6DzQrvfJflhilvbp9WDBxQSlUYVQWaiIepVn+Jx0df/QYFwX4VlYzeIIm2gNlsMihcMTzQPNGZeS8ReOfYSpJ36r0w1PsMEMVjgGvCoZdTrgNJW+by7PVfMX+iopbRAoGAQo17bUcWI72CxMRVYkaqTbkbyGdLLHMUp9XoUhYsmzWGdvbwas9OF0tPEfIjfBIfue2yTWnQRDMV7X13uvt6nvZDpeGf+eLekd/GQMZZzoKHSqIP3NjQFC+Ao9QkGRYcRcEiWd7M9fwysKudQ78oSqdbGYmH+hejKDyS5mUNVCs=";
    private final static String APP_CERT_PATH = "/home/project/gratia-pay/cert/alipay/appCertPublicKey_2021003176605875.crt";
    private final static String ALIPAY_CERT_PATH = "/home/project/gratia-pay/cert/alipay/alipayCertPublicKey_RSA2.crt";
    private final static String ALIPAY_ROOT_CERT_PATH = "/home/project/gratia-pay/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);
    }


}
