wechatpay-apiv3/wechatpay-apache-httpclient

上传图片的uri错误了

Opened this issue · 0 comments

接口文档的地址为 https://api.mch.weixin.qq.com/v3/merchant-service/images/upload

String filePath = "/your/home/hellokitty.png";
// 应该为 https://api.mch.weixin.qq.com/v3/merchant-service/images/upload 
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)
// 如需直接设置媒体文件元信息,可使用withFile代替withImage
        .withImage(file.getName(), sha256, ins2)
        .build();
    CloseableHttpResponse response1 = httpClient.execute(request);
  }
}

上面的代码居然也能执行,而且还返回了数据。

另外回复用户的图片格式官网的示例也错了,调试了一整天,都是无效图。
image
坑爹的腾讯API文档;下面的才是正确的格式
image