package com.tzy.framework.pay.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.*;

/**
 * 全民h5 支付
 */
@Data
@Component
@ConfigurationProperties(prefix = "pay.qm.h5")
public class QmH5PayConfig {

    private String name = "qm-h5";
    //appid
    private String appid;
    //appkey
    private String appkey;
    //商户号
    private String mid;
    private String mid_ali;
    private String mid_uac;
    private String mid_wxh5;
    //终端号
    private String 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;

    private String url = "https://test-api-open.chinaums.com/v1/netpay/trade/h5-pay?";


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


}
