【微信支付-批量转账到零钱】下载电子回单API 签名成功,status code = 200,但是没有文件流?

接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter4_3.shtml

在下载电子回单API 中,接口状态 status code = 200,但是业务请求400是什么原因呢?

【微信支付-批量转账到零钱】下载电子回单API 签名成功,status code = 200,但是没有文件流?

 

 

 用wechatpay-apiv3同样会报错

【微信支付-批量转账到零钱】下载电子回单API 签名成功,status code = 200,但是没有文件流?

 

 

 然后我重新写了一套

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());
    }
}

 

上一篇:cocos2dx 之 android java 与 c++ 互相调用 代码(以百度定位为例子)


下一篇:我终于搞懂了时间……(C# 中时间类型(DateTime) 时间戳(Unix时间戳)互转)