回调log记录
This commit is contained in:
parent
62d050c02f
commit
d6bf4dd952
|
@ -6,6 +6,7 @@ import (
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/services"
|
"PaymentCenter/app/services"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/third/paymentService"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -13,6 +14,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"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -20,7 +22,7 @@ import (
|
||||||
|
|
||||||
// WxCallback 微信支付回调
|
// WxCallback 微信支付回调
|
||||||
func WxCallback(c *gin.Context) {
|
func WxCallback(c *gin.Context) {
|
||||||
logger.Info(c, "WxCallback-回调数据", c.Request)
|
saveLogger(c, "wx")
|
||||||
payChannelId := c.Param("payChannelId")
|
payChannelId := c.Param("payChannelId")
|
||||||
logger.Info(c, "WxCallback-回调数据payChannelId", payChannelId)
|
logger.Info(c, "WxCallback-回调数据payChannelId", payChannelId)
|
||||||
if payChannelId == "" {
|
if payChannelId == "" {
|
||||||
|
@ -80,7 +82,7 @@ func WxCallback(c *gin.Context) {
|
||||||
|
|
||||||
// AliCallback 支付宝支付回调
|
// AliCallback 支付宝支付回调
|
||||||
func AliCallback(c *gin.Context) {
|
func AliCallback(c *gin.Context) {
|
||||||
logger.Info(c, "AliCallback-回调数据", c.Request)
|
saveLogger(c, "ALI")
|
||||||
payChannelId := c.Param("payChannelId")
|
payChannelId := c.Param("payChannelId")
|
||||||
logger.Info(c, "AliCallback-回调数据APPID", payChannelId)
|
logger.Info(c, "AliCallback-回调数据APPID", payChannelId)
|
||||||
if payChannelId == "" {
|
if payChannelId == "" {
|
||||||
|
@ -135,3 +137,27 @@ func AliCallback(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "%s", "success")
|
c.String(http.StatusOK, "%s", "success")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func saveLogger(c *gin.Context, payType string) {
|
||||||
|
// 保存请求的方法和URL
|
||||||
|
method := c.Request.Method
|
||||||
|
url := c.Request.URL.String()
|
||||||
|
|
||||||
|
// 保存请求头
|
||||||
|
headers := make(map[string]string)
|
||||||
|
for k, v := range c.Request.Header {
|
||||||
|
headers[k] = v[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存请求体
|
||||||
|
var bodyBytes []byte
|
||||||
|
if c.Request.Body != nil {
|
||||||
|
bodyBytes, _ = io.ReadAll(c.Request.Body)
|
||||||
|
}
|
||||||
|
// 由于 io.ReadAll 会将 body 读完,所以需要重新赋值
|
||||||
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
|
||||||
|
// 使用 logger 记录请求信息
|
||||||
|
logger.Info(c, "支付回调"+payType, fmt.Sprintf("接受的参数:method: %s , url: %s , headers: %s , body: %s", method, url, headers, string(bodyBytes)))
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue