From 1355634c22d2aeeb6cb9cb76857af6686bce13a8 Mon Sep 17 00:00:00 2001 From: ayflying Date: Tue, 9 Sep 2025 14:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E8=8D=A3=E8=80=80=E6=B6=88?= =?UTF-8?q?=E8=80=97=E7=9A=84=E9=94=99=E8=AF=AF=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/pay/honor/notification.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/package/pay/honor/notification.go b/package/pay/honor/notification.go index 2259ab9..3a312df 100644 --- a/package/pay/honor/notification.go +++ b/package/pay/honor/notification.go @@ -1,11 +1,30 @@ package honor import ( + "errors" + + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/util/grand" + "net/http" ) +// 响应结果结构体 +type Response struct { + Code int `json:"code"` // 结果码 0: 成功,其他: 失败 + Message string `json:"message"` // 错误信息 + Data *DataContent `json:"data"` // 包含购买信息的结构体 +} + +// 数据内容结构体,对应data字段 +type DataContent struct { + PurchaseProductInfo string `json:"purchaseProductInfo"` // 消耗结果数据的JSON字符串 + DataSig string `json:"dataSig"` // purchaseProductInfo的签名 + SigAlgorithm string `json:"sigAlgorithm"` // 签名算法,云侧加密算法为"RSA" +} + func (p *Pay) Notification(r *http.Request) { } @@ -13,14 +32,21 @@ func (p *Pay) Notification(r *http.Request) { // ConsumeProduct 商品消耗 func (p *Pay) ConsumeProduct(purchaseToken string) (err error) { url := Host + "/iap/server/consumeProduct" - _, err = g.Client().ContentJson().Post(gctx.New(), url, g.Map{ + get, err := g.Client().ContentJson().Post(gctx.New(), url, g.Map{ "purchaseToken": purchaseToken, - "developerChallenge": "", + "developerChallenge": grand.S(16), }) if err != nil { return } + var res *Response + gjson.DecodeTo(get.ReadAllString(), &res) + if res.Code != 0 { + g.Log().Error(gctx.New(), "商品消耗失败: "+res.Message) + return errors.New(res.Message) + } + return }