From e51c9e97a37c350e332c8c64c8ef713284b3bf1d Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Fri, 12 May 2017 00:41:50 +1000 Subject: [PATCH] thumb media id added --- mediaID.go | 16 +++++++++++++--- outMsg.go | 15 +++++++++++++-- upload_test.go | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/mediaID.go b/mediaID.go index 088e815..4367f2e 100644 --- a/mediaID.go +++ b/mediaID.go @@ -7,9 +7,10 @@ import ( //MediaID : json response for uploading media type MediaID struct { - Type string `json:"type"` - MediaID string `json:"media_id"` - CreateAt int64 `json:"created_at"` + Type string `json:"type"` + MediaID string `json:"media_id"` + CreateAt int64 `json:"created_at"` + ThumbMediaID string `json:"thumb_media_id"` } func uploadImage(filename string) (mediaid string) { @@ -44,6 +45,15 @@ func uploadVoice(path string) (mediaID string) { return } +func uploadThumb(path string) (mediaID string) { + url, _ := getPostThumbURL() + jstr, _ := postFileForm(path, url, "media") + var m = MediaID{} + json.Unmarshal([]byte(jstr), &m) + mediaID = m.ThumbMediaID + return +} + func checkImageSanity() bool { //check file size should < 2M fmt.Println(" should check image file size") diff --git a/outMsg.go b/outMsg.go index 7b19028..382f70f 100644 --- a/outMsg.go +++ b/outMsg.go @@ -144,7 +144,18 @@ func videoMsgTemplate() string { ` } -func bulidMusicMsg(ToUserName, mediaID, title, description, url, hqURL string) (msg string) { +func buildSampleMusicMsg(ToUserName string) (msg string) { + thumbID := "AxEDlSNwJcs_0KnyiGnpAYiB1-sjITosWkU3VFsj62KuCyTQO-Fh1UH8d-pBmY1K" + thumbID = "JZoNKZr9gzaI5ELBnFUljujiBfIwr4CtXHkZtQMjm-sLVD5PGOU_uvsaF3oNNFjp" + url := "http://www.youtubeinmp3.com/download/get/?i=vNIuJKoAE46uz2RggRaKGFqQUVAqd0Td&e=92&progressType=button&color=008000" + url = "http://agobe.yt-downloader.org/download.php?id=d7be28d3a1fafa69d7e464edb8186226" + url = "http://www.sample-videos.com/audio/mp3/india-national-anthem.mp3" + url = "http://google.com/" + msg = buildMusicMsg(ToUserName, thumbID, "音乐标杆出", "fkd;ajf;daf说明动卡及另附;dasjfsda", url, url) + return +} + +func buildMusicMsg(ToUserName, ThumbMediaID, title, description, url, hqURL string) (msg string) { msg = fmt.Sprintf(musicMsgTemplate(), ToUserName, APIConfig.PublicAccountID, @@ -153,7 +164,7 @@ func bulidMusicMsg(ToUserName, mediaID, title, description, url, hqURL string) ( description, url, hqURL, - mediaID) + ThumbMediaID) return } func musicMsgTemplate() string { diff --git a/upload_test.go b/upload_test.go index a04de6f..395fc6b 100644 --- a/upload_test.go +++ b/upload_test.go @@ -60,3 +60,21 @@ func TestUploadVoice(t *testing.T) { mediaID := uploadVoice(src) log.Println(mediaID) } + +func TestUploadThumb(t *testing.T) { + SetupConfig() + src := "media_for_test/music-thumb.jpg" + mediaID := uploadThumb(src) + log.Println(mediaID) + + //download the media back using the media id + filename, e := saveMedia2File(mediaID) + 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 ") + +}