Merge remote-tracking branch 'origin/dev/dev1.0' into dev/dev1.0
This commit is contained in:
		
						commit
						86af800c7c
					
				| 
						 | 
					@ -44,11 +44,16 @@ func Refund(c *gin.Context) {
 | 
				
			||||||
	c.Set("OutTradeNo", req.OutTradeNo)
 | 
						c.Set("OutTradeNo", req.OutTradeNo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
 | 
						appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
 | 
				
			||||||
	refund, errCode := thirdpay.ThirdPayRefund(c.Request.Context(), req, appCheckInfo, c.ClientIP())
 | 
						check, errCode := thirdpay.ThirdPayRefundCheck(c.Request.Context(), req, appCheckInfo, c.ClientIP())
 | 
				
			||||||
	if errCode != errorcode.Success {
 | 
						if errCode != errorcode.Success {
 | 
				
			||||||
		controllers.ApiRes(c, nil, errCode)
 | 
							controllers.ApiRes(c, nil, errCode)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						refund, errCode := thirdpay.ThirdPayRefund(check)
 | 
				
			||||||
 | 
						if errCode != errorcode.Success {
 | 
				
			||||||
 | 
							controllers.ApiRes(c, nil, errCode, refund.ThirdMsg)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	data := thirdpay.NewOrdersResp(refund.Order)
 | 
						data := thirdpay.NewOrdersResp(refund.Order)
 | 
				
			||||||
	var res front.ApiResponse
 | 
						var res front.ApiResponse
 | 
				
			||||||
	res.Order = data
 | 
						res.Order = data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ import (
 | 
				
			||||||
	"github.com/go-pay/gopay/alipay"
 | 
						"github.com/go-pay/gopay/alipay"
 | 
				
			||||||
	"github.com/go-pay/gopay/wechat/v3"
 | 
						"github.com/go-pay/gopay/wechat/v3"
 | 
				
			||||||
	"github.com/qit-team/snow-core/log/logger"
 | 
						"github.com/qit-team/snow-core/log/logger"
 | 
				
			||||||
 | 
						"io/ioutil"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
| 
						 | 
					@ -135,3 +136,56 @@ func AliCallback(c *gin.Context) {
 | 
				
			||||||
	c.String(http.StatusOK, "%s", "success")
 | 
						c.String(http.StatusOK, "%s", "success")
 | 
				
			||||||
	return
 | 
						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
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +62,8 @@ func RegisterRoute(router *gin.Engine) {
 | 
				
			||||||
			pay.POST("/query", front.QueryOrder) //查询订单
 | 
								pay.POST("/query", front.QueryOrder) //查询订单
 | 
				
			||||||
			pay.POST("/refund", front.Refund)
 | 
								pay.POST("/refund", front.Refund)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// 测试微信支付唤起
 | 
				
			||||||
 | 
							v1.GET("/brokerWechatUrl", front.BrokerWechatUrl)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
 | 
						router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,21 +46,28 @@ func ThirdPayInfoCheck(ctx context.Context, payReq *front.PayReqs, appCheck *ser
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ThirdPayRefund(ctx context.Context, refundReq *front.RefundReqs, appCheck *services.AppCheck, ip string) (refund *thirdpay.Pay, errorCode int) {
 | 
					func ThirdPayRefundCheck(ctx context.Context, refundReq *front.RefundReqs, appCheck *services.AppCheck, ip string) (check *thirdpay.PayCheck, errorCode int) {
 | 
				
			||||||
	var req types.Reqs
 | 
						var req types.Reqs
 | 
				
			||||||
	copier.Copy(&req, refundReq)
 | 
						copier.Copy(&req, refundReq)
 | 
				
			||||||
	check := thirdpay.NewPayCheck(&ctx, &req, appCheck, ip)
 | 
						check = thirdpay.NewPayCheck(&ctx, &req, appCheck, ip)
 | 
				
			||||||
	// 校验表单
 | 
						// 校验表单
 | 
				
			||||||
	check.CheckPayInfo()
 | 
						check.CheckPayInfo()
 | 
				
			||||||
	if check.CheckCode != errorcode.Success {
 | 
						return check, check.CheckCode
 | 
				
			||||||
		return nil, check.CheckCode
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
	check.CheckOrderRefund()
 | 
					
 | 
				
			||||||
	if check.CheckCode != errorcode.Success {
 | 
					func ThirdPayRefund(check *thirdpay.PayCheck) (refund *thirdpay.Pay, errorCode int) {
 | 
				
			||||||
		return nil, check.CheckCode
 | 
					
 | 
				
			||||||
 | 
						refund = thirdpay.NewPayWithPayCheck(check)
 | 
				
			||||||
 | 
						if refund.CheckRefundOrder() {
 | 
				
			||||||
 | 
							refund.CreateOrder(common.ORDER_TYPE_REFUND)
 | 
				
			||||||
 | 
							if refund.PayCode != errorcode.Success {
 | 
				
			||||||
 | 
								return refund, refund.PayCode
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	refund, errorCode = ThirdRefund(check)
 | 
						}
 | 
				
			||||||
	return
 | 
					
 | 
				
			||||||
 | 
						refund.Refund()
 | 
				
			||||||
 | 
						return refund, refund.PayCode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
 | 
					func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
 | 
				
			||||||
| 
						 | 
					@ -76,16 +83,3 @@ func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func ThirdRefund(check *thirdpay.PayCheck) (refund *thirdpay.Pay, errCode int) {
 | 
					 | 
				
			||||||
	refund = thirdpay.NewPayWithPayCheck(check)
 | 
					 | 
				
			||||||
	if refund.CheckRefundOrder() {
 | 
					 | 
				
			||||||
		refund.CreateOrder(common.ORDER_TYPE_REFUND)
 | 
					 | 
				
			||||||
		if refund.PayCode != errorcode.Success {
 | 
					 | 
				
			||||||
			return refund, refund.PayCode
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	refund.Refund()
 | 
					 | 
				
			||||||
	return refund, refund.PayCode
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue