From 15fb9a1da5343ac3c14fdc39e36d30210f8169de Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Mon, 15 Dec 2025 18:02:06 -0800 Subject: [PATCH] =?UTF-8?q?fix(iap/apple):=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8F=B7=E5=9B=9E=E9=80=80=E9=80=BB=E8=BE=91=E4=BB=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=AE=A2=E9=98=85=E4=BF=A1=E6=81=AF=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当请求中缺少duration或subscribeId时,优先从order_no查找订单信息作为回退方案,避免直接返回错误 --- .../iap/apple/attachTransactionLogic.go | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/logic/public/iap/apple/attachTransactionLogic.go b/internal/logic/public/iap/apple/attachTransactionLogic.go index 614df2c..6d61e5e 100644 --- a/internal/logic/public/iap/apple/attachTransactionLogic.go +++ b/internal/logic/public/iap/apple/attachTransactionLogic.go @@ -59,12 +59,26 @@ func (l *AttachTransactionLogic) Attach(req *types.AttachAppleTransactionRequest tier = m.Tier subscribeId = m.SubscribeId } else { - if req.DurationDays <= 0 || req.SubscribeId <= 0 { + // fallback from order_no if provided + if req.OrderNo != "" { + if ord, e := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo); e == nil && ord != nil && ord.Id != 0 { + duration = ord.Quantity + subscribeId = ord.SubscribeId + } + } + // final fallback: use request fields + if duration <= 0 { + duration = req.DurationDays + } + if tier == "" { + tier = req.Tier + } + if subscribeId <= 0 { + subscribeId = req.SubscribeId + } + if duration <= 0 || subscribeId <= 0 { return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "unknown product") } - duration = req.DurationDays - tier = req.Tier - subscribeId = req.SubscribeId } exp := iapapple.CalcExpire(txPayload.PurchaseDate, duration) sum := sha256.Sum256([]byte(req.SignedTransactionJWS))