Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上传图片的uri错误了 #209

Open
sevencm opened this issue Mar 28, 2024 · 0 comments
Open

上传图片的uri错误了 #209

sevencm opened this issue Mar 28, 2024 · 0 comments

Comments

@sevencm
Copy link

sevencm commented Mar 28, 2024

接口文档的地址为 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant