Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 line
1.8KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. )
  6. func serveCommand(openID string, in InWechatMsg) (state chatState, processed bool) {
  7. log.Println("process command")
  8. return echoCommand(openID, in)
  9. }
  10. func echoCommand(openID string, in InWechatMsg) (state chatState, processed bool) {
  11. processed = true
  12. str, err := BuildTextMsg(openID, "default")
  13. log.Println(in.header.MsgType)
  14. switch in.body.(type) {
  15. case TextMsg:
  16. m := in.body.(TextMsg)
  17. str, err = BuildTextMsg(openID, m.Content)
  18. case PicMsg:
  19. m := in.body.(PicMsg)
  20. str = buildPicMsg(openID, m.MediaId)
  21. case VoiceMsg:
  22. m := in.body.(VoiceMsg)
  23. str = buildVoiceMsg(openID, m.MediaId)
  24. kfSendTxt(openID, "翻译结果:"+m.Recognition)
  25. case VideoMsg:
  26. m := in.body.(VideoMsg)
  27. str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId)
  28. case ShortVideoMsg:
  29. m := in.body.(ShortVideoMsg)
  30. str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId)
  31. case LocationMsg:
  32. m := in.body.(LocationMsg)
  33. str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale))
  34. case EventMsg:
  35. m := in.body.(EventMsg)
  36. log.Println(m)
  37. url := fmt.Sprintf("https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&markers=color:red|label:S|%f,%f&zoom=12&size=414x736", m.Latitude, m.Longitude, m.Latitude, m.Longitude)
  38. log.Println(url)
  39. file, _, _ := saveURL(url)
  40. str = buildUploadPicMsg(openID, file)
  41. //str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scal =%f", m.Longitude, m.Latitude, m.Precision))
  42. default:
  43. str, err = BuildTextMsg(openID, "text message")
  44. }
  45. state.OpenID = openID
  46. state.Procedure = ""
  47. state.response = str
  48. log.Println(str)
  49. if err != nil {
  50. log.Println("build response failed")
  51. processed = false
  52. }
  53. //state is any state that
  54. return
  55. }