|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
|
|
|
"encoding/json" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"log" |
|
|
"log" |
|
|
"net/http" |
|
|
"net/http" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type mediaQuery struct { |
|
|
|
|
|
|
|
|
type materialQuery struct { |
|
|
Type string `json:"type"` |
|
|
Type string `json:"type"` |
|
|
Offiset string `json:"offset"` |
|
|
|
|
|
|
|
|
Offiset int `json:"offset"` |
|
|
Count int `json:"count"` |
|
|
Count int `json:"count"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type mediaCount struct { |
|
|
|
|
|
|
|
|
type materialCount struct { |
|
|
VoiceCount int64 `json:"voice_count"` |
|
|
VoiceCount int64 `json:"voice_count"` |
|
|
VideoCount int64 `json:"video_count"` |
|
|
VideoCount int64 `json:"video_count"` |
|
|
ImageCount int64 `json:"image_count"` |
|
|
ImageCount int64 `json:"image_count"` |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getMediaList(mediaType string) (jstr string) { |
|
|
func getMediaList(mediaType string) (jstr string) { |
|
|
var jsonStr = []byte(`{"type":mediaType, "offset":0, "count":20}`) |
|
|
|
|
|
u := url4NewsList() |
|
|
|
|
|
|
|
|
var q = materialQuery{mediaType, 0, 20} |
|
|
|
|
|
jsonStr, _ := json.Marshal(q) |
|
|
|
|
|
u := url4MaterialList() |
|
|
req, err := http.NewRequest("POST", u, bytes.NewBuffer(jsonStr)) |
|
|
req, err := http.NewRequest("POST", u, bytes.NewBuffer(jsonStr)) |
|
|
log.Println(u) |
|
|
log.Println(u) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
|
|
|
|
|
|
u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s", atk) |
|
|
u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s", atk) |
|
|
return u |
|
|
return u |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getMaterialCount() (materialCount, error) { |
|
|
|
|
|
mc := materialCount{} |
|
|
|
|
|
url := url4MaterialCount() |
|
|
|
|
|
r, err := http.Get(url) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return mc, err |
|
|
|
|
|
} |
|
|
|
|
|
defer r.Body.Close() |
|
|
|
|
|
b, _ := ioutil.ReadAll(r.Body) |
|
|
|
|
|
err = json.Unmarshal(b, &mc) |
|
|
|
|
|
return mc, nil |
|
|
|
|
|
} |