初始化微信支付配置
@Componentpublic class WxConfig {
@Autowired
private YmlParament ymlParament;
/**
* 初始化微信支付配置
* @throws Exception
*/
@Bean(autowire = Autowire.BY_NAME,value = WxParament.H5_WX_PAY)
public WXPay setH5WXPay() throws Exception {
return new WXPay(new WxPayConfig(
ymlParament.getH_cert_path(),
ymlParament.getH_app_id(),
ymlParament.getMch_id(),
ymlParament.getH_key()));
}
}
WxPayConfig
public class WxPayConfig implements WXPayConfig {private byte[] certData;
private String appID;
private String mchID;
private String key;
public WxPayConfig(String certPath, String appID,String mchID,String key) throws Exception {
File file = new File(certPath);
InputStream certStream = new FileInputStream(file);
this.certData = new byte[(int) file.length()];
certStream.read(this.certData);
certStream.close();
this.appID = appID;
this.mchID = mchID;
this.key = key;
}
}