Sfoglia il codice sorgente

video media upload/download test started, with success, (but need to decoe video json automatically in following works.

master
Patrick Peng Sun 8 anni fa
parent
commit
223bc41511
3 ha cambiato i file con 33 aggiunte e 3 eliminazioni
  1. +12
    -0
      mediaId.go
  2. +20
    -2
      upload_test.go
  3. +1
    -1
      wechat_hitxy_access_token

+ 12
- 0
mediaId.go Vedi File

@@ -23,6 +23,18 @@ func uploadImage(filename string) (mediaid string) {
return
}

func uploadVideo(filename string) (mediaid string) {
url, _ := getPostVideoURL()

jstr, _ := postFileForm(filename, url, "media")
//{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
var m = MediaID{}
json.Unmarshal([]byte(jstr), &m)
mediaid = m.MediaID
return

}

func checkImageSanity() bool {
//check file size should < 2M
fmt.Println(" should check image file size")

+ 20
- 2
upload_test.go Vedi File

@@ -16,8 +16,6 @@ func TestUploadImage(t *testing.T) {
fmt.Printf("get MediaID: %s \n", mediaID)
//200 OK
//{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
//mediaID = "3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2"
//mediaID = "L2Cyf6F5GvVXpubv75Pnf51f-Z7Ah5fOROqt1qsZTLmrebtOmeQy9Co2xw7JI6ck"
assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")

//download the media back using the media id
@@ -30,3 +28,23 @@ func TestUploadImage(t *testing.T) {
AssertEqual(t, err, nil, "file should be equal ")
AssertEqual(t, equal, true, "file should be equal ")
}

func TestUploadVideo(t *testing.T) {
SetupConfig()
src := "media_for_test/video.mp4"
mediaID := uploadVideo(src)
fmt.Printf("get MediaID: %s \n", mediaID)
//200 OK
//{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")

//download the media back using the media id
filename, e := saveMedia2File(mediaID) // this isi a json with video link, we should download it and compare it.
log.Println("saved :" + filename)
AssertEqual(t, e, nil, "mediaID should be saved without any error")
//make sure two files are the same
cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
equal, err := cmp.CompareFile(src, filename)
AssertEqual(t, err, nil, "file should be equal ")
AssertEqual(t, equal, true, "file should be equal ")
}

+ 1
- 1
wechat_hitxy_access_token Vedi File

@@ -1 +1 @@
{"access_token":"VkqKPaCmYeSLh5p4-0AA7pew_ncB7YY-u5P4S-hc2T8V1KQiRoSsXwjvh4QVb4_eZqEaG_gdrL0e-o9Lz3ajV3HzqftUdzMhi_K7gr0ueguf4MQLFGfahofD7VFoSf98LXVbAHABNL","expires_in":7200,"created_at":"2017-05-07T20:32:46.746644722+10:00"}
{"access_token":"p0-QwbIjK_jEqc-MvDTODjZgQDrrA0hUkcF2zk8y38_9P7xPodtiKx9dePoTs92bGrrthcUp-dj3izRXMt-Hfd0nFa1CW7nq0LzNLx7g1BCM2GyRxyt2q03G0CgOM3GpKIPiAHAXVC","expires_in":7200,"created_at":"2017-05-08T12:06:22.041624283+10:00"}

Loading…
Annulla
Salva