mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-10 15:52:26 +08:00
增加获取永久素材接口
This commit is contained in:
@@ -13,6 +13,7 @@ const (
|
|||||||
addNewsURL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
addNewsURL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
||||||
addMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/add_material"
|
addMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/add_material"
|
||||||
delMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/del_material"
|
delMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/del_material"
|
||||||
|
getMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/get_material"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Material 素材管理
|
//Material 素材管理
|
||||||
@@ -36,6 +37,33 @@ type Article struct {
|
|||||||
ShowCoverPic int `json:"show_cover_pic"`
|
ShowCoverPic int `json:"show_cover_pic"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ContentSourceURL string `json:"content_source_url"`
|
ContentSourceURL string `json:"content_source_url"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
DownURL string `json:"down_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNews 获取/下载永久素材
|
||||||
|
func (material *Material) GetNews(id string) ([]*Article, error) {
|
||||||
|
accessToken, err := material.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", getMaterialURL, accessToken)
|
||||||
|
|
||||||
|
var req struct {
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
}
|
||||||
|
req.MediaID = id
|
||||||
|
responseBytes, err := util.PostJSON(uri, req)
|
||||||
|
|
||||||
|
var res struct {
|
||||||
|
NewsItem []*Article `json:"news_item"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(responseBytes, &res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.NewsItem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//reqArticles 永久性图文素材请求信息
|
//reqArticles 永久性图文素材请求信息
|
||||||
|
|||||||
Reference in New Issue
Block a user