-
-
Notifications
You must be signed in to change notification settings - Fork 9k
添加微信支付视频上传接口 #3871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
添加微信支付视频上传接口 #3871
Changes from all commits
b90de5e
b733aa4
16561c2
32e7de5
0e23226
867293e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.github.binarywang.wxpay.bean.media; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||
|
|
||
| /** | ||
| * 视频文件上传返回结果对象 | ||
| * | ||
| * @author copilot | ||
| */ | ||
| @NoArgsConstructor | ||
| @Data | ||
| public class VideoUploadResult { | ||
|
|
||
| public static VideoUploadResult fromJson(String json) { | ||
| return WxGsonBuilder.create().fromJson(json, VideoUploadResult.class); | ||
| } | ||
|
|
||
| /** | ||
| * 媒体文件标识 Id | ||
| * <p> | ||
| * 微信返回的媒体文件标识Id。 | ||
| * 示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 | ||
| */ | ||
| @SerializedName("media_id") | ||
| private String mediaId; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package com.github.binarywang.wxpay.service.impl; | ||
|
|
||
| import com.github.binarywang.wxpay.bean.media.ImageUploadResult; | ||
| import com.github.binarywang.wxpay.bean.media.VideoUploadResult; | ||
| import com.github.binarywang.wxpay.exception.WxPayException; | ||
| import com.github.binarywang.wxpay.service.MerchantMediaService; | ||
| import com.github.binarywang.wxpay.service.WxPayService; | ||
|
|
@@ -51,4 +52,45 @@ public void testImageUploadV3() throws WxPayException, IOException { | |
| log.info("mediaId2:[{}]",mediaId2); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testVideoUploadV3() throws WxPayException, IOException { | ||
|
|
||
| MerchantMediaService merchantMediaService = new MerchantMediaServiceImpl(wxPayService); | ||
|
|
||
| String filePath = "你的视频文件的路径地址"; | ||
| // String filePath = "WxJava/test-video.mp4"; | ||
|
|
||
| File file = new File(filePath); | ||
|
|
||
| VideoUploadResult videoUploadResult = merchantMediaService.videoUploadV3(file); | ||
| String mediaId = videoUploadResult.getMediaId(); | ||
|
|
||
| log.info("视频上传成功,mediaId:[{}]", mediaId); | ||
|
|
||
| VideoUploadResult videoUploadResult2 = merchantMediaService.videoUploadV3(file); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| String mediaId2 = videoUploadResult2.getMediaId(); | ||
|
|
||
| log.info("视频上传成功2,mediaId2:[{}]", mediaId2); | ||
|
|
||
| } | ||
|
Comment on lines
+56
to
+76
|
||
|
|
||
| @Test | ||
| public void testVideoUploadV3WithInputStream() throws WxPayException, IOException { | ||
|
|
||
| MerchantMediaService merchantMediaService = new MerchantMediaServiceImpl(wxPayService); | ||
|
|
||
| String filePath = "你的视频文件的路径地址"; | ||
| // String filePath = "WxJava/test-video.mp4"; | ||
|
|
||
| File file = new File(filePath); | ||
|
|
||
| try (java.io.FileInputStream inputStream = new java.io.FileInputStream(file)) { | ||
| VideoUploadResult videoUploadResult = merchantMediaService.videoUploadV3(inputStream, file.getName()); | ||
| String mediaId = videoUploadResult.getMediaId(); | ||
|
|
||
| log.info("通过InputStream上传视频成功,mediaId:[{}]", mediaId); | ||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该方法签名声明会抛出
IOException,但 Javadoc 的@throws仅写了WxPayException,文档与代码不一致。Other Locations
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantMediaService.java:71🤖 Was this useful? React with 👍 or 👎