上传图片的uri错误了
Opened this issue · 0 comments
sevencm commented
接口文档的地址为 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);
}
}
上面的代码居然也能执行,而且还返回了数据。