You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 satır
1.1KB

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. )
  6. //
  7. //InWechatMsg what we received currently from wechat
  8. type InWechatMsg struct {
  9. header CommonHeader
  10. body interface{} //dynamic type
  11. req *http.Request
  12. instantResponse chan string //instance reply channel
  13. replied bool //whether instant response has been replied
  14. }
  15. func (m *InWechatMsg) init() {
  16. m.replied = false
  17. m.instantResponse = make(chan string)
  18. }
  19. func (m *InWechatMsg) destroy() {
  20. close(m.instantResponse)
  21. }
  22. func (m *InWechatMsg) replyXML(xml string) {
  23. if !m.replied {
  24. m.replied = true
  25. m.instantResponse <- xml
  26. } else {
  27. d := decryptToXML(xml)
  28. log.Println("BUG::double reply for wechat message\n" + d + "\n")
  29. }
  30. }
  31. func (m *InWechatMsg) replyText(s string) {
  32. if s == "" && m.replied == true {
  33. return //skip safeguard empty message
  34. }
  35. str, _ := BuildTextMsg(m.header.FromUserName, s)
  36. m.replyXML(str)
  37. }
  38. func (m *InWechatMsg) transfer2KF() {
  39. str, _ := BuildKFTransferAnyOneMsg(m.header.FromUserName)
  40. m.replyXML(str)
  41. }
  42. func (m *InWechatMsg) transfer2SpecificKF(kf string) {
  43. str := buildKfForwardMsg(m.header.FromUserName, kf)
  44. m.replyXML(str)
  45. }