package handle import ( "WechatGateWay/global" "log" "net/http" ) func handleVerify(w http.ResponseWriter, r *http.Request) { msgSignature := r.URL.Query().Get("msg_signature") timestamp := r.URL.Query().Get("timestamp") nonce := r.URL.Query().Get("nonce") echoStr := r.URL.Query().Get("echostr") // 合法性验证 echoStrBytes, err := global.WxCrypt.VerifyURL(msgSignature, timestamp, nonce, echoStr) if err != nil { log.Println("验证失败", err.ErrMsg) } else { log.Println("验证成功", string(echoStrBytes)) // 需要返回才能通过验证 _, err := w.Write(echoStrBytes) if err != nil { log.Println("返回验证结果失败", err.Error()) } } }