MCPcopy
hub / github.com/silenceper/wechat / Serve

Method Serve

officialaccount/server/server.go:60–86  ·  view source on GitHub ↗

Serve 处理微信的请求消息

()

Source from the content-addressed store, hash-verified

58
59// Serve 处理微信的请求消息
60func (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 校验请求是否合法
89func (srv *Server) Validate() bool {

Callers

nothing calls this directly

Calls 6

ValidateMethod · 0.95
GetQueryMethod · 0.95
StringMethod · 0.95
handleRequestMethod · 0.95
buildResponseMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected