Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
smartwalle committed Apr 8, 2018
1 parent 77a4c36 commit dfec030
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 60 deletions.
55 changes: 55 additions & 0 deletions notify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alipay

import (
"errors"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -50,3 +51,57 @@ func (this *AliPay) NotifyVerify(notifyId string) bool {
}
return false
}

func (this *AliPay) GetTradeNotification(req *http.Request) (*TradeNotification, error) {
return GetTradeNotification(req, this.AliPayPublicKey)
}

func GetTradeNotification(req *http.Request, aliPayPublicKey []byte) (noti *TradeNotification, err error) {
if req == nil {
return nil, errors.New("request 参数不能为空")
}

noti = &TradeNotification{}
noti.AppId = req.FormValue("app_id")
noti.AuthAppId = req.FormValue("auth_app_id")
noti.NotifyId = req.FormValue("notify_id")
noti.NotifyType = req.FormValue("notify_type")
noti.NotifyTime = req.FormValue("notify_time")
noti.TradeNo = req.FormValue("trade_no")
noti.TradeStatus = req.FormValue("trade_status")
noti.TotalAmount = req.FormValue("total_amount")
noti.ReceiptAmount = req.FormValue("receipt_amount")
noti.InvoiceAmount = req.FormValue("invoice_amount")
noti.BuyerPayAmount = req.FormValue("buyer_pay_amount")
noti.SellerId = req.FormValue("seller_id")
noti.SellerEmail = req.FormValue("seller_email")
noti.BuyerId = req.FormValue("buyer_id")
noti.BuyerLogonId = req.FormValue("buyer_logon_id")
noti.FundBillList = req.FormValue("fund_bill_list")
noti.Charset = req.FormValue("charset")
noti.PointAmount = req.FormValue("point_amount")
noti.OutTradeNo = req.FormValue("out_trade_no")
noti.OutBizNo = req.FormValue("out_biz_no")
noti.GmtCreate = req.FormValue("gmt_create")
noti.GmtPayment = req.FormValue("gmt_payment")
noti.GmtRefund = req.FormValue("gmt_refund")
noti.GmtClose = req.FormValue("gmt_close")
noti.Subject = req.FormValue("subject")
noti.Body = req.FormValue("body")
noti.RefundFee = req.FormValue("refund_fee")
noti.Version = req.FormValue("version")
noti.SignType = req.FormValue("sign_type")
noti.Sign = req.FormValue("sign")
noti.PassbackParams = req.FormValue("passback_params")
noti.VoucherDetailList = req.FormValue("voucher_detail_list")

if len(noti.NotifyId) == 0 {
return nil, errors.New("不是有效的 Notify")
}

ok, err := verifySign(req.Form, aliPayPublicKey)
if ok == false {
return nil, err
}
return noti, err
}
59 changes: 0 additions & 59 deletions notify_type.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package alipay

import (
"errors"
"net/http"
)

// https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.8AmJwg&treeId=203&articleId=105286&docType=1
type TradeNotification struct {
AuthAppId string `json:"auth_app_id"` // App Id
Expand Down Expand Up @@ -40,57 +35,3 @@ type TradeNotification struct {
PassbackParams string `json:"passback_params"` // 回传参数
VoucherDetailList string `json:"voucher_detail_list"` // 优惠券信息
}

func (this *AliPay) GetTradeNotification(req *http.Request) (*TradeNotification, error) {
return GetTradeNotification(req, this.AliPayPublicKey)
}

func GetTradeNotification(req *http.Request, aliPayPublicKey []byte) (noti *TradeNotification, err error) {
if req == nil {
return nil, errors.New("request 参数不能为空")
}

noti = &TradeNotification{}
noti.AppId = req.FormValue("app_id")
noti.AuthAppId = req.FormValue("auth_app_id")
noti.NotifyId = req.FormValue("notify_id")
noti.NotifyType = req.FormValue("notify_type")
noti.NotifyTime = req.FormValue("notify_time")
noti.TradeNo = req.FormValue("trade_no")
noti.TradeStatus = req.FormValue("trade_status")
noti.TotalAmount = req.FormValue("total_amount")
noti.ReceiptAmount = req.FormValue("receipt_amount")
noti.InvoiceAmount = req.FormValue("invoice_amount")
noti.BuyerPayAmount = req.FormValue("buyer_pay_amount")
noti.SellerId = req.FormValue("seller_id")
noti.SellerEmail = req.FormValue("seller_email")
noti.BuyerId = req.FormValue("buyer_id")
noti.BuyerLogonId = req.FormValue("buyer_logon_id")
noti.FundBillList = req.FormValue("fund_bill_list")
noti.Charset = req.FormValue("charset")
noti.PointAmount = req.FormValue("point_amount")
noti.OutTradeNo = req.FormValue("out_trade_no")
noti.OutBizNo = req.FormValue("out_biz_no")
noti.GmtCreate = req.FormValue("gmt_create")
noti.GmtPayment = req.FormValue("gmt_payment")
noti.GmtRefund = req.FormValue("gmt_refund")
noti.GmtClose = req.FormValue("gmt_close")
noti.Subject = req.FormValue("subject")
noti.Body = req.FormValue("body")
noti.RefundFee = req.FormValue("refund_fee")
noti.Version = req.FormValue("version")
noti.SignType = req.FormValue("sign_type")
noti.Sign = req.FormValue("sign")
noti.PassbackParams = req.FormValue("passback_params")
noti.VoucherDetailList = req.FormValue("voucher_detail_list")

if len(noti.NotifyId) == 0 {
return nil, errors.New("不是有效的 Notify")
}

ok, err := verifySign(req.Form, aliPayPublicKey)
if ok == false {
return nil, err
}
return noti, err
}
2 changes: 1 addition & 1 deletion trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ func TestAliPay_TradePagePay(t *testing.T) {
// p.AuthCode = "xxx"
//
// fmt.Println(client.TradePay(p))
//}
//}

0 comments on commit dfec030

Please sign in to comment.