Bläddra i källkod

material count download is successful

master
Patrick Peng Sun 8 år sedan
förälder
incheckning
935d6bfec8
3 ändrade filer med 52 tillägg och 11 borttagningar
  1. +0
    -6
      download_test.go
  2. +20
    -5
      material.go
  3. +32
    -0
      material_test.go

+ 0
- 6
download_test.go Visa fil

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

import (
"log"
"testing"
)

@@ -10,8 +9,3 @@ func TestReadVideoURL(t *testing.T) {
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)
}
func TestGetMediaList(t *testing.T) {
SetupConfig()
l := getNewList()
log.Printf("file is : %s", l)
}

+ 20
- 5
material.go Visa fil

@@ -2,19 +2,20 @@ package main

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)

type mediaQuery struct {
type materialQuery struct {
Type string `json:"type"`
Offiset string `json:"offset"`
Offiset int `json:"offset"`
Count int `json:"count"`
}

type mediaCount struct {
type materialCount struct {
VoiceCount int64 `json:"voice_count"`
VideoCount int64 `json:"video_count"`
ImageCount int64 `json:"image_count"`
@@ -27,8 +28,9 @@ func getNewList() (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))
log.Println(u)
if err != nil {
@@ -57,3 +59,16 @@ func url4MaterialCount() string {
u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s", atk)
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
}

+ 32
- 0
material_test.go Visa fil

@@ -0,0 +1,32 @@
package main

import (
"log"
"testing"
)

func TestGetMaterialList(t *testing.T) {
SetupConfig()
l := getNewList()

log.Printf("file is : %s", l)

// l = getVoiceList()
// log.Printf("file is : %s", l)
// l = getVideoList()
// log.Printf("file is : %s", l)
// l = getImageList()
// log.Printf("file is : %s", l)
}

func TestGetMaterialCount(t *testing.T) {
SetupConfig()
mc, err := getMaterialCount()
if err != nil {
log.Fatal(err)
}
log.Printf("Voice: %d", mc.VoiceCount)
log.Printf("Video: %d", mc.VideoCount)
log.Printf("Image: %d", mc.ImageCount)
log.Printf("News : %d", mc.NewsCount)
}

Laddar…
Avbryt
Spara