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.qm2.app")
public class QmPay2Config extends AlipayConfig {

    private String name = "qm2";
    //appid
    private String appid;
    //appkey
    private String appkey;
    //商户号
    private String mid;
    //终端号
    private String tid;
    //子商户号
    private String sub_mid;
    //子终端号
    private String sub_tid;
    //来源编号
    private String msgSrcId;
    //机构商户号
    private String instMid;
    //私钥
    private String privateKey;

    private String privateKeyPath;
    //支付回调地址
    private String payNotifyUrl;
    //退款回调地址
    private String refundNotifyUrl;
    //订单展示页面
    private String showUrl;
    //支付标记
    private String payFlag;
    //退款标记
    private String refundFlag;
    //微信子商户appid
    private String subAppId;


    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;
    }

}
