Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

52 lines
1.2KB

  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) //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. }
  32. func registerProc(id string, proc chatProcedure) {
  33. AllProc[id] = proc
  34. proc.setID(id)
  35. }
  36. func getProcedurePath(openID, ProcedureName string) (path string) {
  37. path = procedureDir + string(os.PathSeparator) + ProcedureName + string(os.PathSeparator) + openID + ".json"
  38. ensurePathExist(path)
  39. return
  40. }