收藏
回答

java 上传小程序备案媒体材料 第三方平台API调用 invalid media type?

public String uploadMaterialIcp(MultipartFile file) throws Exception {
    String accessToken = wechatService.getAuthorizerAccessToken(miniAppId);
    HttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/icp/upload_icp_media?access_token=" + accessToken);
    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    entityBuilder.addTextBody("type", "image");
    entityBuilder.addTextBody("certificate_type", "2");
    entityBuilder.addTextBody("icp_order_field", "icp_subject.principal_info.certificate_photo_front");
    entityBuilder.addBinaryBody("media", file.getBytes(), ContentType.create("image/jpeg"), file.getName());
    HttpEntity multipartEntity = entityBuilder.build();
    httpPost.setEntity(multipartEntity);
    httpPost.setHeader("Content-type",ContentType.MULTIPART_FORM_DATA.getMimeType());
    // 执行请求
    HttpResponse response = httpClient.execute(httpPost);
    HttpEntity entity = response.getEntity();
    JSONObject result = JSONUtil.parseObj(EntityUtils.toString(entity));
    log.info("请求小程序备案【上传材料】返回数据:{}", result);
    if (result.getInt("errcode") != 0) {
        throw exception(new ErrorCode(101, result.getStr("errmsg")));
    }
    return result.getStr("mediaid");
}

{"errcode":40004,"errmsg":"invalid media type rid: 670e1bc6-5a2e7c45-3882b571"}


有没有调用成功的java ?

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容