Skip to content

Commit

Permalink
Merge pull request #403 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Matrix-X authored Nov 2, 2023
2 parents da79180 + 6d57a21 commit b02e5ca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/officialAccount/material/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func (comp *Client) UploadImage(ctx context.Context, path string) (*response.Res
return result, err
}

// 上传永久图片素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadImageByData(ctx context.Context, data []byte) (*response.ResponseMaterialAddMaterial, error) {
result := &response.ResponseMaterialAddMaterial{}
_, err := comp.UploadByData(ctx, "image", "image", data, &object.StringMap{}, result)
return result, err
}

// 上传永久语音素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadVoice(ctx context.Context, path string) (*response.ResponseMaterialAddMaterial, error) {
Expand All @@ -46,6 +54,14 @@ func (comp *Client) UploadVoice(ctx context.Context, path string) (*response.Res
return result, err
}

// 上传永久语音素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadVoiceByData(ctx context.Context, data []byte) (*response.ResponseMaterialAddMaterial, error) {
result := &response.ResponseMaterialAddMaterial{}
_, err := comp.UploadByData(ctx, "voice", "voice", data, &object.StringMap{}, result)
return result, err
}

// 上传永久缩略图素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadThumb(ctx context.Context, path string) (*response.ResponseMaterialAddMaterial, error) {
Expand All @@ -54,6 +70,14 @@ func (comp *Client) UploadThumb(ctx context.Context, path string) (*response.Res
return result, err
}

// 上传永久缩略图素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadThumbByData(ctx context.Context, data []byte) (*response.ResponseMaterialAddMaterial, error) {
result := &response.ResponseMaterialAddMaterial{}
_, err := comp.UploadByData(ctx, "thumb", "thumb", data, &object.StringMap{}, result)
return result, err
}

// 上传永久视频素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadVideo(ctx context.Context, path string, title string, description string) (*response.ResponseMaterialAddMaterial, error) {
Expand All @@ -76,6 +100,28 @@ func (comp *Client) UploadVideo(ctx context.Context, path string, title string,
return result, err
}

// 上传永久视频素材
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (comp *Client) UploadVideoByData(ctx context.Context, data []byte, title string, description string) (*response.ResponseMaterialAddMaterial, error) {

result := &response.ResponseMaterialAddMaterial{}

jsonDescription, err := object.JsonEncode(&object.HashMap{
"title": title,
"introduction": description,
})
if err != nil {
return nil, err
}

params := &object.StringMap{
"Description": jsonDescription,
}

_, err = comp.UploadByData(ctx, "video", "video", data, params, result)
return result, err
}

// 新增永久素材
// https://developers.weixin.qq.com/doc/offiaccount/Comments_management/Image_Comments_Management_Interface.html
func (comp *Client) UploadArticle(ctx context.Context, articles request2.RequestAddArticles) (*response.ResponseMaterialAddNews, error) {
Expand All @@ -92,7 +138,7 @@ func (comp *Client) UploadArticle(ctx context.Context, articles request2.Request
return result, err
}

// 上传永久视频素材
// 上传永久素材
// https://developers.weixin.qq.com/doc/offiaccount/Comments_management/Image_Comments_Management_Interface.html
func (comp *Client) UpdateArticle(ctx context.Context, mediaID string, articles request2.RequestAddArticles, index int) (response.ResponseMaterialAddNews, error) {
result := response.ResponseMaterialAddNews{}
Expand Down Expand Up @@ -220,6 +266,20 @@ func (comp *Client) Upload(ctx context.Context, Type string, path string, query
return comp.BaseClient.HttpUpload(ctx, comp.getApiByType(Type), files, form, query, nil, result)
}

func (comp *Client) UploadByData(ctx context.Context, Type string, name string, data []byte, query *object.StringMap, result interface{}) (interface{}, error) {

formData := &kernel.UploadForm{
Contents: []*kernel.UploadContent{
&kernel.UploadContent{
Name: name,
Value: data,
},
},
}

return comp.BaseClient.HttpUpload(ctx, comp.getApiByType(Type), nil, formData, query, nil, result)
}

func (comp *Client) getApiByType(Type string) string {

switch Type {
Expand Down
1 change: 1 addition & 0 deletions src/officialAccount/menu/request/requestMenuCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type SubButton struct {
AppID string `json:"appid,omitempty"`
PagePath string `json:"pagepath,omitempty"`
Key string `json:"key,omitempty"`
MediaId string `json:"media_id,omitempty"`
SubButtons []SubButton `json:"sub_button,omitempty"`
}

Expand Down

0 comments on commit b02e5ca

Please sign in to comment.