-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
496 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package mini | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-pay/bm" | ||
) | ||
|
||
// MediaAssetListMedia 媒资管理-获取媒资列表 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于获取已上传到平台的媒资列表。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_2-1-%E8%8E%B7%E5%8F%96%E5%AA%92%E8%B5%84%E5%88%97%E8%A1%A8 | ||
func (s *SDK) MediaAssetListMedia(c context.Context, body bm.BodyMap) (rsp *MediaAssetListMediaRsp, err error) { | ||
path := "/wxa/sec/vod/listmedia?access_token=" + s.accessToken | ||
rsp = &MediaAssetListMediaRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetGetMedia 媒资管理-获取媒资详细信息 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于获取已上传到平台的指定媒资信息,用于开发者后台管理使用。用于给用户客户端播放的链接应该使用getmedialink接口获取。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_2-2-%E8%8E%B7%E5%8F%96%E5%AA%92%E8%B5%84%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF | ||
func (s *SDK) MediaAssetGetMedia(c context.Context, body bm.BodyMap) (rsp *MediaAssetGetMediaRsp, err error) { | ||
path := "/wxa/sec/vod/getmedia?access_token=" + s.accessToken | ||
rsp = &MediaAssetGetMediaRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetGetMediaLink 媒资管理-获取媒资播放链接 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于获取视频临时播放链接,用于给用户的播放使用。只有审核通过的视频才能通过该接口获取播放链接。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_2-3-%E8%8E%B7%E5%8F%96%E5%AA%92%E8%B5%84%E6%92%AD%E6%94%BE%E9%93%BE%E6%8E%A5 | ||
func (s *SDK) MediaAssetGetMediaLink(c context.Context, body bm.BodyMap) (rsp *MediaAssetGetMediaLinkRsp, err error) { | ||
path := "/wxa/sec/vod/getmedialink?access_token=" + s.accessToken | ||
rsp = &MediaAssetGetMediaLinkRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetDeleteMedia 媒资管理-删除媒资 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于删除指定媒资。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_2-4-%E5%88%A0%E9%99%A4%E5%AA%92%E8%B5%84 | ||
func (s *SDK) MediaAssetDeleteMedia(c context.Context, body bm.BodyMap) (rsp *MediaAssetDeleteMediaRsp, err error) { | ||
path := "/wxa/sec/vod/deletemedia?access_token=" + s.accessToken | ||
rsp = &MediaAssetDeleteMediaRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package mini | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-pay/bm" | ||
"github.com/go-pay/xlog" | ||
) | ||
|
||
func TestMediaAssetListMedia(t *testing.T) { | ||
body := make(bm.BodyMap) | ||
body.Set("drama_id", 20001). | ||
Set("limit", 20) | ||
|
||
rsp, err := miniSDK.MediaAssetListMedia(ctx, body) | ||
if err != nil { | ||
xlog.Error(err) | ||
return | ||
} | ||
xlog.Debugf("rsp:%+v", rsp) | ||
} | ||
|
||
func TestMediaAssetGetMedia(t *testing.T) { | ||
body := make(bm.BodyMap) | ||
body.Set("media_id", 20001) | ||
|
||
rsp, err := miniSDK.MediaAssetGetMedia(ctx, body) | ||
if err != nil { | ||
xlog.Error(err) | ||
return | ||
} | ||
xlog.Debugf("rsp:%+v", rsp) | ||
} | ||
|
||
func TestMediaAssetGetMediaLink(t *testing.T) { | ||
body := make(bm.BodyMap) | ||
body.Set("media_id", 28918028). | ||
Set("t", 1689990878) | ||
|
||
rsp, err := miniSDK.MediaAssetGetMediaLink(ctx, body) | ||
if err != nil { | ||
xlog.Error(err) | ||
return | ||
} | ||
xlog.Debugf("rsp:%+v", rsp) | ||
} | ||
|
||
func TestMediaAssetDeleteMedia(t *testing.T) { | ||
body := make(bm.BodyMap) | ||
body.Set("media_id", 28918028) | ||
|
||
rsp, err := miniSDK.MediaAssetDeleteMedia(ctx, body) | ||
if err != nil { | ||
xlog.Error(err) | ||
return | ||
} | ||
xlog.Debugf("rsp:%+v", rsp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package mini | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-pay/bm" | ||
) | ||
|
||
// MediaAssetSingleFileUpload 媒资上传-单个文件上传 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:上传媒体(和封面)文件,上传小文件(小于10MB)时使用。上传大文件请使用分片上传接口。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-1-%E5%8D%95%E4%B8%AA%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0 | ||
func (s *SDK) MediaAssetSingleFileUpload(c context.Context, body bm.BodyMap) (rsp *MediaAssetSingleFileUploadRsp, err error) { | ||
path := "/wxa/sec/vod/singlefileupload?access_token=" + s.accessToken | ||
rsp = &MediaAssetSingleFileUploadRsp{} | ||
if _, err = s.DoRequestPostFile(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetPullUpload 媒资上传-拉取上传 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于将一个网络上的视频拉取上传到平台。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-2-%E6%8B%89%E5%8F%96%E4%B8%8A%E4%BC%A0 | ||
func (s *SDK) MediaAssetPullUpload(c context.Context, body bm.BodyMap) (rsp *MediaAssetPullUploadRsp, err error) { | ||
path := "/wxa/sec/vod/pullupload?access_token=" + s.accessToken | ||
rsp = &MediaAssetPullUploadRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetGetTask 媒资上传-查询任务 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于查询拉取上传的任务状态。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-3-%E6%9F%A5%E8%AF%A2%E4%BB%BB%E5%8A%A1 | ||
func (s *SDK) MediaAssetGetTask(c context.Context, body bm.BodyMap) (rsp *MediaAssetGetTaskRsp, err error) { | ||
path := "/wxa/sec/vod/gettask?access_token=" + s.accessToken | ||
rsp = &MediaAssetGetTaskRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetApplyUpload 媒资上传-申请分片上传 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:上传大文件时需使用分片上传方式,分为 3 个步骤: | ||
// 1、申请分片上传,确定文件名、格式类型,返回 upload_id,唯一标识本次分片上传。 | ||
// 2、上传分片,多次调用上传文件分片,需要携带 part_number 和 upload_id,其中 part_number 为分片的编号,支持乱序上传。当传入 part_number 和 upload_id 都相同的时候,后发起上传请求的分片将覆盖之前的分片。 | ||
// 3、确认分片上传,当上传完所有分片后,需要完成整个文件的合并。请求体中需要给出每一个分片的 part_number 和 etag,用来校验分片的准确性,最后返回文件的 media_id。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-4-%E7%94%B3%E8%AF%B7%E5%88%86%E7%89%87%E4%B8%8A%E4%BC%A0 | ||
func (s *SDK) MediaAssetApplyUpload(c context.Context, body bm.BodyMap) (rsp *MediaAssetApplyUploadRsp, err error) { | ||
path := "/wxa/sec/vod/applyupload?access_token=" + s.accessToken | ||
rsp = &MediaAssetApplyUploadRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetUploadPart 媒资上传-上传分片 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:将文件的其中一个分片上传到平台,最多支持100个分片,每个分片大小为5MB,最后一个分片可以小于5MB。该接口适用于视频和封面图片。视频最大支持500MB,封面图片最大支持10MB。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-5-%E4%B8%8A%E4%BC%A0%E5%88%86%E7%89%87 | ||
func (s *SDK) MediaAssetUploadPart(c context.Context, body bm.BodyMap) (rsp *MediaAssetUploadPartRsp, err error) { | ||
path := "/wxa/sec/vod/uploadpart?access_token=" + s.accessToken | ||
rsp = &MediaAssetUploadPartRsp{} | ||
if _, err = s.DoRequestPostFile(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} | ||
|
||
// MediaAssetCommitUpload 媒资上传-确认上传 | ||
// 注意:errcode = 0 为成功 | ||
// 说明:该接口用于完成整个分片上传流程,合并所有文件分片,确认媒体文件(和封面图片文件)上传到平台的结果,返回文件的 ID。请求中需要给出每一个分片的 part_number 和 etag,用来校验分片的准确性。 | ||
// 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/mini-drama/mini_drama.html#_1-6-%E7%A1%AE%E8%AE%A4%E4%B8%8A%E4%BC%A0 | ||
func (s *SDK) MediaAssetCommitUpload(c context.Context, body bm.BodyMap) (rsp *MediaAssetCommitUploadRsp, err error) { | ||
path := "/wxa/sec/vod/commitupload?access_token=" + s.accessToken | ||
rsp = &MediaAssetCommitUploadRsp{} | ||
if _, err = s.DoRequestPost(c, path, body, rsp); err != nil { | ||
return nil, err | ||
} | ||
if rsp.Errcode != Success { | ||
return nil, fmt.Errorf("errcode(%d), errmsg(%s)", rsp.Errcode, rsp.Errmsg) | ||
} | ||
return rsp, nil | ||
} |
Oops, something went wrong.