Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没大神给个gin调用的例子呢 #261

Open
akuan opened this issue Jul 19, 2019 · 2 comments
Open

有没大神给个gin调用的例子呢 #261

akuan opened this issue Jul 19, 2019 · 2 comments

Comments

@akuan
Copy link

akuan commented Jul 19, 2019

gin的路由函数是这样的

func StoreExample(c *gin.Context) {
}

怎么和 msgServer.ServeHTTP结合起来呢? msgServer.ServeHTTP是必须调用的方法吗?

// wxCallbackHandler 是处理回调请求的 http handler.
//  1. 不同的 web 框架有不同的实现
//  2. 一般一个 handler 处理一个公众号的回调请求(当然也可以处理多个, 这里我只处理一个)
func wxCallbackHandler(w http.ResponseWriter, r *http.Request) {
    msgServer.ServeHTTP(w, r, nil)
}
@dreamlu
Copy link

dreamlu commented Sep 5, 2019

// update 2019/09/04
wxs.GET("/call", wx.WxCall)
wxs.POST("/call", wx.WxCall)

func WxCall(c *gin.Context) {
r := c.Request
w := c.Writer
msgServer.ServeHTTP(w, r, nil)
}
// 文档中token验证是GET请求, 事件、文本、扫码等接收却是POST请求
// 放同一个入口超奇怪
// 或者更好的方式?请告知

@json7
Copy link

json7 commented Sep 29, 2020

// update 2019/09/04
wxs.GET("/call", wx.WxCall)
wxs.POST("/call", wx.WxCall)

func WxCall(c *gin.Context) {
r := c.Request
w := c.Writer
msgServer.ServeHTTP(w, r, nil)
}
// 文档中token验证是GET请求, 事件、文本、扫码等接收却是POST请求
// 放同一个入口超奇怪
// 或者更好的方式?请告知
很多人都是这么实现的,并且官方也是这么干的. 没有让你填两个api,就填一个.用post和get区分.我是自己拆开的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants