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

GET不响应 #61

Open
JiajunDou opened this issue Sep 19, 2021 · 3 comments
Open

GET不响应 #61

JiajunDou opened this issue Sep 19, 2021 · 3 comments

Comments

@JiajunDou
Copy link

package main

import (
	"fmt"
	"net/http"

	"github.com/medivhzhan/weapp/v3/server"
)

func main() {

	http.HandleFunc("/sub", func(w http.ResponseWriter, r *http.Request) {
		srv, err := server.NewServer("appid", "", "", "mchID", "apiKey", false, nil)
		if err != nil {
			fmt.Printf("init server error: %s", err)
		}

		// 当用户触发订阅消息弹框后
		srv.OnSubscribeMsgPopup(func(msg *server.SubscribeMsgPopupEvent) {

			// Do something cool ...

		})

		// 当用户通过设置界面改变订阅消息事件内容
		srv.OnSubscribeMsgChange(func(msg *server.SubscribeMsgChangeEvent) {
			// Do something cool ...

		})

		if err := srv.Serve(w, r); err != nil {
			fmt.Println(r)
			return
		}
	})

	http.ListenAndServe(":8082", nil)
}
@JiajunDou
Copy link
Author

http.HandleFunc("/wechat/notify", func(w http.ResponseWriter, r *http.Request) {
		srv, err := server.NewServer("appid", "token", "aesKey", "mchID", "apiKey", false, nil)
		if err != nil {
			//lof.Fatalf("init server error: %s", err)
		}

		// 当用户触发订阅消息弹框后
		srv.OnSubscribeMsgPopup(func(msg *server.SubscribeMsgPopupEvent) {

			// Do something cool ...
			//return nil
		})

		// 当用户通过设置界面改变订阅消息事件内容
		srv.OnSubscribeMsgChange(func(msg *server.SubscribeMsgChangeEvent) {
			// Do something cool ...
			//return nil
		})

		if err := srv.Serve(w, r); err != nil {
			// 处理微信返回错误信息
			return
		}
		fmt.Println(w)
		fmt.Println(r.URL.Query())
	})
	http.ListenAndServe(":8083", nil)

GET signature=74fa2420b718af62bd92e3f84a32ffa09127027c&timestamp=1&nonce=1&echostr=1
伪造一段GET无响应

@royalrick
Copy link
Owner

如果开启服务器校验,那么GET请求会返回 query 中的 echostr。
否则不会返回任何消息。

@JiajunDou
Copy link
Author

所以NewServer里面倒数第二个要把false改成true 时间很紧 读代码真心累

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

2 participants