参考:Java 微信支付 继承 WXPayConfig 类 getWXPayDomain() 方法 重写 遗漏
    Java开发微信支付使用wxpay-sdk中遇到的坑(一)

    MyWxPayConfig配置类代码,应该是extends继承,而不是implement实现

    1. package com.tj.qywx.config;
    2. import com.github.wxpay.sdk.IWXPayDomain;
    3. import com.github.wxpay.sdk.WXPayConfig;
    4. import com.tj.base.service.BaseNumvarService;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.beans.factory.annotation.Value;
    7. import java.io.*;
    8. public class MyWxPayConfig extends WXPayConfig {
    9. @Autowired
    10. private BaseNumvarService baseNumvarService;
    11. private byte[] certData;
    12. @Value("${cert.path}") //读取yaml文件里设置的地址信息
    13. private String path;
    14. public MyWxPayConfig() throws Exception {
    15. String certPath = this.path;
    16. File file = new File(certPath);
    17. InputStream certStream = new FileInputStream(file);
    18. this.certData = new byte[(int) file.length()];
    19. certStream.read(this.certData);
    20. certStream.close();
    21. }
    22. @Override
    23. public String getAppID() {
    24. return baseNumvarService.getCorpid();
    25. }
    26. @Override
    27. public String getMchID() {
    28. return baseNumvarService.getMchId();
    29. }
    30. @Override
    31. public String getKey() {
    32. return baseNumvarService.getAPIv2();
    33. }
    34. @Override
    35. public InputStream getCertStream() {
    36. ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
    37. return certBis;
    38. }
    39. @Override
    40. public IWXPayDomain getWXPayDomain() {
    41. return null;
    42. }
    43. }