public UploadTempMediaResult uploadMedia(String accessToken, String type, File file) { log.info("把媒体文件上传到微信服务器[OkHttpClient] 请求参数 type[{}] filename[{}]", type, file.getName()); try { OkHttpClient client = new OkHttpClient().newBuilder() .build(); // MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("media", file.getName(), RequestBody.create(MediaType.parse("application/octet-stream"), file ) ) .build(); String url = String.format("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s", accessToken, type); Request request = new Request.Builder() .url(url) .method("POST", body) .build(); Response response = client.newCall(request).execute(); ResponseBody responseBody = response.body(); if (responseBody == null) { return null; } UploadTempMediaResult uploadTempMediaResult = JSONObject.parseObject(responseBody.string(), UploadTempMediaResult.class); log.info("把媒体文件上传到微信服务器[OkHttpClient] 返回结果 {}", JSONObject.toJSONString(uploadTempMediaResult)); return uploadTempMediaResult; } catch (Exception e) { log.info("uploadMedia e = ", e); } return null; }
把媒体文件上传到微信服务器,提示:media data missing?接口如下:[图片]接口辅助类如下:[图片]handler:[图片]impl:[图片] 日志信息如下: 把媒体文件上传到微信服务器 请求参数 type[image] filename[vccb4250ddffa0d24f.png] feign interceptor requestTemplate: POST /media/upload?access_token=...&type=image HTTP/1.1 Content-Length: 277 Content-Type: multipart/form-data; charset=UTF-8; boundary=180e0d46c02 Binary data 把媒体文件上传到微信服务器 返回结果 {"errorCode":41005,"errorMsg":"media data missing hint: [oOxFFa04598236] rid: 62876163-0fe20ed5-3a41e945"}
2022-05-21同上 {"errorCode":41005,"errorMsg":"media data missing hint: [g0YnNa0345e151] rid: 6285e221-2b984cbe-589d2619"}
新增临时素材抛 media data missing hint“媒体数据丢失提示”?"errcode":41005,"errmsg":"media data missing hint: [xZ8LfA08540032] rid: 626a6cde-7c431276-5c9ed232"
2022-05-19