From 461f0e9b5e9da768db6b96adf6f092c72bfb7c90 Mon Sep 17 00:00:00 2001 From: Jerry <85411418@qq.com> Date: Tue, 28 Dec 2021 14:19:03 +0800 Subject: [PATCH] BodyMap add new method Unmarshal() --- alipay/notify.go | 1 + body_map.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/alipay/notify.go b/alipay/notify.go index 7462d685..60ed40e5 100644 --- a/alipay/notify.go +++ b/alipay/notify.go @@ -45,6 +45,7 @@ func ParseNotifyByURLValues(value url.Values) (bm gopay.BodyMap, err error) { } // Deprecated +// 推荐使用 ParseNotifyToBodyMap(),以防阿里云通知参数变动,NotifyRequest 无法解析。 // 解析支付宝支付异步通知的参数到Struct // req:*http.Request // 返回参数notifyReq:Notify请求的参数 diff --git a/body_map.go b/body_map.go index 2a0ae35e..612c2043 100644 --- a/body_map.go +++ b/body_map.go @@ -93,6 +93,15 @@ func (bm BodyMap) JsonBody() (jb string) { return jb } +// Unmarshal to struct or slice point +func (bm BodyMap) Unmarshal(ptr interface{}) (err error) { + bs, err := json.Marshal(bm) + if err != nil { + return err + } + return json.Unmarshal(bs, ptr) +} + func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { if len(bm) == 0 { return nil