From 43bf445f8b6dddb44116be5d29fa35e04c153a32 Mon Sep 17 00:00:00 2001 From: ziming Date: Thu, 11 Dec 2025 18:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=AC=94=E7=AB=8B=E5=87=8F=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/bo/wechat_notify_bo.go | 28 ++++++++++++++++++++-------- internal/service/qixing.go | 5 +++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/internal/biz/bo/wechat_notify_bo.go b/internal/biz/bo/wechat_notify_bo.go index b8238b8..56364d9 100644 --- a/internal/biz/bo/wechat_notify_bo.go +++ b/internal/biz/bo/wechat_notify_bo.go @@ -3,21 +3,22 @@ package bo import ( "encoding/json" "fmt" + "github.com/go-playground/validator/v10" "time" "voucher/internal/biz/vo" ) // ConsumeInformation 定义消费信息结构体 type ConsumeInformation struct { - ConsumeTime time.Time `json:"consume_time"` // 核销时间 - ConsumeMchid string `json:"consume_mchid"` // 核销商户号 - TransactionID string `json:"transaction_id"` // 微信支付交易单号 - ConsumeAmount int `json:"consume_amount"` // 核销金额(单位:分) + ConsumeTime time.Time `json:"consume_time" validate:"required"` // 核销时间 + ConsumeMchid string `json:"consume_mchid"` // 核销商户号 + TransactionID string `json:"transaction_id" validate:"required"` // 微信支付交易单号 + ConsumeAmount int `json:"consume_amount" validate:"required"` // 核销金额(单位:分) } // PlainText 定义明文数据结构体 type PlainText struct { - StockCreatorMchid string `json:"stock_creator_mchid"` + StockCreatorMchid string `json:"stock_creator_mchid" validate:"required"` StockID string `json:"stock_id"` CouponID string `json:"coupon_id"` CouponName string `json:"coupon_name"` @@ -32,14 +33,14 @@ type PlainText struct { } type WechatVoucherNotifyBo struct { - ID string `json:"id"` + ID string `json:"id" validate:"required"` CreateTime string `json:"create_time"` ResourceType string `json:"resource_type"` - EventType string `json:"event_type"` + EventType string `json:"event_type" validate:"required"` Summary string `json:"summary"` OriginalType string `json:"original_type"` AssociatedData string `json:"associated_data"` - PlainText PlainText `json:"plain_text"` + PlainText PlainText `json:"plain_text" validate:"required"` } func (d *WechatVoucherNotifyBo) Str() (string, error) { @@ -51,3 +52,14 @@ func (d *WechatVoucherNotifyBo) Str() (string, error) { return string(b), nil } + +func (c *WechatVoucherNotifyBo) Validate() error { + + if err := validator.New().Struct(c); err != nil { + for _, err = range err.(validator.ValidationErrors) { + return err + } + } + + return nil +} diff --git a/internal/service/qixing.go b/internal/service/qixing.go index 4518be1..a302e53 100644 --- a/internal/service/qixing.go +++ b/internal/service/qixing.go @@ -69,6 +69,11 @@ func (srv *TripartiteService) QiXingNotify(ctx http.Context) error { return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal wxNotifyData error: %v", err)) } + if err = wxNotifyData.Validate(); err != nil { + log.Errorf("qixing notify wxNotifyData validate err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes)) + return srv.ResponseErr(ctx, fmt.Sprintf("validate wxNotifyData error: %v", err)) + } + err = srv.multiBiz.Notify(ctx, "qixing_"+wxNotifyData.PlainText.StockCreatorMchid, wxNotifyData) if err != nil { log.Errorf("qixing notify run err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))