|
- package main
-
- import (
- "log"
- "net/http"
- )
-
- //
- //InWechatMsg what we received currently from wechat
- type InWechatMsg struct {
- header CommonHeader
- 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)
- }
-
- func (m *InWechatMsg) destroy() {
- close(m.instantResponse)
- }
-
- func (m *InWechatMsg) replyXML(xml string) {
- if !m.replied {
- m.replied = true
- m.instantResponse <- xml
- } else {
- d := decryptToXML(xml)
- log.Println("BUG::double reply for wechat message\n" + d + "\n")
- }
- }
-
- func (m *InWechatMsg) replyText(s string) {
- if s == "" && m.replied == true {
- return //skip safeguard empty message
- }
- str, _ := BuildTextMsg(m.header.FromUserName, s)
- m.replyXML(str)
- }
-
- func (m *InWechatMsg) transfer2KF() {
- str, _ := BuildKFTransferAnyOneMsg(m.header.FromUserName)
- m.replyXML(str)
- }
-
- func (m *InWechatMsg) transfer2SpecificKF(kf string) {
- str := buildKfForwardMsg(m.header.FromUserName, kf)
- m.replyXML(str)
- }
|