收藏
回答

调用微信https://api.mch.weixin.qq.com/v3/merchant/medi

调用微信https://api.mch.weixin.qq.com/v3/merchant/media/upload,报System.IO.IOException错误

回答关注问题邀请回答
收藏

2 个回答

  • 北望沣渭
    北望沣渭
    2020-09-18

    建议用官方maven包,源码地址:  https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient

    使用WechatPayUploadHttpPost构造一个上传的HttpPost,需设置待上传文件的文件名,SHA256摘要,文件的输入流。

    通过WechatPayHttpClientBuilder得到的HttpClient发送请求。示例请参考下列代码。

    String filePath = "/your/home/hellokitty.png";
    URI uri = new URI("https://api.mch.weixin.qq.com/v3/merchant/media/upload");
    File file = new File(filePath);
    
    try (FileInputStream ins1 = new FileInputStream(file)) { 
      String sha256 = DigestUtils.sha256Hex(ins1);
      try (InputStream ins2 = new FileInputStream(file)) {
        HttpPost request = new WechatPayUploadHttpPost.Builder(uri)
            .withImage(file.getName(), sha256, ins2)
            .build();
        CloseableHttpResponse response1 = httpClient.execute(request);
      }
    }
    

    AutoUpdateVerifierTest.uploadImageTest 是一个更完整的示例。

    2020-09-18
    有用 1
    回复
  • SMVC
    SMVC
    2021-08-06

    大佬,这个参数怎么设置的

    2021-08-06
    有用
    回复
登录 后发表内容
问题标签