wechatpay-apiv3 / wechatpay-apache-httpclient

微信支付 APIv3 Apache HttpClient装饰器(decorator)
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml
Apache License 2.0
665 stars 249 forks source link

视频上传问题 #195

Closed lzb-libra closed 11 months ago

lzb-libra commented 11 months ago

我使用wechatpay-apache-httpclient提供的功能进行视频上传,发现由问题,但是上传图片就没有问题。我看文档中上传图片和上传视频是一样的代码的,还是我看漏了什么吗? QQ截图20230817151219

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 11 months ago
  1. 检查下你的网络是不是于限制?
  2. 不是发送错了地址?
  3. 视频文件超大了?
lzb-libra commented 11 months ago

确实是我的文件超大了,12M,我换了一个就可以了,是我没有仔细看文档。不过这个5M是不是太小了呀,现在手机随随便便拍出来都好几10M的视频