Browse Source

prevent double reply of wechat message

master
Patrick Peng Sun 8 years ago
parent
commit
6f3fa47148
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      wechatMsg.go

+ 13
- 3
wechatMsg.go View File

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() {

Loading…
Cancel
Save