视频上传问题
lzb-libra opened this issue · 2 comments
lzb-libra commented
我使用wechatpay-apache-httpclient提供的功能进行视频上传,发现由问题,但是上传图片就没有问题。我看文档中上传图片和上传视频是一样的代码的,还是我看漏了什么吗?
private static CloseableHttpClient getHttpClient(String mchId) throws NotFoundException {
Verifier verifier = WXEnvInit.certificatesManager.getVerifier(mchId);
WXPayConfigInfo merchantInfo = WXEnvInit.getMchInfo(mchId);
return WechatPayHttpClientBuilder.create()
.withMerchant(merchantInfo.getMchId(), merchantInfo.getCertSerialNo(), merchantInfo.getPrivateKey())
.withValidator(new WechatPay2Validator(verifier))
.build();
}
public static ResultDTO uploadFile(String merchantId, String url, File file) throws IOException, URISyntaxException, NotFoundException {
String uuid = UUID.randomUUID().toString().replace("-", "");
System.out.printf("[%s][request url] %s%n", uuid, url);
try (FileInputStream fis = new FileInputStream(file)) {
String fileSha256 = DigestUtil.sha256Hex(fis);
try(InputStream is = Files.newInputStream(file.toPath())) {
HttpPost post = new WechatPayUploadHttpPost.Builder(new URI(url))
.withFile(file.getName(), String.format("{\"filename\":\"%s\",\"sha256\":\"%s\"}", file.getName(), fileSha256), is)
.build();
try (CloseableHttpResponse response = getHttpClient(merchantId).execute(post)){
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if(entity == null) return new ResultDTO().failure("响应解析失败");
String body = EntityUtils.toString(entity);
System.out.printf("[%s][response] %s%n", uuid, body);
if(status == 200) return new ResultDTO().success(body);
if(body.contains("<html>") && body.contains("<header>") && body.contains("<title>")) return new ResultDTO().setStatusCode(status).setMessage(body);
ErrorDTO error = BasicConst.jsonMapper.readValue(body, ErrorDTO.class);
return new ResultDTO().setStatusCode(status).setMessage(error.getMessage()).setErrorCode(error.getCode());
}
}
}
}
xy-peng commented
- 检查下你的网络是不是于限制?
- 不是发送错了地址?
- 视频文件超大了?
lzb-libra commented
确实是我的文件超大了,12M,我换了一个就可以了,是我没有仔细看文档。不过这个5M是不是太小了呀,现在手机随随便便拍出来都好几10M的视频