Jerry 6 лет назад
Родитель
Сommit
656f21c2b6
3 измененных файлов с 70 добавлено и 33 удалено
  1. 61 22
      alipay/client_test.go
  2. 7 9
      alipay/model.go
  3. 2 2
      alipay/service_api.go

+ 61 - 22
alipay/client_test.go

@@ -419,29 +419,68 @@ func TestSyncVerifySign(t *testing.T) {
 
 func TestVerifySign(t *testing.T) {
 	// 测试,假数据,无法验签通过
-	bm := make(gopay.BodyMap)
-	bm.Set("sign", "kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=")
-	bm.Set("sign_type", "RSA2")
-	bm.Set("total_amount", "2.00")
-	bm.Set("buyer_id", "2088102116773037")
-	bm.Set("body", "大乐透2.1")
-	bm.Set("trade_no", "2016071921001003030200089909")
-	bm.Set("refund_fee", "0.00")
-	bm.Set("notify_time", "2016-07-19 14:10:49")
-	bm.Set("subject", "大乐透2.1")
-	bm.Set("charset", "utf-8")
-	bm.Set("notify_type", "trade_status_sync")
-	bm.Set("out_trade_no", "0719141034-6418")
-	bm.Set("gmt_close", "2016-07-19 14:10:46")
-	bm.Set("gmt_payment", "2016-07-19 14:10:47")
-	bm.Set("trade_status", "TRADE_SUCCESS")
-	bm.Set("version", "1.0")
-	bm.Set("gmt_create", "2016-07-19 14:10:44")
-	bm.Set("app_id", "2015102700040153")
-	bm.Set("seller_id", "2088102119685838")
-	bm.Set("notify_id", "4a91b7a78a503640467525113fb7d8bg8e")
 
-	ok, err := VerifySign("aliPayPublicKey", bm)
+	publicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8gueNlkbiDidz6FBQEBpqoRgH8h7JtsPtYW0nzAqy1MME4mFnDSMfSKlreUomS3a55gmBopL1eF4/Km/dEnaL5tCY9+24SKn1D4iyls+lvz/ZjvUjVwxoUYBh8kkcxMZSDeDz8//o+9qZTrICVP2a4sBB8T0XmU4gxfw8FsmtoomBH1nLk3AO7wgRN2a3+SRSAmxrhIGDmF1lljSlhY32eJpJ2TZQKaWNW+7yDBU/0Wt3kQVY84vr14yYagnSCiIfqyVFqePayRtmVJDr5qvSXr51tdqs2zKZCu+26X7JAF4BSsaq4gmY5DmDTm4TohCnBduI1+bPGD+igVmtl05wIDAQAB"
+
+	//bm := make(gopay.BodyMap)
+	//bm.Set("sign", "f19WZ3rko3cVpSG3uEEJF0eb4DuZVLt4/GXnNw9qg8iHUsJLkav0V91R5SSTDhW5lgkn3Xhq7TkFRJiDXdVXMu3XUlsONArp3Iu4tXagYJWt9jbcnc2/l29VYDXPLNcs7BXEWFEaCZLutQY2U82AumEwSc1XBKtsLC4mVX3M3f/ExFQHWklJEBHArYBGe4535uFRlsT2fk6WVuX8CuYZatCrVF1o02xMS5aD29eICPkmin/h87OcTbE1syktyCU1WVgcypagUdGGPTF0SVDFf7FRov7+w7fiCGGGL10tNlK/MLzcewtN2dyGF6RLUX3m+HQ7sNEk2wylRXLNUFig==")
+	//bm.Set("seller_email", "imonkey@100tal.com")
+	//bm.Set("sign_type", "RSA2")
+	//bm.Set("total_amount", "0.02")
+	//bm.Set("buyer_id", "2088812847201551")
+	//bm.Set("invoice_amount", "0.02")
+	//bm.Set("fund_bill_list", `[{"amount":"0.02","fundChannel":"PCREDIT"}]`)
+	//bm.Set("trade_no", "2020010222001401551430614892")
+	//bm.Set("receipt_amount", "0.02")
+	//bm.Set("buyer_pay_amount", "0.02")
+	//bm.Set("notify_time", "2020-01-02 16:18:21")
+	//bm.Set("subject", "商品")
+	//bm.Set("auth_app_id", "2015102700040153")
+	//bm.Set("charset", "utf-8")
+	//bm.Set("point_amount", "0.00")
+	//bm.Set("notify_type", "trade_status_sync")
+	//bm.Set("out_trade_no", "1086209247658383466")
+	//bm.Set("gmt_payment", "2020-01-02 16:18:21")
+	//bm.Set("trade_status", "TRADE_SUCCESS")
+	//bm.Set("version", "1.0")
+	//bm.Set("buyer_logon_id", "185****2920")
+	//bm.Set("gmt_create", "2020-01-02 16:18:21")
+	//bm.Set("app_id", "2015102700040153")
+	//bm.Set("seller_id", "2088631240818980")
+	//bm.Set("notify_id", "2020010200222161821001551453140885")
+
+	req := new(NotifyRequest)
+	req.GmtCreate = "2020-01-02 16:18:21"
+	req.Charset = "utf-8"
+	req.SellerEmail = "imonkey@100tal.com"
+	req.Subject = "商品"
+	req.Sign = "f19WZ3rko3cVpSG3uEEJF0eb4DuZVLt4/GXnNw9qg8iHUsJLkav0V91R5SSTDhW5lgkn3Xhq7TkFRJiDXdVXMu3XUlsONArp3Iu4tXagYJWt9jbcnc2/l29VYDXPLNcs7BXEWFEaCZLutQY2U82AumEwSc1XBKtsLC4mVX3M3f/ExFQHWklJEBHArYBGe4535uFRlsT2fk6WVuX8CuYZatCrVF1o02xMS5aD29eICPkmin/h87OcTbE1syktyCU1WVgcypagUdGGPTF0SVDFf7FRov7+w7fiCGGGL10tNlK/MLzcewtN2dyGF6RLUX3m+HQ7sNEk2wylRXLNUFig=="
+	req.BuyerId = "2088812847201551"
+	req.InvoiceAmount = "0.02"
+	req.NotifyId = "2020010200222161821001551453140885"
+	infos := []*FundBillListInfo{&FundBillListInfo{
+		Amount:      "0.02",
+		FundChannel: "PCREDIT",
+	}}
+	req.FundBillList = infos
+	req.NotifyType = "trade_status_sync"
+	req.TradeStatus = "TRADE_SUCCESS"
+	req.ReceiptAmount = "0.02"
+	req.AppId = "2015102700040153"
+	req.BuyerPayAmount = "0.02"
+	req.SignType = "RSA2"
+	req.SellerId = "2088631240818980"
+	req.GmtPayment = "2020-01-02 16:18:21"
+	req.NotifyTime = "2020-01-02 16:18:21"
+	req.Version = "1.0"
+	req.OutTradeNo = "1086209247658383466"
+	req.TotalAmount = "0.02"
+	req.TradeNo = "2020010222001401551430614892"
+	req.AuthAppId = "2015102700040153"
+	req.BuyerLogonId = "185****2920"
+	req.PointAmount = "0.00"
+
+	ok, err := VerifySign(publicKey, req)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 7 - 9
alipay/model.go

@@ -40,21 +40,19 @@ type NotifyRequest struct {
 	GmtPayment        string                   `json:"gmt_payment,omitempty"`
 	GmtRefund         string                   `json:"gmt_refund,omitempty"`
 	GmtClose          string                   `json:"gmt_close,omitempty"`
-	FundBillList      []*fundBillListInfo      `json:"fund_bill_list,omitempty"`
+	FundBillList      []*FundBillListInfo      `json:"fund_bill_list,omitempty"`
 	PassbackParams    string                   `json:"passback_params,omitempty"`
-	VoucherDetailList []*voucherDetailListInfo `json:"voucher_detail_list,omitempty"`
+	VoucherDetailList []*VoucherDetailListInfo `json:"voucher_detail_list,omitempty"`
 	Method            string                   `json:"method,omitempty"`    //电脑网站支付 支付宝请求 return_url 同步返回参数
 	Timestamp         string                   `json:"timestamp,omitempty"` //电脑网站支付 支付宝请求 return_url 同步返回参数
 }
 
-type fundBillListInfo struct {
+type FundBillListInfo struct {
 	Amount      string `json:"amount,omitempty"`
 	FundChannel string `json:"fundChannel,omitempty"` //异步通知里是 fundChannel
-	BankCode    string `json:"bank_code,omitempty"`
-	RealAmount  string `json:"real_amount,omitempty"`
 }
 
-type voucherDetailListInfo struct {
+type VoucherDetailListInfo struct {
 	Id                         string `json:"id,omitempty"`
 	Name                       string `json:"name,omitempty"`
 	Type                       string `json:"type,omitempty"`
@@ -324,7 +322,7 @@ type refundResponse struct {
 	RefundFee               string           `json:"refund_fee,omitempty"`
 	RefundCurrency          string           `json:"refund_currency,omitempty"`
 	GmtRefundPay            string           `json:"gmt_refund_pay,omitempty"`
-	RefundDetailItemList    []*tradeFundBill `json:"refund_detail_item_list,omitempty"`
+	RefundDetailItemList    []*TradeFundBill `json:"refund_detail_item_list,omitempty"`
 	StoreName               string           `json:"store_name,omitempty"`
 	BuyerUserId             string           `json:"buyer_user_id,omitempty"`
 	RefundPresetPaytoolList []*struct {
@@ -337,7 +335,7 @@ type refundResponse struct {
 	PresentRefundMdiscountAmount string `json:"present_refund_mdiscount_amount,omitempty"`
 }
 
-type tradeFundBill struct {
+type TradeFundBill struct {
 	FundChannel string `json:"fund_channel,omitempty"` //同步通知里是 fund_channel
 	BankCode    string `json:"bank_code,omitempty"`
 	Amount      string `json:"amount,omitempty"`
@@ -374,7 +372,7 @@ type refundQueryResponse struct {
 		TransInEmail  string `json:"trans_in_email,omitempty"`
 	} `json:"refund_royaltys,omitempty"`
 	GmtRefundPay                 string           `json:"gmt_refund_pay,omitempty"`
-	RefundDetailItemList         []*tradeFundBill `json:"refund_detail_item_list,omitempty"`
+	RefundDetailItemList         []*TradeFundBill `json:"refund_detail_item_list,omitempty"`
 	SendBackFee                  string           `json:"send_back_fee,omitempty"`
 	RefundSettlementId           string           `json:"refund_settlement_id,omitempty"`
 	PresentRefundBuyerAmount     string           `json:"present_refund_buyer_amount,omitempty"`

+ 2 - 2
alipay/service_api.go

@@ -98,7 +98,7 @@ func ParseNotifyResult(req *http.Request) (notifyReq *NotifyRequest, err error)
 
 	billList := req.Form.Get("fund_bill_list")
 	if billList != gopay.NULL {
-		bills := make([]*fundBillListInfo, 0)
+		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)
 		}
@@ -109,7 +109,7 @@ func ParseNotifyResult(req *http.Request) (notifyReq *NotifyRequest, err error)
 
 	detailList := req.Form.Get("voucher_detail_list")
 	if detailList != gopay.NULL {
-		details := make([]*voucherDetailListInfo, 0)
+		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)
 		}