package main import ( "fmt" "log" ) func serveCommand(openID string, in InWechatMsg) (state chatState, processed bool) { log.Println("process command") return echoCommand(openID, in) } func echoCommand(openID string, in InWechatMsg) (state chatState, processed bool) { processed = true str, err := BuildTextMsg(openID, "default") log.Println(in.header.MsgType) switch in.body.(type) { case TextMsg: m := in.body.(TextMsg) str, err = BuildTextMsg(openID, m.Content) case PicMsg: m := in.body.(PicMsg) str = buildPicMsg(openID, m.MediaId) case VoiceMsg: m := in.body.(VoiceMsg) str = buildVoiceMsg(openID, m.MediaId) kfSendTxt(openID, "翻译结果:"+m.Recognition) case VideoMsg: m := in.body.(VideoMsg) str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) case ShortVideoMsg: m := in.body.(ShortVideoMsg) str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) case LocationMsg: m := in.body.(LocationMsg) str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) case EventMsg: m := in.body.(EventMsg) log.Println(m) url := fmt.Sprintf("https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&markers=color:red|label:S|%f,%f&zoom=12&size=414x736", m.Latitude, m.Longitude, m.Latitude, m.Longitude) log.Println(url) file, _, _ := saveURL(url) str = buildUploadPicMsg(openID, file) //str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scal =%f", m.Longitude, m.Latitude, m.Precision)) default: str, err = BuildTextMsg(openID, "text message") } state.OpenID = openID state.Procedure = "" state.response = str log.Println(str) if err != nil { log.Println("build response failed") processed = false } //state is any state that return }