Skip to content

Commit 44b09c7

Browse files
authored
feat(media): add getTempFile api (#801)
add getTempFile api
1 parent 2e07088 commit 44b09c7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

work/material/media.go

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const (
1414
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
1515
// uploadAttachment 上传附件资源
1616
uploadAttachment = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_attachment?access_token=%s&media_type=%s&attachment_type=%d"
17+
// getTempFile 获取临时素材
18+
getTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s"
1719
)
1820

1921
// UploadImgResponse 上传图片响应
@@ -148,3 +150,21 @@ func (r *Client) UploadAttachmentFromReader(filename, mediaType string, reader i
148150
err = util.DecodeWithError(response, result, "UploadAttachment")
149151
return result, err
150152
}
153+
154+
// GetTempFile 获取临时素材
155+
// @see https://developer.work.weixin.qq.com/document/path/90254
156+
func (r *Client) GetTempFile(mediaID string) ([]byte, error) {
157+
var (
158+
accessToken string
159+
err error
160+
)
161+
if accessToken, err = r.GetAccessToken(); err != nil {
162+
return nil, err
163+
}
164+
url := fmt.Sprintf(getTempFile, accessToken, mediaID)
165+
response, err := util.HTTPGet(url)
166+
if err != nil {
167+
return nil, err
168+
}
169+
return response, nil
170+
}

0 commit comments

Comments
 (0)