-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
添加微信支付视频上传接口 #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参数版本的上传功能 |
...ava-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MerchantMediaServiceImpl.java
Outdated
Show resolved
Hide resolved
| @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缓冲),建议添加测试用例以确保两种上传方式都能正常工作。
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.
已添加testVideoUploadV3WithInputStream测试方法,覆盖InputStream方式的视频上传。提交:867293e
| /** | ||
| * 视频文件上传返回结果对象 | ||
| * | ||
| * @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"确实是该文件的实际作者。
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.
@copilot 新增代码作者应该为copilot,就是你本人,不要写成别人
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.
已修改作者标签为copilot。提交:867293e
…ice/impl/MerchantMediaServiceImpl.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
所有评审意见都已处理完成:
当前代码状态良好,所有修改都已正确应用。 |
微信支付视频上传接口实现
实现总结
本PR成功实现了微信支付视频上传接口,遵循了项目现有的代码风格和实现模式:
新增文件
修改文件
API说明
测试覆盖
使用示例
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.