ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2022-03-04 11:00:18  阅读:302  来源: 互联网

标签:status 200 code String timestamp sign sb import append


接口地址: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());
    }
}

 

标签:status,200,code,String,timestamp,sign,sb,import,append
来源: https://www.cnblogs.com/SparkMore/p/15895427.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有