【微信支付】微信JSAPI支付流程 (4)

初始化微信支付配置

@Component
public 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;
 }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgwgyy.html