Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

53 lines
1.3KB

  1. package main
  2. import (
  3. "os"
  4. )
  5. type chatProcedureID struct {
  6. chatprocID string
  7. }
  8. func (m *chatProcedureID) setID(id string) {
  9. m.chatprocID = id
  10. }
  11. func (m *chatProcedureID) getID() string {
  12. return m.chatprocID
  13. }
  14. // a description of
  15. type chatProcedure interface {
  16. setID(id string) //set Procedure ID
  17. getID() (id string) //get Proecdure ID
  18. init(*openIDSessionData) //house keeping
  19. clean(*openIDSessionData) //house keeping
  20. start(*openIDSessionData, *InWechatMsg) //for first message
  21. serve(*openIDSessionData, *InWechatMsg) bool //for all subsequent message
  22. summary(*openIDSessionData) //after all message has been done
  23. intro(*openIDSessionData, *InWechatMsg) //initial text/video/voice introduction
  24. }
  25. //AllProc all procedure that we implemented
  26. var AllProc = map[string]chatProcedure{}
  27. func initAllProc() {
  28. //registerProc("Dummy", &procDummy)
  29. registerProc("Echo", &procEcho)
  30. registerProc("用户信息", &procGetBasicUserInfo)
  31. registerProc("搜索校友", &procSearchMember)
  32. }
  33. func registerProc(id string, proc chatProcedure) {
  34. AllProc[id] = proc
  35. proc.setID(id)
  36. }
  37. func getProcedurePath(openID, ProcedureName string) (path string) {
  38. path = procedureDir + string(os.PathSeparator) + ProcedureName + string(os.PathSeparator) + openID + ".json"
  39. ensurePathExist(path)
  40. return
  41. }