接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter4_3.shtml
在下载电子回单API 中,接口状态 status code = 200,但是业务请求400是什么原因呢?
用wechatpay-apiv3同样会报错
然后我重新写了一套
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import java.io.InputStream; import java.security.PrivateKey; import java.security.Signature; import java.util.Base64; import java.util.UUID; /** * 微信电子回单下载 * @Author xiaoqiang * @Date 2022/02/12 17:50 */ public class DownLoadBillUtil { //商户号 private String merchantId; //商户序列号 private String certificateSerialNo; //商户私钥 private PrivateKey privateKey; public DownLoadBillUtil(String merchantId, String certificateSerialNo, PrivateKey privateKey){ this.merchantId = merchantId; this.certificateSerialNo = certificateSerialNo; this.privateKey = privateKey; } public InputStream downloadBill(String downloadUrl) throws Exception{ String timestamp = String.valueOf(System.currentTimeMillis()); String nonceStr = UUID.randomUUID().toString().replace("-", "");; HttpGet httpGet = new HttpGet(downloadUrl); String path = httpGet.getURI().getPath(); String canonicalUrl = httpGet.getURI().getQuery(); if (canonicalUrl != null) { path += "?" + canonicalUrl; } String billSign = this.createBillSign(nonceStr, timestamp, path); StringBuilder sb = new StringBuilder("WECHATPAY2-SHA256-RSA2048 mchid=").append("\"").append(this.merchantId).append("\","); sb.append("serial_no=").append("\"").append(this.certificateSerialNo).append("\","); sb.append("nonce_str=").append("\"").append(nonceStr).append("\","); sb.append("timestamp=").append("\"").append(timestamp).append("\","); sb.append("signature=").append("\"").append(billSign).append("\""); String auth = sb.toString(); HttpResponse execute = HttpRequest.get(downloadUrl).auth(auth).execute(); return execute.bodyStream(); } public String createBillSign(String nonceStr, String timestamp, String download) throws Exception{ String plain_text = "GET" + "\n" + download + "\n" + timestamp + "\n" + nonceStr + "\n"; Signature sign = Signature.getInstance("SHA256withRSA"); sign.initSign(this.privateKey); sign.update(plain_text.getBytes("utf-8")); return Base64.getEncoder().encodeToString(sign.sign()); } }