Sfoglia il codice sorgente

download news list success

master
Patrick Peng Sun 8 anni fa
parent
commit
999da2ed40
3 ha cambiato i file con 38 aggiunte e 3 eliminazioni
  1. +28
    -1
      download.go
  2. +9
    -1
      download_test.go
  3. +1
    -1
      wechat_hitxy_access_token

+ 28
- 1
download.go Vedi File

package main package main


import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
if err == nil { if err == nil {
_, err = url.ParseRequestURI(v.VideoURL) _, err = url.ParseRequestURI(v.VideoURL)
if err == nil { if err == nil {

return v.VideoURL return v.VideoURL
} }
} }
} }
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
}

+ 9
- 1
download_test.go Vedi File

package main package main


import "testing"
import (
"log"
"testing"
)


func TestReadVideoURL(t *testing.T) { func TestReadVideoURL(t *testing.T) {
u := readVideoURL("media_for_test/videourl.json") u := readVideoURL("media_for_test/videourl.json")
expected := "http://153.37.232.148/vweixinp.tc.qq.com/1007_baa70feeaffb450682d848707e2d38d9.f10.mp4?vkey=6027E95AC6BADE010F39C1C08FA1E8E264C4702D52BE4B04C6BAF89A0857AB371971463C6C1D5D4779E1B748D1BC21041EC5AFBCD41BE4E7D0295A3DA96254505E8ACBDF1C427FD2FC92D5AB0CA9BFD16C0E02D99675DED4&sha=0&save=1" expected := "http://153.37.232.148/vweixinp.tc.qq.com/1007_baa70feeaffb450682d848707e2d38d9.f10.mp4?vkey=6027E95AC6BADE010F39C1C08FA1E8E264C4702D52BE4B04C6BAF89A0857AB371971463C6C1D5D4779E1B748D1BC21041EC5AFBCD41BE4E7D0295A3DA96254505E8ACBDF1C427FD2FC92D5AB0CA9BFD16C0E02D99675DED4&sha=0&save=1"
AssertEqual(t, u, expected, "URL should be equal to "+expected) AssertEqual(t, u, expected, "URL should be equal to "+expected)
} }
func TestGetMediaList(t *testing.T) {
SetupConfig()
l := getNewList()
log.Printf("file is : %s", l)
}

+ 1
- 1
wechat_hitxy_access_token Vedi File

{"access_token":"7_AZHknAOn1mHOS-kYHbN7jhMGBDHTbVHOLWvo_VcbePdruPvLJm2hhBbCU9BUSmmhBjhhNOvFMp1Hx12kunIGehLxKUGdKgJmO55mPVYXldjVivHcCfOS_XlDSMAxr3GMFgACASYR","expires_in":7200,"created_at":"2017-05-09T16:52:32.722017137+10:00"}
{"access_token":"GAMFvLGWol69qo3-zGVswpXzlWsmt_4xUGUJf4Gsesk2-gJuiIxUlOdBaVJU-xVCoAz7OheyR2nJ36_RP0lJK9ARl8yJeJD62pE5XoLuHkdCXrEeTRip-MFEvC6SkYuNSWZiAGALPS","expires_in":7200,"created_at":"2017-05-10T02:52:24.014027459+10:00"}

Loading…
Annulla
Salva