Quellcode durchsuchen

upload voice worked and tested with wechat client

master
Patrick Peng Sun vor 8 Jahren
Ursprung
Commit
8ff9e51973
5 geänderte Dateien mit 25 neuen und 1 gelöschten Zeilen
  1. +9
    -0
      mediaID.go
  2. +8
    -0
      outMsg.go
  3. +1
    -0
      server.go
  4. +7
    -0
      upload_test.go
  5. +0
    -1
      wechat_hitxy_access_token

mediaId.go → mediaID.go Datei anzeigen



} }


func uploadVoice(path string) (mediaID string) {
url, _ := getPostVoiceURL()
jstr, _ := postFileForm(path, url, "media")
var m = MediaID{}
json.Unmarshal([]byte(jstr), &m)
mediaID = m.MediaID
return
}

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

+ 8
- 0
outMsg.go Datei anzeigen

msg = buildPicMsg(ToUserName, mediaID) msg = buildPicMsg(ToUserName, mediaID)
return return
} }

func buildPicMsg(ToUserName, mediaID string) (msg string) { func buildPicMsg(ToUserName, mediaID string) (msg string) {
msg = fmt.Sprintf(picMsgTemplate(), ToUserName, APIConfig.PublicAccountID, int32(time.Now().Unix()), mediaID) msg = fmt.Sprintf(picMsgTemplate(), ToUserName, APIConfig.PublicAccountID, int32(time.Now().Unix()), mediaID)
return return
</xml>` </xml>`
} }


func buildUploadVoiceMsg(ToUserName, path string) (msg string) {
mediaID := uploadVoice(path)
log.Println("get media id " + mediaID)
msg = buildVoiceMsg(ToUserName, mediaID)
return
}

func buildVoiceMsg(ToUserName, mediaID string) (msg string) { func buildVoiceMsg(ToUserName, mediaID string) (msg string) {
msg = fmt.Sprintf(voiceMsgTemplate(), ToUserName, APIConfig.PublicAccountID, int32(time.Now().Unix()), mediaID) msg = fmt.Sprintf(voiceMsgTemplate(), ToUserName, APIConfig.PublicAccountID, int32(time.Now().Unix()), mediaID)
return return

+ 1
- 0
server.go Datei anzeigen

reply = buildVideoMsg(h.FromUserName, mediaID, "标题123", a.Event+"/"+a.EventKey) reply = buildVideoMsg(h.FromUserName, mediaID, "标题123", a.Event+"/"+a.EventKey)


reply = buildUploadPicMsg(h.FromUserName, "media_for_test/640x480.jpg") reply = buildUploadPicMsg(h.FromUserName, "media_for_test/640x480.jpg")
reply = buildUploadVoiceMsg(h.FromUserName, "media_for_test/example.amr")
} }
w.Header().Set("Content-Type", "text/xml; charset=utf-8") w.Header().Set("Content-Type", "text/xml; charset=utf-8")
fmt.Fprint(w, reply) fmt.Fprint(w, reply)

+ 7
- 0
upload_test.go Datei anzeigen

AssertEqual(t, err, nil, "error ro compare file should be nil ") AssertEqual(t, err, nil, "error ro compare file should be nil ")
AssertEqual(t, equal, true, "video file should be equal ") AssertEqual(t, equal, true, "video file should be equal ")
} }

func TestUploadVoice(t *testing.T) {
SetupConfig()
src := "media_for_test/example.amr"
mediaID := uploadVoice(src)
log.Println(mediaID)
}

+ 0
- 1
wechat_hitxy_access_token Datei anzeigen

{"access_token":"GAMFvLGWol69qo3-zGVswpXzlWsmt_4xUGUJf4Gsesk2-gJuiIxUlOdBaVJU-xVCoAz7OheyR2nJ36_RP0lJK9ARl8yJeJD62pE5XoLuHkdCXrEeTRip-MFEvC6SkYuNSWZiAGALPS","expires_in":7200,"created_at":"2017-05-10T02:52:24.014027459+10:00"}

Laden…
Abbrechen
Speichern