-
-
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
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
🤖 Augment PR SummarySummary: 本 PR 为微信支付 V3 通用媒体接口新增视频上传能力,与既有图片上传接口保持一致的调用方式。
/v3/merchant/media/video_upload 端点以 multipart 方式提交。
🤖 Was this summary useful? React with 👍 or 👎 |
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.
| @Override | ||
| public VideoUploadResult videoUploadV3(InputStream inputStream, String fileName) throws WxPayException, IOException { | ||
| String url = String.format("%s/v3/merchant/media/video_upload", this.payService.getPayBaseUrl()); | ||
| try(ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
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.
|
|
||
| log.info("视频上传成功,mediaId:[{}]", mediaId); | ||
|
|
||
| VideoUploadResult videoUploadResult2 = merchantMediaService.videoUploadV3(file); |
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.
| * @return VideoUploadResult 微信返回的媒体文件标识Id。示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 | ||
| * @throws WxPayException the wx pay exception | ||
| */ | ||
| VideoUploadResult videoUploadV3(File videoFile) throws WxPayException, IOException; |
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.
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.
Pull request overview
本PR实现了微信支付V3视频上传API(/v3/merchant/media/video_upload),与现有的图片上传功能保持一致的设计模式和代码结构。
变更内容:
- 新增VideoUploadResult bean类用于封装视频上传返回结果
- 在MerchantMediaService接口中添加两个视频上传方法(File版本和InputStream版本)
- 在MerchantMediaServiceImpl中实现视频上传逻辑,使用SHA256计算文件摘要
- 重构WechatPayUploadHttpPost,提取私有的withMedia方法消除代码重复,并添加withVideo方法
- 添加视频上传测试用例
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| VideoUploadResult.java | 新增视频上传返回结果bean,结构与ImageUploadResult保持一致 |
| MerchantMediaService.java | 添加videoUploadV3的两个重载方法声明,附带完整的Javadoc文档 |
| MerchantMediaServiceImpl.java | 实现视频上传逻辑,代码结构与图片上传方法高度一致 |
| WechatPayUploadHttpPost.java | 重构代码,提取withMedia私有方法,添加withVideo公共方法,泛化错误消息 |
| MerchantMediaServiceImplTest.java | 添加视频上传测试方法,测试File参数版本的上传功能 |
| @Override | ||
| public VideoUploadResult videoUploadV3(InputStream inputStream, String fileName) throws WxPayException, IOException { | ||
| String url = String.format("%s/v3/merchant/media/video_upload", this.payService.getPayBaseUrl()); | ||
| try(ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
Copilot
AI
Jan 26, 2026
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.
在try(ByteArrayOutputStream语句中try和(之间缺少空格。应为try (而非try(。这与项目中其他文件的代码风格不一致(参见ComplaintServiceImpl.java:142和MarketingMediaServiceImpl.java:43)。虽然这个问题也存在于同文件第44行的imageUploadV3方法中,但新代码应遵循项目统一的代码风格。
| try(ByteArrayOutputStream bos = new ByteArrayOutputStream()) { | |
| try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| @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); | ||
| String mediaId2 = videoUploadResult2.getMediaId(); | ||
|
|
||
| log.info("视频上传成功2,mediaId2:[{}]", mediaId2); | ||
|
|
||
| } |
Copilot
AI
Jan 26, 2026
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.
测试方法只测试了File参数版本的videoUploadV3方法,缺少对videoUploadV3(InputStream, String)重载方法的测试覆盖。由于该重载方法使用了不同的实现逻辑(通过ByteArrayOutputStream缓冲),建议添加测试用例以确保两种上传方式都能正常工作。
| /** | ||
| * 视频文件上传返回结果对象 | ||
| * | ||
| * @author Binary Wang |
Copilot
AI
Jan 26, 2026
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.
VideoUploadResult的@author标签为"Binary Wang",而同目录下功能相似的ImageUploadResult使用"zhouyongshen"作为作者。为保持一致性,建议VideoUploadResult也使用相同的作者标签,除非"Binary Wang"确实是该文件的实际作者。
实现微信支付V3视频上传API(
/v3/merchant/media/video_upload),与现有图片上传接口保持一致的设计模式。变更内容
media_id字段videoUploadV3(File)和videoUploadV3(InputStream, String)方法withVideo()方法,重构提取withMedia()私有方法消除代码重复使用示例
API参考
/v3/merchant/media/video_uploadOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.