|
- package main
-
- import (
- "bytes"
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
- )
-
- type mediaQuery struct {
- Type string `json:"type"`
- Offiset string `json:"offset"`
- Count int `json:"count"`
- }
-
- type mediaCount struct {
- VoiceCount int64 `json:"voice_count"`
- VideoCount int64 `json:"video_count"`
- ImageCount int64 `json:"image_count"`
- NewsCount int64 `json:"news_count"`
- }
-
- func getNewList() (jstr string) {
- jstr = getMediaList("news")
- return
- }
-
- func getMediaList(mediaType string) (jstr string) {
- var jsonStr = []byte(`{"type":mediaType, "offset":0, "count":20}`)
- u := url4NewsList()
- req, err := http.NewRequest("POST", u, bytes.NewBuffer(jsonStr))
- log.Println(u)
- if err != nil {
- return ""
- }
-
- client := &http.Client{}
- r, err := client.Do(req)
- if err != nil {
- return ""
- }
- defer r.Body.Close()
- b, _ := ioutil.ReadAll(r.Body)
- jstr = string(b)
- return
- }
-
- func url4NewsList() string {
- atk, _ := GetAccessToken()
- u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s", atk)
- return u
- }
-
- func url4MediaCount() string {
- atk, _ := GetAccessToken()
- u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s", atk)
- return u
- }
|