Skip to content

Commit

Permalink
feat(media): add getTempFile api
Browse files Browse the repository at this point in the history
add getTempFile api
  • Loading branch information
Lumiaqian committed Oct 16, 2024
1 parent 2e07088 commit aafc82e
Showing 1 changed file with 20 additions and 0 deletions.
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
}

0 comments on commit aafc82e

Please sign in to comment.