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)