Jerry 6 лет назад
Родитель
Сommit
642d2ecf13
3 измененных файлов с 65 добавлено и 0 удалено
  1. 1 0
      README.md
  2. 63 0
      alipay/service_api.go
  3. 1 0
      release_note.txt

+ 1 - 0
README.md

@@ -140,6 +140,7 @@ func main() {
 * alipay.FormatPublicKey() => 格式化支付宝公钥
 * alipay.FormatURLParam() => 格式化支付宝请求URL参数
 * alipay.ParseNotifyResult() => 解析支付宝支付异步通知的参数到Struct
+* alipay.ParseNotifyResultByURLValues() => 通过 url.Values 解析支付宝支付异步通知的参数到Struct
 * alipay.ParseNotifyResultToBodyMap() => 解析支付宝支付异步通知的参数到BodyMap
 * alipay.VerifySign() => 支付宝异步通知参数验签
 * alipay.VerifySyncSign() => 支付宝同步返回参数验签

+ 63 - 0
alipay/service_api.go

@@ -16,6 +16,7 @@ import (
 	"hash"
 	"io/ioutil"
 	"net/http"
+	"net/url"
 	"reflect"
 	"strings"
 	"time"
@@ -55,6 +56,68 @@ func ParseNotifyResultToBodyMap(req *http.Request) (bm gopay.BodyMap, err error)
 	return
 }
 
+// 通过 url.Values 解析支付宝支付异步通知的参数到Struct
+//    value:url.Values
+//    返回参数notifyReq:Notify请求的参数
+//    返回参数err:错误信息
+//    文档:https://docs.open.alipay.com/203/105286/
+func ParseNotifyResultByURLValues(value url.Values) (notifyReq *NotifyRequest, err error) {
+	notifyReq = new(NotifyRequest)
+	notifyReq.NotifyTime = value.Get("notify_time")
+	notifyReq.NotifyType = value.Get("notify_type")
+	notifyReq.NotifyId = value.Get("notify_id")
+	notifyReq.AppId = value.Get("app_id")
+	notifyReq.Charset = value.Get("charset")
+	notifyReq.Version = value.Get("version")
+	notifyReq.SignType = value.Get("sign_type")
+	notifyReq.Sign = value.Get("sign")
+	notifyReq.AuthAppId = value.Get("auth_app_id")
+	notifyReq.TradeNo = value.Get("trade_no")
+	notifyReq.OutTradeNo = value.Get("out_trade_no")
+	notifyReq.OutBizNo = value.Get("out_biz_no")
+	notifyReq.BuyerId = value.Get("buyer_id")
+	notifyReq.BuyerLogonId = value.Get("buyer_logon_id")
+	notifyReq.SellerId = value.Get("seller_id")
+	notifyReq.SellerEmail = value.Get("seller_email")
+	notifyReq.TradeStatus = value.Get("trade_status")
+	notifyReq.TotalAmount = value.Get("total_amount")
+	notifyReq.ReceiptAmount = value.Get("receipt_amount")
+	notifyReq.InvoiceAmount = value.Get("invoice_amount")
+	notifyReq.BuyerPayAmount = value.Get("buyer_pay_amount")
+	notifyReq.PointAmount = value.Get("point_amount")
+	notifyReq.RefundFee = value.Get("refund_fee")
+	notifyReq.Subject = value.Get("subject")
+	notifyReq.Body = value.Get("body")
+	notifyReq.GmtCreate = value.Get("gmt_create")
+	notifyReq.GmtPayment = value.Get("gmt_payment")
+	notifyReq.GmtRefund = value.Get("gmt_refund")
+	notifyReq.GmtClose = value.Get("gmt_close")
+	notifyReq.PassbackParams = value.Get("passback_params")
+
+	billList := value.Get("fund_bill_list")
+	if billList != gopay.NULL {
+		bills := make([]*FundBillListInfo, 0)
+		if err = json.Unmarshal([]byte(billList), &bills); err != nil {
+			return nil, fmt.Errorf(`"fund_bill_list" xml.Unmarshal(%s):%w`, billList, err)
+		}
+		notifyReq.FundBillList = bills
+	} else {
+		notifyReq.FundBillList = nil
+	}
+
+	detailList := value.Get("voucher_detail_list")
+	if detailList != gopay.NULL {
+		details := make([]*VoucherDetailListInfo, 0)
+		if err = json.Unmarshal([]byte(detailList), &details); err != nil {
+			return nil, fmt.Errorf(`"voucher_detail_list" xml.Unmarshal(%s):%w`, detailList, err)
+		}
+		notifyReq.VoucherDetailList = details
+	} else {
+		notifyReq.VoucherDetailList = nil
+	}
+	return
+}
+
 // 解析支付宝支付异步通知的参数到Struct
 //    req:*http.Request
 //    返回参数notifyReq:Notify请求的参数

+ 1 - 0
release_note.txt

@@ -5,6 +5,7 @@
    (2) 支付宝:新增Client方法:client.DataBillDownloadUrlQuery(),查询对账单下载地址。
    (3) 支付宝:开放公共方法:alipay.GetRsaSign(),获取支付宝参数签名(参数sign值)。
    (4) 支付宝:开放公共方法:alipay.FormatURLParam(),格式化支付宝请求URL参数。
+   (4) 支付宝:新增公共方法:alipay.ParseNotifyResultByURLValues(),通过 url.Values 解析支付宝支付异步通知的参数到Struct。
 
 版本号:Release 1.5.4
 发布时间:2020/02/29 14:32