package com.jsowell.alipay.factory;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class AlipayClientFactory {
    private static AlipayClient alipayClient;

    public AlipayClientFactory(
            @Value("${alipay.gatewayHost}") String gatewayUrl,
            @Value("${alipay.appId}") String appId,
            @Value("${alipay.merchantPrivateKey}") String appPrivateKey,
            @Value("${alipay.alipayPublicKey}") String alipayPublicKey,
            @Value("${alipay.charset}") String charset,
            @Value("${alipay.signType}") String signType
    ) {
        // 初始化 AlipayClient
        alipayClient = new DefaultAlipayClient(
                gatewayUrl,
                appId,
                appPrivateKey,
                "json",
                charset,
                alipayPublicKey,
                signType
        );
    }

    public static AlipayClient getAlipayClient() {
        return alipayClient;
    }
}
