Selaa lähdekoodia

media navitation and list move to seperate file

master
Patrick Peng Sun 8 vuotta sitten
vanhempi
commit
518418ef01
2 muutettua tiedostoa jossa 59 lisäystä ja 38 poistoa
  1. +0
    -38
      download.go
  2. +59
    -0
      medialist.go

+ 0
- 38
download.go Näytä tiedosto

@@ -1,7 +1,6 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"io"
@@ -52,16 +51,6 @@ func saveURL(url string) (tmpFile string, contentType string, err error) {
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"}
type videoURL struct {
VideoURL string `json:"video_url"`
@@ -84,30 +73,3 @@ func readVideoURL(path string) (u string) {
}
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
}

+ 59
- 0
medialist.go Näytä tiedosto

@@ -0,0 +1,59 @@
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
}

Loading…
Peruuta
Tallenna