package com.tzy.framework.pay.config;

import com.alipay.api.AlipayConfig;
import com.tzy.common.utils.StringUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.*;

/**
 *
 */
@Data
@Component
@ConfigurationProperties(prefix = "pay.alipay.app1")
public class AliPaySpareConfig extends AlipayConfig {

    private String name = "alipay-spare1";

    private String appId;
    //MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCXH4ho5I+CAOZROpsZVpSq3iz3tb/NVDz4msy0pGJyoMAN6FpfY0TO8f4nft6kLPshLaAzu/tTv14hm29BJ7fNoOULtTCf5iaOPGyHptsmHj7zzJJFpqEFkd3TE9Z+pxGmf9fsw6LWGRnZdpGKXCqzKV7YVuACfZVt9NXxidy4sKahvgr9A6OZBi1fuu2iL4xyPqY/87d6ixU+/BwM+oTDK6ChpNkg7o5NO2Te5syYF3LJtOqL5LXzbuzP6wLw+FOzphoAyHiLkgcnemw8eZoImcsdKJawFO/qjft432rnBnW1IWFuqsLq6JEJsgN2Wch38fkqRf0Y1/IdeEXNUvaHAgMBAAECggEBAJKlus1u3gOds+InKNLRvbqBlslZySILGI92SCcTTaVGcJgOXYQq5F6dXbAd4RcXvypXCBqr1BtUnJeoKbHkROx5sUpHLUQ9JjToVbjdJdQ7jYMvhNGp/J9XCRcHLSICJZKYhIPw5Fc2TGtGL70/6v+oqaztwLsp+pOU/vdAfLuK0kkaYJTNKQDRbdoGoSQ/vDir85PV+nliinyAEoUqBHvoDoN/Xs9jo9JGagZQKkpjJzv3DOoQZIzUyLF1imiEKKDuKa+WVRU3+YzE1Wd2CYq3iCJNvs8nf48VeHvx1q7JuU4wK82M75BDF0jyNIy7UrXs0lVUIv/mlgjumGxciqECgYEAzbS6doad0zGdk21H53NU4R9+z+eKSzacaU2J0p3t68ouNhb3uM6ijfsEjiSc0HhyiwfIVDfpAnXefsOKLahY3tuz7WkZu9xZeYAWCOKQlglVFOtN0VTmuuaVe32d8wZ7QDt+Jmtz217GgNtJJGuwS9rpnWZTRgrCwBpPmdj9nfMCgYEAvBJueNG8PYyLmHfI+mKRsde/i+RoySBHeQR8AAV8FCR2UEw+HLxdWIzpa77WQoq6+WBSqwfAtdYeKp8q/WJ0p1V6sIGXTnRVPD2w/a8rsD/dJotrogaKfaO+PvUUV0TOnCfZ99RfL7Gr4QT5YKHGxySUAcfiEIw7lwk15tvCJh0CgYEAhrDv5uv+K2sxYncLveEmksGspzVUuCrp/4ll1SLTxrB70a74RWoHxi+2q9wNUfOMDLzrzzlMuO+04AvpTjwM9N+m0K0gzIFblNLpmqe/RH6X1zq7mXWeHoMdHd8CrT5xNX2+/Ckfk2RbVcRAADkDFqggj4+QtywUmPShantKlUECgYB6WB8nV4D2JRyWda33O/H9WBVSIqcL14THM+Saevbpf4K73600MlEjDp+2KLHnHapeGYwNmICDiaOcJGjp5oduZ4vlkJfmQIVGJ/egP7jS8eiib2X4Q/sJmmBjQjkWQDuLl90SfEPjmdfvDLZRZ0wRNjlWIzpre140dZhr8p+M/QKBgFGaOb2croSy1rEJcx/kP+feyLpQadh3rD8+TsLs+kYrvF50V4JZFA3uFkB9WkzfkemuOVGVw6hL4yf2IrWRFufarzuSO2lChFBex3jXIvgiAh4YFqYqRXcbVm2FeHAufuztJA7MNPZbcQHuYhcUaaRjSvCrAd9awoH1CLSW+eXE
    private String privateKey;
    private String alipayPublicKey;
    private String privateKeyPath;
    private String payNotifyUrl;
    private String refundNotifyUrl;

    public String getPrivateKey(){
        if(StringUtils.isEmpty(privateKey)) {
            String privateKey = "";
            InputStream inputStream = getClass().getClassLoader().getResourceAsStream(privateKeyPath);
            if (null == inputStream) {
                try {
                    inputStream = new FileInputStream(new File(privateKeyPath));
                    StringBuilder sb = new StringBuilder();
                    String line;

                    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                    while ((line = br.readLine()) != null) {
                        sb.append(line);
                    }
                    privateKey = sb.toString();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return privateKey;
        }
        return privateKey;
    }

}
