From df9889d982aaba40514ebe50167409f1bf6eb17c Mon Sep 17 00:00:00 2001 From: Amor Date: Mon, 6 Jul 2020 20:03:43 +0800 Subject: [PATCH] feat: get material count (#292) * feat: get material count --- officialaccount/material/material.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/officialaccount/material/material.go b/officialaccount/material/material.go index 2fe3f4b..3c505b3 100644 --- a/officialaccount/material/material.go +++ b/officialaccount/material/material.go @@ -14,6 +14,7 @@ const ( addMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/add_material" delMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/del_material" getMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/get_material" + getMaterialCountURL = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s" batchGetMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material" ) @@ -294,3 +295,29 @@ func (material *Material) BatchGetMaterial(permanentMaterialType PermanentMateri err = util.DecodeWithError(response, &list, "BatchGetMaterial") return } + +// ResMaterialCount 素材总数 +type ResMaterialCount struct { + util.CommonError + VoiceCount int64 `json:"voice_count"` // 语音总数量 + VideoCount int64 `json:"video_count"` // 视频总数量 + ImageCount int64 `json:"image_count"` // 图片总数量 + NewsCount int64 `json:"news_count"` // 图文总数量 +} + +// GetMaterialCount 获取素材总数. +func (material *Material) GetMaterialCount() (res ResMaterialCount, err error) { + var accessToken string + accessToken, err = material.GetAccessToken() + if err != nil { + return + } + uri := fmt.Sprintf("%s?access_token=%s", getMaterialCountURL, accessToken) + var response []byte + response, err = util.HTTPGet(uri) + if err != nil { + return + } + err = util.DecodeWithError(response, &res, "GetMaterialCount") + return +}