package com.tzy.framework.pay.config;

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

import java.io.*;

@Data
@Component
@ConfigurationProperties(prefix = "pay.hm.app")
public class HmPayConfig extends AlipayConfig {

    private String name = "hm";

    private String app_id;
    private String wxMchID;
    private String privateKey;
    private String publicKey;
    private String hmPublicKey;
    private String privateKeyPath;
    private String format;
    private String version;
    private String storeId;
    private String payNotifyUrl;
    private String returnUrl;
    private String ghStaticUrl;

    public String getPrivateKey(){
        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;
    }


}
