|
|
|
@@ -7,32 +7,27 @@ import ( |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
const idProcEcho = "Echo" |
|
|
|
|
|
|
|
var procEcho = chatProcedure{ |
|
|
|
echoInit, |
|
|
|
echoClean, |
|
|
|
echoStart, |
|
|
|
echoServe, |
|
|
|
echoSummary, |
|
|
|
echoInto, |
|
|
|
type procEchoDef struct { |
|
|
|
chatProcedureID |
|
|
|
} |
|
|
|
|
|
|
|
func echoInit(ss *openIDSessionData) { |
|
|
|
ss.setProcedure(idProcEcho) |
|
|
|
var procEcho = procEchoDef{} |
|
|
|
|
|
|
|
func (m *procEchoDef) init(ss *openIDSessionData) { |
|
|
|
ss.setProcedure(m.getID()) |
|
|
|
ss.refreshExpire(600) |
|
|
|
} |
|
|
|
|
|
|
|
func echoClean(ss *openIDSessionData) { |
|
|
|
func (m *procEchoDef) clean(ss *openIDSessionData) { |
|
|
|
ss.Procedure = "" |
|
|
|
log.Println(*ss) |
|
|
|
//log.Println(*ss) |
|
|
|
} |
|
|
|
|
|
|
|
func echoStart(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
func (m *procEchoDef) start(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
ss.setKvPair("started at", time.Now().Format("2006/03:04:05")) |
|
|
|
} |
|
|
|
|
|
|
|
func echoServe(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
func (m *procEchoDef) serve(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
stopEcho := false |
|
|
|
if in.header.MsgType == "text" { |
|
|
|
if in.body.(TextMsg).Content == "结束Echo" || in.body.(TextMsg).Content == "结束echo" { |
|
|
|
@@ -47,16 +42,16 @@ func echoServe(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
|
|
|
|
if stopEcho { |
|
|
|
in.replyText("echo 正式结束") |
|
|
|
echoSummary(ss) |
|
|
|
echoClean(ss) |
|
|
|
procEcho.summary(ss) |
|
|
|
procEcho.clean(ss) |
|
|
|
} else { |
|
|
|
ss.refreshExpire(600) |
|
|
|
echoCommand(ss, in) |
|
|
|
procEcho.doCommand(ss, in) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func echoSummary(ss *openIDSessionData) { |
|
|
|
func (m *procEchoDef) summary(ss *openIDSessionData) { |
|
|
|
msg := ss.getVal("started at") |
|
|
|
allmsg := ss.getVal("msg") //may be too long |
|
|
|
if len(allmsg) > 2000 { |
|
|
|
@@ -67,11 +62,11 @@ func echoSummary(ss *openIDSessionData) { |
|
|
|
kfSendTxt(ss.OpenID, msg) |
|
|
|
} |
|
|
|
|
|
|
|
func echoInto(ss *openIDSessionData) { |
|
|
|
func (m *procEchoDef) intro(ss *openIDSessionData) { |
|
|
|
kfSendTxt(ss.OpenID, "10分钟静默之后 Echo将自动结束,\n输入 [结束Echo],或者语音 ‘退出退出', 清除Echo模式") |
|
|
|
} |
|
|
|
|
|
|
|
func echoCommand(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
func (m *procEchoDef) doCommand(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
openID := in.header.FromUserName |
|
|
|
str, err := BuildTextMsg(openID, "default") |
|
|
|
log.Println("echoCommand :" + in.header.MsgType) |
|
|
|
@@ -79,29 +74,29 @@ func echoCommand(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
case TextMsg: |
|
|
|
m := in.body.(TextMsg) |
|
|
|
str, err = BuildTextMsg(openID, m.Content+"\n\n关键词 [转接] 将后续信息都转接到 客服 测试版") |
|
|
|
procEchoRecordMsg(ss, "文字:"+m.Content) |
|
|
|
procEcho.recordMsg(ss, "文字:"+m.Content) |
|
|
|
in.replyXML(str) |
|
|
|
case PicMsg: |
|
|
|
m := in.body.(PicMsg) |
|
|
|
str = buildPicMsg(openID, m.MediaId) |
|
|
|
in.replyXML(str) |
|
|
|
procEchoRecordMsg(ss, "图片:..") |
|
|
|
procEcho.recordMsg(ss, "图片:..") |
|
|
|
case VoiceMsg: |
|
|
|
m := in.body.(VoiceMsg) |
|
|
|
str = buildVoiceMsg(openID, m.MediaId) |
|
|
|
in.replyXML(str) |
|
|
|
procEchoRecordMsg(ss, "音译:"+m.Recognition) |
|
|
|
procEcho.recordMsg(ss, "音译:"+m.Recognition) |
|
|
|
kfSendTxt(openID, "翻译结果:"+m.Recognition) |
|
|
|
case VideoMsg: |
|
|
|
m := in.body.(VideoMsg) |
|
|
|
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) |
|
|
|
in.replyXML(str) |
|
|
|
procEchoRecordMsg(ss, "视频:..") |
|
|
|
procEcho.recordMsg(ss, "视频:..") |
|
|
|
case ShortVideoMsg: |
|
|
|
m := in.body.(ShortVideoMsg) |
|
|
|
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) |
|
|
|
in.replyXML(str) |
|
|
|
procEchoRecordMsg(ss, "小视频:..") |
|
|
|
procEcho.recordMsg(ss, "小视频:..") |
|
|
|
case LocationMsg: |
|
|
|
m := in.body.(LocationMsg) |
|
|
|
mid := location2MediaID(m.Location_X, m.Location_Y) |
|
|
|
@@ -109,15 +104,15 @@ func echoCommand(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
in.replyXML(str) |
|
|
|
url := location2URL(m.Location_X, m.Location_Y) |
|
|
|
kfSendTxt(openID, url+"\n"+fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) |
|
|
|
procEchoRecordMsg(ss, "坐标:..") |
|
|
|
procEcho.recordMsg(ss, "坐标:..") |
|
|
|
case LinkMsg: |
|
|
|
m := in.body.(LinkMsg) |
|
|
|
str, _ = BuildTextMsg(openID, m.Url) |
|
|
|
in.replyXML(str) |
|
|
|
kfSendTxt(openID, m.Title+m.Description) |
|
|
|
procEchoRecordMsg(ss, "链接:"+m.Title) |
|
|
|
procEcho.recordMsg(ss, "链接:"+m.Title) |
|
|
|
case EventMsg: |
|
|
|
echoEvents(ss, in) |
|
|
|
procEcho.doEvents(ss, in) |
|
|
|
default: |
|
|
|
str, err = BuildTextMsg(openID, "text message") |
|
|
|
} |
|
|
|
@@ -128,47 +123,47 @@ func echoCommand(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func echoEvents(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
func (m *procEchoDef) doEvents(ss *openIDSessionData, in InWechatMsg) { |
|
|
|
openID := in.header.FromUserName |
|
|
|
str := "" |
|
|
|
m := in.body.(EventMsg) |
|
|
|
e := in.body.(EventMsg) |
|
|
|
//log.Println("Event = " + m.Event) |
|
|
|
procEchoRecordMsg(ss, "事件:"+m.Event) |
|
|
|
switch m.Event { |
|
|
|
procEcho.recordMsg(ss, "事件:"+e.Event) |
|
|
|
switch e.Event { |
|
|
|
case "LOCATION": |
|
|
|
mid := location2MediaID(m.Latitude, m.Longitude) |
|
|
|
mid := location2MediaID(e.Latitude, e.Longitude) |
|
|
|
str = buildPicMsg(openID, mid) |
|
|
|
case "CLICK": |
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
str, _ = BuildTextMsg(openID, e.EventKey) |
|
|
|
case "subscribe": |
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
str, _ = BuildTextMsg(openID, e.EventKey) |
|
|
|
case "unsubscribe": |
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
str, _ = BuildTextMsg(openID, e.EventKey) |
|
|
|
case "SCAN": |
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
str, _ = BuildTextMsg(openID, e.EventKey) |
|
|
|
case "VIEW": |
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
str, _ = BuildTextMsg(openID, e.EventKey) |
|
|
|
case "kf_create_session": |
|
|
|
kfSendTxt(openID, m.KfAccount) |
|
|
|
kfSendTxt(openID, e.KfAccount) |
|
|
|
//str, _ = BuildTextMsg(openID, m.KfAccount) // response msg is ignored by wechat |
|
|
|
case "kf_close_session": |
|
|
|
kfSendTxt(openID, m.KfAccount+"\n close type ="+m.CloseType) |
|
|
|
kfSendTxt(openID, e.KfAccount+"\n close type ="+e.CloseType) |
|
|
|
//str, _ = BuildTextMsg(openID, m.KfAccount+"\n close type ="+m.CloseType) //response msg is ignored by wechat |
|
|
|
case "scancode_waitmsg": |
|
|
|
log.Println(m.ScanCodeInfo.ScanResult) |
|
|
|
log.Println(m.ScanCodeInfo.ScanType) |
|
|
|
msg := fmt.Sprintf("ScanResult =%s, ScanType=%s", m.ScanCodeInfo.ScanResult, m.ScanCodeInfo.ScanType) |
|
|
|
log.Println(e.ScanCodeInfo.ScanResult) |
|
|
|
log.Println(e.ScanCodeInfo.ScanType) |
|
|
|
msg := fmt.Sprintf("ScanResult =%s, ScanType=%s", e.ScanCodeInfo.ScanResult, e.ScanCodeInfo.ScanType) |
|
|
|
kfSendTxt(openID, msg) |
|
|
|
case "pic_photo_or_album": |
|
|
|
msg := fmt.Sprintf("Count = %d ", m.SendPicsInfo.Count) |
|
|
|
log.Println(m.SendPicsInfo.Count) |
|
|
|
for _, v := range m.SendPicsInfo.PicList.Item { |
|
|
|
msg := fmt.Sprintf("Count = %d ", e.SendPicsInfo.Count) |
|
|
|
log.Println(e.SendPicsInfo.Count) |
|
|
|
for _, v := range e.SendPicsInfo.PicList.Item { |
|
|
|
log.Println(v.PicMd5Sum) |
|
|
|
kfSendTxt(openID, v.PicMd5Sum) |
|
|
|
} |
|
|
|
kfSendTxt(openID, msg) |
|
|
|
default: |
|
|
|
str, _ = BuildTextMsg(openID, " unknown event:"+m.Event) |
|
|
|
str, _ = BuildTextMsg(openID, " unknown event:"+e.Event) |
|
|
|
} |
|
|
|
in.replyXML(str) |
|
|
|
return |
|
|
|
@@ -188,7 +183,7 @@ func location2URL(lat, long float64) (url string) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func procEchoRecordMsg(ss *openIDSessionData, newmsg string) { |
|
|
|
func (m *procEchoDef) recordMsg(ss *openIDSessionData, newmsg string) { |
|
|
|
msg := ss.getVal("msg") |
|
|
|
msg = msg + newmsg + "\n" |
|
|
|
ss.setKvPair("msg", msg) |