本文是基于微信支付V2版本的工具类,如果使用V3的版本请参考官网:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/api.shtml
因为图方便,所以引入了两个公共的工具包 来处理https 请求 以及 加密,里面也封装了快速替换下面两个依赖的方式
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay</artifactId>
<version>1.1.6</version>
</dependency>
工具类
package com.example.wxBill;
import cn.hutool.crypto.digest.MD5;
import com.jpay.ext.kit.PaymentKit;
import com.jpay.ext.kit.StrKit;
import com.jpay.util.HttpUtils;
import org.springframework.util.StringUtils;
import java.util.*;
public class WXBillDownUtils {
public final static String WX_DOWNLOAD_BILL_URL = "https://api.mch.weixin.qq.com/pay/downloadbill";
/**
* 需要替换的部分
*/
public final static String appid = "xxxx";
public final static String mch_id = "xxxx";
public final static String appKey = "xxxx";
public final static String default_characterEncoding = "UTF-8";
/**
* 入口测试
* @param args
*/
public static void main(String[] args) {
catchTradeBill("20201103");
}
public static void catchTradeBill(String yyyyMMdd) {
SortedMap<String, String> parameters = new TreeMap<String, String>();//用来放置各个所需要的参数,自己对应寻找填写。
parameters.put("appid", appid);
//下载对账单的日期,格式:20140603
parameters.put("bill_date",