| package main | package main | ||||
| import "net/http" | |||||
| import ( | |||||
| "log" | |||||
| "net/http" | |||||
| ) | |||||
| // | // | ||||
| //InWechatMsg what we received currently from wechat | //InWechatMsg what we received currently from wechat | ||||
| body interface{} //dynamic type | body interface{} //dynamic type | ||||
| req *http.Request | req *http.Request | ||||
| instantResponse chan string //instance reply channel | instantResponse chan string //instance reply channel | ||||
| replied bool //whether instant response has been replied | |||||
| } | } | ||||
| func (m *InWechatMsg) init() { | func (m *InWechatMsg) init() { | ||||
| m.replied = false | |||||
| m.instantResponse = make(chan string) | m.instantResponse = make(chan string) | ||||
| } | } | ||||
| } | } | ||||
| func (m *InWechatMsg) replyXML(xml string) { | 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) { | func (m *InWechatMsg) replyText(s string) { | ||||
| str, _ := BuildTextMsg(m.header.FromUserName, s) | str, _ := BuildTextMsg(m.header.FromUserName, s) | ||||
| m.instantResponse <- str | |||||
| m.replyXML(str) | |||||
| } | } | ||||
| func (m *InWechatMsg) transfer2KF() { | func (m *InWechatMsg) transfer2KF() { |