| @@ -1,6 +1,9 @@ | |||
| package main | |||
| import "net/http" | |||
| import ( | |||
| "log" | |||
| "net/http" | |||
| ) | |||
| // | |||
| //InWechatMsg what we received currently from wechat | |||
| @@ -9,9 +12,11 @@ type InWechatMsg struct { | |||
| body interface{} //dynamic type | |||
| req *http.Request | |||
| instantResponse chan string //instance reply channel | |||
| replied bool //whether instant response has been replied | |||
| } | |||
| func (m *InWechatMsg) init() { | |||
| m.replied = false | |||
| m.instantResponse = make(chan string) | |||
| } | |||
| @@ -20,12 +25,17 @@ func (m *InWechatMsg) destroy() { | |||
| } | |||
| func (m *InWechatMsg) replyXML(xml string) { | |||
| m.instantResponse <- xml | |||
| if !m.replied { | |||
| m.replied = true | |||
| m.instantResponse <- xml | |||
| } else { | |||
| log.Println("BUG::doubl reply for wechat message") | |||
| } | |||
| } | |||
| func (m *InWechatMsg) replyText(s string) { | |||
| str, _ := BuildTextMsg(m.header.FromUserName, s) | |||
| m.instantResponse <- str | |||
| m.replyXML(str) | |||
| } | |||
| func (m *InWechatMsg) transfer2KF() { | |||