| } | } | ||||
| func echoInit(ss *openIDSessionData) { | func echoInit(ss *openIDSessionData) { | ||||
| ss.Procedure = idProcEcho | |||||
| ss.setProcedure(idProcEcho) | |||||
| ss.refreshExpire(600) | |||||
| } | } | ||||
| func echoClean(ss *openIDSessionData) { | func echoClean(ss *openIDSessionData) { | ||||
| ss.Procedure = "" | ss.Procedure = "" | ||||
| log.Println(*ss) | |||||
| } | } | ||||
| func echoStart(ss *openIDSessionData, in InWechatMsg) { | func echoStart(ss *openIDSessionData, in InWechatMsg) { | ||||
| echoCommand(ss, in) | |||||
| } | } | ||||
| func echoServe(ss *openIDSessionData, in InWechatMsg) { | func echoServe(ss *openIDSessionData, in InWechatMsg) { | ||||
| if in.header.MsgType == "text" { | |||||
| if in.body.(TextMsg).Content == "结束Echo" { | |||||
| in.replyText("echo 正式结束") | |||||
| echoClean(ss) | |||||
| return | |||||
| } | |||||
| } | |||||
| ss.refreshExpire(600) | |||||
| echoCommand(ss, in) | |||||
| kfSendTxt(ss.OpenID, "10 分钟之后 Echo将自动结束,\n输入 [结束Echo] 清除Echo模式") | |||||
| } | } | ||||
| func echoSummary(ss *openIDSessionData) { | func echoSummary(ss *openIDSessionData) { | ||||
| } | } | ||||
| func echoCommand(ss *openIDSessionData, in InWechatMsg) { | func echoCommand(ss *openIDSessionData, in InWechatMsg) { | ||||
| openID := in.header.FromUserName | openID := in.header.FromUserName | ||||
| processed = true | |||||
| str, err := BuildTextMsg(openID, "default") | str, err := BuildTextMsg(openID, "default") | ||||
| log.Println("echoCommand :" + in.header.MsgType) | log.Println("echoCommand :" + in.header.MsgType) | ||||
| switch in.body.(type) { | switch in.body.(type) { | ||||
| case TextMsg: | case TextMsg: | ||||
| m := in.body.(TextMsg) | m := in.body.(TextMsg) | ||||
| str, err = BuildTextMsg(openID, m.Content+"\n\n关键词 [转接] 将后续信息都转接到 客服 测试版") | str, err = BuildTextMsg(openID, m.Content+"\n\n关键词 [转接] 将后续信息都转接到 客服 测试版") | ||||
| if m.Content == "转接" { | |||||
| processed = false | |||||
| } | |||||
| in.replyXML(str) | |||||
| case PicMsg: | case PicMsg: | ||||
| m := in.body.(PicMsg) | m := in.body.(PicMsg) | ||||
| str = buildPicMsg(openID, m.MediaId) | str = buildPicMsg(openID, m.MediaId) | ||||
| in.replyXML(str) | |||||
| case VoiceMsg: | case VoiceMsg: | ||||
| m := in.body.(VoiceMsg) | m := in.body.(VoiceMsg) | ||||
| str = buildVoiceMsg(openID, m.MediaId) | str = buildVoiceMsg(openID, m.MediaId) | ||||
| in.replyXML(str) | |||||
| kfSendTxt(openID, "翻译结果:"+m.Recognition) | kfSendTxt(openID, "翻译结果:"+m.Recognition) | ||||
| case VideoMsg: | case VideoMsg: | ||||
| m := in.body.(VideoMsg) | m := in.body.(VideoMsg) | ||||
| str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) | str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) | ||||
| in.replyXML(str) | |||||
| case ShortVideoMsg: | case ShortVideoMsg: | ||||
| m := in.body.(ShortVideoMsg) | m := in.body.(ShortVideoMsg) | ||||
| str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) | str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) | ||||
| in.replyXML(str) | |||||
| case LocationMsg: | case LocationMsg: | ||||
| m := in.body.(LocationMsg) | m := in.body.(LocationMsg) | ||||
| mid := location2MediaID(m.Location_X, m.Location_Y) | mid := location2MediaID(m.Location_X, m.Location_Y) | ||||
| //str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) | |||||
| str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) | |||||
| in.replyXML(str) | |||||
| str = buildPicMsg(openID, mid) | str = buildPicMsg(openID, mid) | ||||
| url := location2URL(m.Location_X, m.Location_Y) | url := location2URL(m.Location_X, m.Location_Y) | ||||
| kfSendTxt(openID, url) | kfSendTxt(openID, url) | ||||
| case LinkMsg: | case LinkMsg: | ||||
| m := in.body.(LinkMsg) | m := in.body.(LinkMsg) | ||||
| kfSendTxt(openID, m.Title+m.Description) | |||||
| str, _ = BuildTextMsg(openID, m.Url) | str, _ = BuildTextMsg(openID, m.Url) | ||||
| in.replyXML(str) | |||||
| kfSendTxt(openID, m.Title+m.Description) | |||||
| case EventMsg: | case EventMsg: | ||||
| return echoEvents(openID, in) | |||||
| echoEvents(in) | |||||
| default: | default: | ||||
| str, err = BuildTextMsg(openID, "text message") | str, err = BuildTextMsg(openID, "text message") | ||||
| } | } | ||||
| if err != nil { | if err != nil { | ||||
| log.Println("build response failed") | log.Println("build response failed") | ||||
| processed = false | |||||
| } | } | ||||
| //state is any state that | |||||
| return | return | ||||
| } | } | ||||
| func echoEvents(openID string, in InWechatMsg) (state chatState, processed bool) { | |||||
| processed = true | |||||
| func echoEvents(in InWechatMsg) { | |||||
| openID := in.header.FromUserName | |||||
| str := "" | str := "" | ||||
| m := in.body.(EventMsg) | m := in.body.(EventMsg) | ||||
| log.Println("Event = " + m.Event) | log.Println("Event = " + m.Event) | ||||
| default: | default: | ||||
| str, _ = BuildTextMsg(openID, " unknown event:"+m.Event) | str, _ = BuildTextMsg(openID, " unknown event:"+m.Event) | ||||
| } | } | ||||
| state.response = str | |||||
| in.replyXML(str) | |||||
| return | return | ||||
| } | } | ||||