Skip to content
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

feat(media): add getTempFile api #801

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions work/material/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
// uploadAttachment 上传附件资源
uploadAttachment = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_attachment?access_token=%s&media_type=%s&attachment_type=%d"
// getTempFile 获取临时素材
getTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s"
)

// UploadImgResponse 上传图片响应
Expand Down Expand Up @@ -148,3 +150,21 @@ func (r *Client) UploadAttachmentFromReader(filename, mediaType string, reader i
err = util.DecodeWithError(response, result, "UploadAttachment")
return result, err
}

// GetTempFile 获取临时素材
// @see https://developer.work.weixin.qq.com/document/path/90254
func (r *Client) GetTempFile(mediaID string) ([]byte, error) {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return nil, err
}
url := fmt.Sprintf(getTempFile, accessToken, mediaID)
response, err := util.HTTPGet(url)
if err != nil {
return nil, err
}
return response, nil
}
Loading