Jerry 7 лет назад
Родитель
Сommit
f03810802b
2 измененных файлов с 57 добавлено и 10 удалено
  1. 6 5
      alipay_client_test.go
  2. 51 5
      alipay_server_api.go

+ 6 - 5
alipay_client_test.go

@@ -18,11 +18,12 @@ func TestAliPayClient_AliPayTradeWapPay(t *testing.T) {
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
 		//SetReturnUrl("https://www.igoogle.ink").
-		SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify")
+		//SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify").
+		SetNotifyUrl("https://gytmp.iguiyu.com/park-api/pay/alipay/notify")
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "手机网站测试支付")
-	body.Set("out_trade_no", "GYWX201901301040355706100410")
+	body.Set("out_trade_no", "GYWX201901301040355706100423")
 	body.Set("quit_url", "https://www.igoogle.ink")
 	body.Set("total_amount", "100.00")
 	body.Set("product_code", "QUICK_WAP_WAY")
@@ -46,7 +47,7 @@ func TestAliPayClient_AliPayTradeAppPay(t *testing.T) {
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
-		SetNotifyUrl("https://www.igoogle.ink")
+		SetNotifyUrl("https://gytmp.iguiyu.com/park-api/pay/alipay/notify")
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "测试APP支付")
@@ -72,11 +73,11 @@ func TestAliPayClient_AliPayTradePagePay(t *testing.T) {
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
-		SetNotifyUrl("https://gytmp.iguiyu.com/park-api/pay/wechat/notify")
+		SetNotifyUrl("https://gytmp.iguiyu.com/park-api/pay/alipay/notify")
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "网站测试支付")
-	body.Set("out_trade_no", "GYWX201901301040355706100418")
+	body.Set("out_trade_no", "GYWX201901301040355706100425")
 	body.Set("quit_url", "https://www.igoogle.ink")
 	body.Set("total_amount", "88.88")
 	body.Set("product_code", "FAST_INSTANT_TRADE_PAY")

+ 51 - 5
alipay_server_api.go

@@ -15,12 +15,58 @@ import (
 //解析支付宝支付完成后的Notify信息
 func ParseAliPayNotifyResult(req *http.Request) (notifyRsp *AliPayNotifyRequest, err error) {
 	notifyRsp = new(AliPayNotifyRequest)
-	defer req.Body.Close()
-	err = json.NewDecoder(req.Body).Decode(notifyRsp)
-	if err != nil {
-		return nil, err
+	notifyRsp.NotifyTime = req.FormValue("notify_time")
+	notifyRsp.NotifyType = req.FormValue("notify_type")
+	notifyRsp.NotifyId = req.FormValue("notify_id")
+	notifyRsp.AppId = req.FormValue("app_id")
+	notifyRsp.Charset = req.FormValue("charset")
+	notifyRsp.Version = req.FormValue("version")
+	notifyRsp.SignType = req.FormValue("sign_type")
+	notifyRsp.Sign = req.FormValue("sign")
+	notifyRsp.TradeNo = req.FormValue("trade_no")
+	notifyRsp.OutTradeNo = req.FormValue("out_trade_no")
+	notifyRsp.OutBizNo = req.FormValue("out_biz_no")
+	notifyRsp.BuyerId = req.FormValue("buyer_id")
+	notifyRsp.BuyerLogonId = req.FormValue("buyer_logon_id")
+	notifyRsp.SellerId = req.FormValue("seller_id")
+	notifyRsp.SellerEmail = req.FormValue("seller_email")
+	notifyRsp.TradeStatus = req.FormValue("trade_status")
+	notifyRsp.TotalAmount = req.FormValue("total_amount")
+	notifyRsp.ReceiptAmount = req.FormValue("receipt_amount")
+	notifyRsp.InvoiceAmount = req.FormValue("invoice_amount")
+	notifyRsp.BuyerPayAmount = req.FormValue("buyer_pay_amount")
+	notifyRsp.PointAmount = req.FormValue("point_amount")
+	notifyRsp.RefundFee = req.FormValue("refund_fee")
+	notifyRsp.Subject = req.FormValue("subject")
+	notifyRsp.Body = req.FormValue("body")
+	notifyRsp.GmtCreate = req.FormValue("gmt_create")
+	notifyRsp.GmtPayment = req.FormValue("gmt_payment")
+	notifyRsp.GmtRefund = req.FormValue("gmt_refund")
+	notifyRsp.GmtClose = req.FormValue("gmt_close")
+	billList := req.FormValue("fund_bill_list")
+	if billList != null {
+		bills := make([]FundBillListInfo, 0)
+		err = json.Unmarshal([]byte(billList), bills)
+		if err != nil {
+			return nil, err
+		}
+		notifyRsp.FundBillList = bills
+	} else {
+		notifyRsp.FundBillList = nil
 	}
-	return
+	notifyRsp.PassbackParams = req.FormValue("passback_params")
+	detailList := req.FormValue("voucher_detail_list")
+	if detailList != null {
+		details := make([]VoucherDetailListInfo, 0)
+		err = json.Unmarshal([]byte(detailList), details)
+		if err != nil {
+			return nil, err
+		}
+		notifyRsp.VoucherDetailList = details
+	} else {
+		notifyRsp.VoucherDetailList = nil
+	}
+	return notifyRsp, err
 }
 
 //支付通知的签名验证和参数签名后的Sign