补齐相关日志日志
This commit is contained in:
@@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/dto"
|
||||
@@ -158,6 +159,8 @@ func (h *OrderHandler) XPayVerify(c *gin.Context) {
|
||||
plain, err := wechat.DecodeEchoStr(echostr, timestamp, nonce, msgSignature)
|
||||
if err != nil {
|
||||
// 兼容模式:echostr 可能仍是明文(msg_signature 对明文计算),原样回显。
|
||||
slog.WarnContext(c.Request.Context(), "xpay verify: decode echo str failed, fallback to plain echo",
|
||||
"remote_addr", c.Request.RemoteAddr, "error", err)
|
||||
c.String(http.StatusOK, echostr)
|
||||
return
|
||||
}
|
||||
@@ -169,6 +172,7 @@ func (h *OrderHandler) XPayVerify(c *gin.Context) {
|
||||
c.String(http.StatusOK, echostr)
|
||||
return
|
||||
}
|
||||
slog.WarnContext(c.Request.Context(), "xpay verify: invalid signature", "remote_addr", c.Request.RemoteAddr)
|
||||
c.String(http.StatusUnauthorized, "invalid signature")
|
||||
}
|
||||
|
||||
@@ -177,6 +181,8 @@ func (h *OrderHandler) XPayVerify(c *gin.Context) {
|
||||
func (h *OrderHandler) XPayNotify(c *gin.Context) {
|
||||
raw, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
slog.ErrorContext(c.Request.Context(), "xpay notify: read request body failed",
|
||||
"remote_addr", c.Request.RemoteAddr, "error", err)
|
||||
writeXPayNotifyReply(c, false, false)
|
||||
return
|
||||
}
|
||||
@@ -187,6 +193,8 @@ func (h *OrderHandler) XPayNotify(c *gin.Context) {
|
||||
plain, derr := wechat.DecodeEncryptedNotify(raw, c.Query("timestamp"), c.Query("nonce"), c.Query("msg_signature"))
|
||||
if derr != nil {
|
||||
// 验签/解密失败:回失败应答触发微信重试(fail-closed)。
|
||||
slog.ErrorContext(c.Request.Context(), "xpay notify: verify or decrypt failed",
|
||||
"remote_addr", c.Request.RemoteAddr, "error", derr)
|
||||
writeXPayNotifyReply(c, true, false)
|
||||
return
|
||||
}
|
||||
@@ -210,6 +218,8 @@ func encryptIfNeeded(c *gin.Context, plain []byte, encrypted bool) []byte {
|
||||
}
|
||||
out, err := wechat.EncodeEncryptedNotify(plain, c.Query("nonce"))
|
||||
if err != nil {
|
||||
slog.WarnContext(c.Request.Context(), "xpay notify: encrypt reply failed, fallback to plain",
|
||||
"remote_addr", c.Request.RemoteAddr, "error", err)
|
||||
return plain
|
||||
}
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user