diff --git a/app/http/controllers/front/payment_controller.go b/app/http/controllers/front/payment_controller.go index 05a0a0c..3c27df8 100644 --- a/app/http/controllers/front/payment_controller.go +++ b/app/http/controllers/front/payment_controller.go @@ -13,6 +13,7 @@ import ( "github.com/go-pay/gopay/alipay" "github.com/go-pay/gopay/wechat/v3" "github.com/qit-team/snow-core/log/logger" + "io/ioutil" "strconv" "net/http" @@ -135,3 +136,56 @@ func AliCallback(c *gin.Context) { c.String(http.StatusOK, "%s", "success") return } + +func BrokerWechatUrl(c *gin.Context) { + url := c.Query("url") + if url == "" { + c.String(400, "url is empty") + return + } + + method := "GET" + client := &http.Client{} + req, err := http.NewRequest(method, url, nil) + if err != nil { + fmt.Println(err) + return + } + req.Header.Add("Referer", "https://cardmallpay.85938.cn") + req.Header.Add("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + req.Header.Add("Accept", "*/*") + req.Header.Add("Host", "wx.tenpay.com") + req.Header.Add("Connection", "keep-alive") + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + // 读取响应体 + body, err := ioutil.ReadAll(res.Body) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + + // 复制响应头部(可选,根据需要选择需要的头部) + for name, values := range res.Header { + // 注意:某些头部(如Content-Length)在转发时可能需要重新计算 + for _, value := range values { + c.Writer.Header().Add(name, value) + } + } + + // 设置状态码 + c.Writer.WriteHeader(res.StatusCode) + + // 写入响应体 + _, err = c.Writer.Write(body) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } +} diff --git a/app/http/routes/route.go b/app/http/routes/route.go index 71562ea..810cd2d 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -62,6 +62,8 @@ func RegisterRoute(router *gin.Engine) { pay.POST("/query", front.QueryOrder) //查询订单 pay.POST("/refund", front.Refund) } + // 测试微信支付唤起 + v1.GET("/brokerWechatUrl", front.BrokerWechatUrl) } router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))