-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathassets.go
84 lines (74 loc) · 2.33 KB
/
assets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package wechat3rd
import (
"github.com/l306287405/wechat3rd/core"
"net/url"
)
type MediaUploadReq struct {
Path string `json:"path"`
Type string `json:"type"`
}
type MediaUploadResp struct {
core.Error
Type string `json:"type"`
MediaId string `json:"media_id"`
CreatedAt int `json:"created_at"`
}
//新增临时素材
//https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html
func (s *Server) MediaUpload(authorizerAccessToken string, req *MediaUploadReq) (resp *MediaUploadResp) {
var (
u = CGIUrl + "/media/upload?"
)
u = s.AuthToken2url(u, authorizerAccessToken) + "&type=" + req.Type
resp = &MediaUploadResp{}
resp.Err(core.PostFile(u, req.Path, "media", resp))
return
}
type MediaGetResp struct {
core.Error
VideoUrl string `json:"video_url"`
}
//获取临时素材
//https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
func (s *Server) MediaGet(authorizerAccessToken string, mediaId string) (resp *MediaGetResp) {
var (
u = CGIUrl + "/media/get?"
req = url.Values{}
)
req.Set("media_id", mediaId)
resp = &MediaGetResp{}
resp.Err(core.GetRequest(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}
type MaterialItem struct {
Title string `json:"title"`
ThumbMediaId string `json:"thumbMediaId"`
ShowCoverPic int8 `json:"showCoverPic"`
Author string `json:"author"`
Digest string `json:"digest"`
Content string `json:"content"`
Url string `json:"url"`
ContentSourceUrl string `json:"contentSourceUrl"`
}
type GetMaterialResp struct {
core.Error
//图文内容响应结果
NewsItem []*MaterialItem `json:"newsItem,omitempty"`
//视频消息响应结果
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
DownUrl *string `json:"downUrl,omitempty"`
}
//获取永久素材
//https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
func (s *Server) GetMaterial(authorizerAccessToken string, mediaId string) (resp *GetMaterialResp) {
var (
u = CGIUrl + "/material/get_material?"
req = &struct {
MediaId string `json:"mediaId"`
}{MediaId: mediaId}
)
resp = &GetMaterialResp{}
resp.Err(core.PostJson(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}