From 22ef786d2e1edc1ef6176ebc360d3eecf428e970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Sat, 8 Mar 2025 16:04:30 +0800 Subject: [PATCH] cmb --- internal/pkg/mq_http/mq_http_test.go | 22 ++++++++++++++++++++-- internal/server/wechat_notify_consumer.go | 2 +- internal/service/wechat_notify_consume.go | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/internal/pkg/mq_http/mq_http_test.go b/internal/pkg/mq_http/mq_http_test.go index 69c4189..c3690b9 100644 --- a/internal/pkg/mq_http/mq_http_test.go +++ b/internal/pkg/mq_http/mq_http_test.go @@ -1,13 +1,31 @@ package mq_http -import "testing" +import ( + "encoding/json" + "testing" + "voucher/internal/biz/bo" +) func Test_WechatNotifyProducer(t *testing.T) { - bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}` + bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` err := wechatNotifyProducer(bodyStr) if err != nil { t.Errorf("入队失败 error = %v", err) return } } + +func Test_WechatVoucherNotifyData(t *testing.T) { + + bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` + + var x *bo.WechatVoucherNotifyBo + + if err := json.Unmarshal([]byte(bodyStr), &x); err != nil { + t.Error(err) + return + } + + t.Log(x) +} diff --git a/internal/server/wechat_notify_consumer.go b/internal/server/wechat_notify_consumer.go index 19ad860..dd19e32 100644 --- a/internal/server/wechat_notify_consumer.go +++ b/internal/server/wechat_notify_consumer.go @@ -80,7 +80,7 @@ func (w *WechatNotifyConsumer) consumeMessages(ctx context.Context, mqConsumer m log.Warnf("接收消息成功 wechat notify messageTag:%s, message: %s", v.MessageTag, v.MessageBody) if err := w.voucherService.WechatNotifyConsumer(ctx, v.MessageTag, v.MessageBody); err != nil { - log.Errorf("wechat notify messageTag:%s, message: %s, err:%+v", v.MessageTag, v.MessageBody, err) + log.Errorf("wechat notify messageTag:%s, err:%+v", v.MessageTag, err) } } diff --git a/internal/service/wechat_notify_consume.go b/internal/service/wechat_notify_consume.go index 7e2ba9e..6c161ae 100644 --- a/internal/service/wechat_notify_consume.go +++ b/internal/service/wechat_notify_consume.go @@ -12,7 +12,7 @@ func (j *VoucherService) WechatNotifyConsumer(ctx context.Context, tag, msg stri var x *bo.WechatVoucherNotifyBo - if err := json.Unmarshal([]byte(msg), x); err != nil { + if err := json.Unmarshal([]byte(msg), &x); err != nil { return fmt.Errorf("consume msg json.Unmarshal error:%s", err.Error()) }