Serve 处理微信的请求消息
()
| 58 | |
| 59 | // Serve 处理微信的请求消息 |
| 60 | func (srv *Server) Serve() error { |
| 61 | if !srv.Validate() { |
| 62 | log.Error("Validate Signature Failed.") |
| 63 | return fmt.Errorf("请求校验失败") |
| 64 | } |
| 65 | |
| 66 | echostr, exists := srv.GetQuery("echostr") |
| 67 | if exists { |
| 68 | srv.String(echostr) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | response, err := srv.handleRequest() |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | // 非安全模式下,请求处理方法返回为 nil 则直接回复 success 给微信服务器 |
| 77 | if response == nil && !srv.isSafeMode { |
| 78 | srv.String("success") |
| 79 | return nil |
| 80 | } |
| 81 | |
| 82 | // debug print request msg |
| 83 | log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg)) |
| 84 | |
| 85 | return srv.buildResponse(response) |
| 86 | } |
| 87 | |
| 88 | // Validate 校验请求是否合法 |
| 89 | func (srv *Server) Validate() bool { |
nothing calls this directly
no test coverage detected