微信官方给的sdk有点问题,通过百度找到了maven依赖,这个比较靠谱
添加依赖
com.github.wxpay
wxpay-sdk
0.0.3
com.google.code.gson
gson
2.8.2
重写config
public class MyConfig implements WXPayConfig {
private byte[] certData;
public MyConfig() throws Exception {
String certPath = "F:\\work\\WxPayAPI_JAVA\\java_sdk_v3.0.9\\src\\main\\resource\\apiclient_cert.p12";
File file = new File(certPath);
InputStream certStream = new FileInputStream(file);
this.certData = new byte[(int) file.length()];
certStream.read(this.certData);
certStream.close();
}
public String getAppID() {
return "wx888888888";
}
public String getMchID() {
return "1234567897";
}
public String getKey() {
return "00000000000000000000000";
}
public InputStream getCertStream() {
ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
return certBis;
}
public int getHttpConnectTimeoutMs() {
return 8000;
}
public int getHttpReadTimeoutMs() {
return 10000;
}
}
创建测试文件 WXPayExample.java
MyConfig config = new MyConfig();
WXPay wxpay = new WXPay(config, HMACSHA256);
Map data = new HashMap();
data.put("bill_date", "20181117");
data.put("bill_type", "ALL");
对账单数据
请求下载对账单的api方法
Map resp = wxpay.downloadBill(data);
String s = resp.get("data");
对于数据返回的 比较麻烦,所以用bean对其进行处理,方便装换成我们需要的数据类型
接收的数据bean
public class Pay