From 4473003a36d2e5c328bf5e0cfd047cff98d61db2 Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 10 Sep 2025 12:15:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8D=A3=E8=80=80=E6=B6=88=E8=80=97=E5=90=8E?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9B=B4=E5=A4=9A=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/pay/honor/notification.go | 47 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/package/pay/honor/notification.go b/package/pay/honor/notification.go index 1c9f0f1..9c5fe85 100644 --- a/package/pay/honor/notification.go +++ b/package/pay/honor/notification.go @@ -11,19 +11,29 @@ import ( "net/http" ) -// 响应结果结构体 type Response struct { - Code int `json:"code"` // 结果码 0: 成功,其他: 失败 - Message string `json:"message"` // 错误信息 - Data *DataContent `json:"data"` // 包含购买信息的结构体 + Code int `json:"code"` + Message string `json:"message"` + Data struct { + PurchaseProductInfo string `json:"purchaseProductInfo"` + DataSig string `json:"dataSig"` + SigAlgorithm string `json:"sigAlgorithm"` + } `json:"data"` } -// 数据内容结构体,对应data字段 -type DataContent struct { - PurchaseProductInfo string `json:"purchaseProductInfo"` // 消耗结果数据的JSON字符串 - DataSig string `json:"dataSig"` // purchaseProductInfo的签名 - SigAlgorithm string `json:"sigAlgorithm"` // 签名算法,云侧加密算法为"RSA" -} +//// 响应结果结构体 +//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) { @@ -37,21 +47,24 @@ func (p *Pay) ConsumeProduct(purchaseToken string) (err error) { if err != nil { return } - get, err := g.Client().ContentJson().Header(g.MapStrStr{ + var header = g.MapStrStr{ "access-token": token, "x-iap-appid": p.AppId, "purchaseToken": purchaseToken, - }).Post(gctx.New(), url, g.Map{ + } + var params = g.Map{ "purchaseToken": purchaseToken, "developerChallenge": grand.S(16), - }) - if err != nil { - - return } + get := g.Client().ContentJson().Header(header).PostContent(gctx.New(), url, params) + g.Log().Debugf(gctx.New(), "商品消耗请求发送:url=%v, header=%v, params=%v", url, header, params) + g.Log().Debugf(gctx.New(), "商品消耗请求收到回复: %s", get) var res *Response - gjson.DecodeTo(get.ReadAllString(), &res) + err = gjson.DecodeTo(get, &res) + if err != nil { + return + } if res.Code != 0 { g.Log().Error(gctx.New(), "商品消耗失败: "+res.Message) return errors.New(res.Message)