| package main | package main | ||||
| import ( | import ( | ||||
| "bytes" | |||||
| "encoding/json" | "encoding/json" | ||||
| "fmt" | "fmt" | ||||
| "io" | "io" | ||||
| return | return | ||||
| } | } | ||||
| func contentType2MediaType(contentType string) (mediaType string) { | |||||
| switch contentType { | |||||
| case "image/jpeg": | |||||
| mediaType = "image" | |||||
| case "text/plain": | |||||
| mediaType = "json" | |||||
| } | |||||
| return | |||||
| } | |||||
| //{"video_url":"http://153.37.232.145/vweixinp.tc.qq.com/1007_6475d21fb443453b8adeac7e59cc0e1c.f10.mp4?vkey=E79C6B0DA06E7A434D15E24774F91412386D1956768C400AC93ECA5320ACAAAF050E1E1BA5C22DFD81B5EE3FBA97E928E0FC2DC597CF611B3E6641BC1AEE2892736FFE29E993F200AA4A0811FEB4E234C48516131207DDE4&sha=0&save=1"} | //{"video_url":"http://153.37.232.145/vweixinp.tc.qq.com/1007_6475d21fb443453b8adeac7e59cc0e1c.f10.mp4?vkey=E79C6B0DA06E7A434D15E24774F91412386D1956768C400AC93ECA5320ACAAAF050E1E1BA5C22DFD81B5EE3FBA97E928E0FC2DC597CF611B3E6641BC1AEE2892736FFE29E993F200AA4A0811FEB4E234C48516131207DDE4&sha=0&save=1"} | ||||
| type videoURL struct { | type videoURL struct { | ||||
| VideoURL string `json:"video_url"` | VideoURL string `json:"video_url"` | ||||
| } | } | ||||
| return "" | return "" | ||||
| } | } | ||||
| func getNewList() (jstr string) { | |||||
| var jsonStr = []byte(`{"type":"news", "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 | |||||
| } |
| 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 | |||||
| } |