Skip to content

Commit

Permalink
BodyMap add new method Unmarshal()
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Dec 28, 2021
1 parent 25cfb58 commit 461f0e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions alipay/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func ParseNotifyByURLValues(value url.Values) (bm gopay.BodyMap, err error) {
}

// Deprecated
// 推荐使用 ParseNotifyToBodyMap(),以防阿里云通知参数变动,NotifyRequest 无法解析。
// 解析支付宝支付异步通知的参数到Struct
// req:*http.Request
// 返回参数notifyReq:Notify请求的参数
Expand Down
9 changes: 9 additions & 0 deletions body_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 461f0e9

Please sign in to comment.