diff --git a/alipay/client.go b/alipay/client.go index 8b792146..a991cfb3 100644 --- a/alipay/client.go +++ b/alipay/client.go @@ -44,7 +44,7 @@ func NewClient(appId, privateKey string, isProd bool) (client *Client) { } // alipay.trade.fastpay.refund.query(统一收单交易退款查询) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.fastpay.refund.query func (a *Client) TradeFastPayRefundQuery(bm gopay.BodyMap) (aliRsp *TradeFastpayRefundQueryResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -70,7 +70,7 @@ func (a *Client) TradeFastPayRefundQuery(bm gopay.BodyMap) (aliRsp *TradeFastpay } // alipay.trade.order.settle(统一收单交易结算接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.order.settle +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.order.settle func (a *Client) TradeOrderSettle(bm gopay.BodyMap) (aliRsp *TradeOrderSettleResponse, err error) { err = bm.CheckEmptyError("out_request_no", "trade_no", "royalty_parameters") if err != nil { @@ -93,7 +93,7 @@ func (a *Client) TradeOrderSettle(bm gopay.BodyMap) (aliRsp *TradeOrderSettleRes } // alipay.trade.create(统一收单交易创建接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.create +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.create func (a *Client) TradeCreate(bm gopay.BodyMap) (aliRsp *TradeCreateResponse, err error) { err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject") if err != nil { @@ -116,7 +116,7 @@ func (a *Client) TradeCreate(bm gopay.BodyMap) (aliRsp *TradeCreateResponse, err } // alipay.trade.close(统一收单交易关闭接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.close +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.close func (a *Client) TradeClose(bm gopay.BodyMap) (aliRsp *TradeCloseResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -138,7 +138,7 @@ func (a *Client) TradeClose(bm gopay.BodyMap) (aliRsp *TradeCloseResponse, err e } // alipay.trade.cancel(统一收单交易撤销接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.cancel +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.cancel func (a *Client) TradeCancel(bm gopay.BodyMap) (aliRsp *TradeCancelResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -160,7 +160,7 @@ func (a *Client) TradeCancel(bm gopay.BodyMap) (aliRsp *TradeCancelResponse, err } // alipay.trade.refund(统一收单交易退款接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.refund +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.refund func (a *Client) TradeRefund(bm gopay.BodyMap) (aliRsp *TradeRefundResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -186,7 +186,7 @@ func (a *Client) TradeRefund(bm gopay.BodyMap) (aliRsp *TradeRefundResponse, err } // alipay.trade.page.refund(统一收单退款页面接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.refund +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.page.refund func (a *Client) TradePageRefund(bm gopay.BodyMap) (aliRsp *TradePageRefundResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -212,7 +212,7 @@ func (a *Client) TradePageRefund(bm gopay.BodyMap) (aliRsp *TradePageRefundRespo } // alipay.trade.precreate(统一收单线下交易预创建) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.precreate +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.precreate func (a *Client) TradePrecreate(bm gopay.BodyMap) (aliRsp *TradePrecreateResponse, err error) { err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject") if err != nil { @@ -239,7 +239,7 @@ func (a *Client) TradePrecreate(bm gopay.BodyMap) (aliRsp *TradePrecreateRespons } // alipay.trade.pay(统一收单交易支付接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.pay +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.pay func (a *Client) TradePay(bm gopay.BodyMap) (aliRsp *TradePayResponse, err error) { err = bm.CheckEmptyError("out_trade_no", "scene", "auth_code", "subject") if err != nil { @@ -262,7 +262,7 @@ func (a *Client) TradePay(bm gopay.BodyMap) (aliRsp *TradePayResponse, err error } // alipay.trade.query(统一收单线下交易查询) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.query +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.query func (a *Client) TradeQuery(bm gopay.BodyMap) (aliRsp *TradeQueryResponse, err error) { if bm.Get("out_trade_no") == gopay.NULL && bm.Get("trade_no") == gopay.NULL { return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time") @@ -284,7 +284,7 @@ func (a *Client) TradeQuery(bm gopay.BodyMap) (aliRsp *TradeQueryResponse, err e } // alipay.trade.app.pay(app支付接口2.0) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.app.pay +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.app.pay func (a *Client) TradeAppPay(bm gopay.BodyMap) (payParam string, err error) { err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject") if err != nil { @@ -299,7 +299,7 @@ func (a *Client) TradeAppPay(bm gopay.BodyMap) (payParam string, err error) { } // alipay.trade.wap.pay(手机网站支付接口2.0) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay func (a *Client) TradeWapPay(bm gopay.BodyMap) (payUrl string, err error) { bm.Set("product_code", "QUICK_WAP_WAY") err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject") @@ -315,7 +315,7 @@ func (a *Client) TradeWapPay(bm gopay.BodyMap) (payUrl string, err error) { } // alipay.trade.page.pay(统一收单下单并支付页面接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.pay +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.page.pay func (a *Client) TradePagePay(bm gopay.BodyMap) (payUrl string, err error) { bm.Set("product_code", "FAST_INSTANT_TRADE_PAY") err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject") @@ -331,7 +331,7 @@ func (a *Client) TradePagePay(bm gopay.BodyMap) (payUrl string, err error) { } // alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口) -// 文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer +// 文档地址:https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.toaccount.transfer // 注意:此接口官方以升级替换为 alipay.fund.trans.uni.transfer func (a *Client) FundTransToaccountTransfer(bm gopay.BodyMap) (aliRsp *FundTransToaccountTransferResponse, err error) { if bm.Get("out_biz_no") == gopay.NULL { @@ -354,7 +354,7 @@ func (a *Client) FundTransToaccountTransfer(bm gopay.BodyMap) (aliRsp *FundTrans } // alipay.fund.trans.uni.transfer(单笔转账接口) -// 文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.uni.transfer +// 文档地址:https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer func (a *Client) FundTransUniTransfer(bm gopay.BodyMap) (aliRsp *FundTransUniTransferResponse, err error) { err = bm.CheckEmptyError("out_biz_no", "trans_amount", "product_code", "payee_info") if err != nil { @@ -377,7 +377,7 @@ func (a *Client) FundTransUniTransfer(bm gopay.BodyMap) (aliRsp *FundTransUniTra } // alipay.fund.trans.common.query(转账业务单据查询接口) -// 文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.common.query +// 文档地址:https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.common.query func (a *Client) FundTransCommonQuery(bm gopay.BodyMap) (aliRsp *FundTransCommonQueryResponse, err error) { var bs []byte if bs, err = a.doAliPay(bm, "alipay.fund.trans.common.query"); err != nil { @@ -396,7 +396,7 @@ func (a *Client) FundTransCommonQuery(bm gopay.BodyMap) (aliRsp *FundTransCommon } // alipay.fund.account.query(支付宝资金账户资产查询接口) -// 文档地址:https://docs.open.alipay.com/api_28/alipay.fund.account.query +// 文档地址:https://opendocs.alipay.com/apis/api_28/alipay.fund.account.query func (a *Client) FundAccountQuery(bm gopay.BodyMap) (aliRsp *FundAccountQueryResponse, err error) { err = bm.CheckEmptyError("alipay_user_id") if err != nil { @@ -419,13 +419,13 @@ func (a *Client) FundAccountQuery(bm gopay.BodyMap) (aliRsp *FundAccountQueryRes } // alipay.trade.orderinfo.sync(支付宝订单信息同步接口) -// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.orderinfo.sync +// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.orderinfo.sync func (a *Client) TradeOrderinfoSync(body gopay.BodyMap) { } // alipay.system.oauth.token(换取授权访问令牌) -// 文档地址:https://docs.open.alipay.com/api_9/alipay.system.oauth.token +// 文档地址:https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token func (a *Client) SystemOauthToken(bm gopay.BodyMap) (aliRsp *SystemOauthTokenResponse, err error) { if bm.Get("code") == gopay.NULL && bm.Get("refresh_token") == gopay.NULL { return nil, errors.New("code and refresh_token are not allowed to be null at the same time") @@ -452,7 +452,7 @@ func (a *Client) SystemOauthToken(bm gopay.BodyMap) (aliRsp *SystemOauthTokenRes // alipay.user.info.share(支付宝会员授权信息查询接口) // body:此接口无需body参数 -// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.info.share +// 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.info.share func (a *Client) UserInfoShare() (aliRsp *UserInfoShareResponse, err error) { var bs []byte if bs, err = a.doAliPay(nil, "alipay.user.info.share"); err != nil { @@ -471,7 +471,7 @@ func (a *Client) UserInfoShare() (aliRsp *UserInfoShareResponse, err error) { } // alipay.open.auth.token.app(换取应用授权令牌) -// 文档地址:https://docs.open.alipay.com/api_9/alipay.open.auth.token.app +// 文档地址:https://opendocs.alipay.com/apis/api_9/alipay.open.auth.token.app func (a *Client) OpenAuthTokenApp(bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppResponse, err error) { if bm.Get("code") == gopay.NULL && bm.Get("refresh_token") == gopay.NULL { return nil, errors.New("code and refresh_token are not allowed to be null at the same time") @@ -497,7 +497,7 @@ func (a *Client) OpenAuthTokenApp(bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppRes } // zhima.credit.score.get(芝麻分) -// 文档地址:https://docs.open.alipay.com/api_8/zhima.credit.score.get +// 文档地址:https://opendocs.alipay.com/apis/api_8/zhima.credit.score.get func (a *Client) ZhimaCreditScoreGet(bm gopay.BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error) { if bm.Get("product_code") == gopay.NULL { bm.Set("product_code", "w1010100100000000001") @@ -523,7 +523,7 @@ func (a *Client) ZhimaCreditScoreGet(bm gopay.BodyMap) (aliRsp *ZhimaCreditScore } // alipay.user.certify.open.initialize(身份认证初始化服务) -// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.initialize +// 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certify.open.initialize func (a *Client) UserCertifyOpenInit(bm gopay.BodyMap) (aliRsp *UserCertifyOpenInitResponse, err error) { err = bm.CheckEmptyError("outer_order_no", "biz_code", "identity_param", "merchant_config") if err != nil { @@ -546,8 +546,8 @@ func (a *Client) UserCertifyOpenInit(bm gopay.BodyMap) (aliRsp *UserCertifyOpenI } // alipay.user.certify.open.certify(身份认证开始认证) -// API文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.certify -// 产品文档地址:https://docs.open.alipay.com/20181012100420932508/quickstart +// API文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certify.open.certify +// 产品文档地址:https://opendocs.alipay.com/open/20181012100420932508/quickstart func (a *Client) UserCertifyOpenCertify(bm gopay.BodyMap) (certifyUrl string, err error) { err = bm.CheckEmptyError("certify_id") if err != nil { @@ -562,7 +562,7 @@ func (a *Client) UserCertifyOpenCertify(bm gopay.BodyMap) (certifyUrl string, er } // alipay.user.certify.open.query(身份认证记录查询) -// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.query +// 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certify.open.query func (a *Client) UserCertifyOpenQuery(bm gopay.BodyMap) (aliRsp *UserCertifyOpenQueryResponse, err error) { err = bm.CheckEmptyError("certify_id") if err != nil { @@ -585,7 +585,7 @@ func (a *Client) UserCertifyOpenQuery(bm gopay.BodyMap) (aliRsp *UserCertifyOpen } // alipay.user.info.auth(用户登陆授权) -// 文档地址:https://docs.open.alipay.com/api_9/alipay.user.info.auth +// 文档地址:https://opendocs.alipay.com/apis/api_9/alipay.user.info.auth func (a *Client) UserInfoAuth(bm gopay.BodyMap) (aliRsp *UserInfoAuthResponse, err error) { err = bm.CheckEmptyError("scopes", "state") if err != nil { @@ -612,7 +612,7 @@ func (a *Client) UserInfoAuth(bm gopay.BodyMap) (aliRsp *UserInfoAuthResponse, e } // alipay.data.bill.balance.query(支付宝商家账户当前余额查询) -// 文档地址:https://docs.open.alipay.com/api_15/alipay.data.bill.balance.query +// 文档地址:https://opendocs.alipay.com/apis/api_15/alipay.data.bill.balance.query func (a *Client) DataBillBalanceQuery(bm gopay.BodyMap) (aliRsp *DataBillBalanceQueryResponse, err error) { var bs []byte if bs, err = a.doAliPay(bm, "alipay.data.bill.balance.query"); err != nil { @@ -631,7 +631,7 @@ func (a *Client) DataBillBalanceQuery(bm gopay.BodyMap) (aliRsp *DataBillBalance } // alipay.data.dataservice.bill.downloadurl.query(查询对账单下载地址) -// 文档地址:https://docs.open.alipay.com/api_15/alipay.data.dataservice.bill.downloadurl.query +// 文档地址:https://opendocs.alipay.com/apis/api_15/alipay.data.dataservice.bill.downloadurl.query func (a *Client) DataBillDownloadUrlQuery(bm gopay.BodyMap) (aliRsp *DataBillDownloadUrlQueryResponse, err error) { err = bm.CheckEmptyError("bill_type", "bill_date") if err != nil { diff --git a/alipay/client_test.go b/alipay/client_test.go index 75f4f108..5acd2af0 100644 --- a/alipay/client_test.go +++ b/alipay/client_test.go @@ -434,68 +434,36 @@ func TestSyncVerifySign(t *testing.T) { func TestVerifySign(t *testing.T) { // 测试,假数据,无法验签通过 - 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) + 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") + + ok, err := VerifySign(publicKey, bm) if err != nil { fmt.Println("err:", err) return diff --git a/alipay/model.go b/alipay/model.go index 78f2b9c3..9ad9a38c 100644 --- a/alipay/model.go +++ b/alipay/model.go @@ -16,6 +16,7 @@ const ( type PKCSType uint8 +// Deprecated type NotifyRequest struct { NotifyTime string `json:"notify_time,omitempty"` NotifyType string `json:"notify_type,omitempty"` @@ -49,15 +50,17 @@ type NotifyRequest struct { FundBillList []*FundBillListInfo `json:"fund_bill_list,omitempty"` PassbackParams string `json:"passback_params,omitempty"` VoucherDetailList []*VoucherDetailListInfo `json:"voucher_detail_list,omitempty"` - Method string `json:"method,omitempty"` //电脑网站支付 支付宝请求 return_url 同步返回参数 - Timestamp string `json:"timestamp,omitempty"` //电脑网站支付 支付宝请求 return_url 同步返回参数 + Method string `json:"method,omitempty"` // 电脑网站支付 支付宝请求 return_url 同步返回参数 + Timestamp string `json:"timestamp,omitempty"` // 电脑网站支付 支付宝请求 return_url 同步返回参数 } +// Deprecated type FundBillListInfo struct { Amount string `json:"amount,omitempty"` - FundChannel string `json:"fundChannel,omitempty"` //异步通知里是 fundChannel + FundChannel string `json:"fundChannel,omitempty"` // 异步通知里是 fundChannel } +// Deprecated type VoucherDetailListInfo struct { Id string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -274,6 +277,7 @@ type SystemOauthTokenResponse struct { SignData string `json:"-"` Sign string `json:"sign"` } + type oauthTokenInfo struct { AccessToken string `json:"access_token,omitempty"` AlipayUserId string `json:"alipay_user_id,omitempty"` diff --git a/alipay/service_api.go b/alipay/service_api.go index 1b4499f3..67e1721e 100644 --- a/alipay/service_api.go +++ b/alipay/service_api.go @@ -41,13 +41,13 @@ var allowSignatureAlgorithm = map[string]bool{ // req:*http.Request // 返回参数bm:Notify请求的参数 // 返回参数err:错误信息 -// 文档:https://docs.open.alipay.com/203/105286/ -func ParseNotifyResultToBodyMap(req *http.Request) (bm gopay.BodyMap, err error) { +// 文档:https://opendocs.alipay.com/open/203/105286 +func ParseNotifyToBodyMap(req *http.Request) (bm gopay.BodyMap, err error) { if err = req.ParseForm(); err != nil { return nil, err } var form map[string][]string = req.Form - bm = make(gopay.BodyMap, len(form)) + bm = make(gopay.BodyMap, len(form)+1) for k, v := range form { if len(v) == 1 { bm.Set(k, v[0]) @@ -60,69 +60,23 @@ func ParseNotifyResultToBodyMap(req *http.Request) (bm gopay.BodyMap, err error) // 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) +// 文档:https://opendocs.alipay.com/open/203/105286 +func ParseNotifyByURLValues(value url.Values) (bm gopay.BodyMap, err error) { + bm = make(gopay.BodyMap, len(value)+1) + for k, v := range value { + if len(v) == 1 { + bm.Set(k, v[0]) } - notifyReq.VoucherDetailList = details - } else { - notifyReq.VoucherDetailList = nil } return } +// Deprecated // 解析支付宝支付异步通知的参数到Struct // req:*http.Request // 返回参数notifyReq:Notify请求的参数 // 返回参数err:错误信息 -// 文档:https://docs.open.alipay.com/203/105286/ +// 文档:https://opendocs.alipay.com/open/203/105286 func ParseNotifyResult(req *http.Request) (notifyReq *NotifyRequest, err error) { notifyReq = new(NotifyRequest) if err = req.ParseForm(); err != nil { @@ -206,7 +160,7 @@ A:开发者上传自己的应用公钥证书后,开放平台会为开发者 // sign:待验签sign,aliRsp.Sign // 返回参数ok:是否验签通过 // 返回参数err:错误信息 -// 验签文档:https://docs.open.alipay.com/200/106120 +// 验签文档:https://opendocs.alipay.com/open/200/106120 func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error) { // 支付宝公钥验签 pKey := FormatPublicKey(aliPayPublicKey) @@ -219,10 +173,10 @@ func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error) // VerifySign 支付宝异步通知验签 // 注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签 // aliPayPublicKey:支付宝公钥 -// bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm +// bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm,推荐通 BodyMap 验签 // 返回参数ok:是否验签通过 // 返回参数err:错误信息 -// 验签文档:https://docs.open.alipay.com/200/106120 +// 验签文档:https://opendocs.alipay.com/open/200/106120 func VerifySign(aliPayPublicKey string, bean interface{}) (ok bool, err error) { if aliPayPublicKey == gopay.NULL { return false, errors.New("aliPayPublicKey is null") @@ -300,10 +254,10 @@ func verifySign(signData, sign, signType, aliPayPublicKey string) (err error) { // VerifySignWithCert 支付宝异步通知验签 // 注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签 // aliPayPublicKeyPath:支付宝公钥存放路径 alipayCertPublicKey_RSA2.crt -// bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm +// bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm,推荐通 BodyMap 验签 // 返回参数ok:是否验签通过 // 返回参数err:错误信息 -// 验签文档:https://docs.open.alipay.com/200/106120 +// 验签文档:https://opendocs.alipay.com/open/200/106120 func VerifySignWithCert(aliPayPublicKeyPath string, bean interface{}) (ok bool, err error) { if aliPayPublicKeyPath == gopay.NULL { return false, errors.New("aliPayPublicKeyPath is null") @@ -509,8 +463,8 @@ func GetRootCertSN(rootCertPath string) (sn string, err error) { // encryptedData:包括敏感数据在内的完整用户信息的加密数据 // secretKey:AES密钥,支付宝管理平台配置 // beanPtr:需要解析到的结构体指针 -// 文档:https://docs.alipay.com/mini/introduce/aes -// 文档:https://docs.open.alipay.com/common/104567 +// 文档:https://opendocs.alipay.com/mini/introduce/aes +// 文档:https://opendocs.alipay.com/open/common/104567 func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{}) (err error) { if encryptedData == gopay.NULL || secretKey == gopay.NULL { return errors.New("encryptedData or secretKey is null") @@ -551,8 +505,8 @@ func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{ // DecryptOpenDataToBodyMap 解密支付宝开放数据到 BodyMap // encryptedData:包括敏感数据在内的完整用户信息的加密数据 // secretKey:AES密钥,支付宝管理平台配置 -// 文档:https://docs.alipay.com/mini/introduce/aes -// 文档:https://docs.open.alipay.com/common/104567 +// 文档:https://opendocs.alipay.com/mini/introduce/aes +// 文档:https://opendocs.alipay.com/open/common/104567 func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap, err error) { if encryptedData == gopay.NULL || secretKey == gopay.NULL { return nil, errors.New("encryptedData or secretKey is null") @@ -591,7 +545,7 @@ func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap // grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取 // codeOrToken:支付宝授权码或refresh_token // signType:签名方式 RSA 或 RSA2,默认 RSA2 -// 文档:https://docs.open.alipay.com/api_9/alipay.system.oauth.token +// 文档:https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token func SystemOauthToken(appId string, t PKCSType, privateKey, grantType, codeOrToken, signType string) (rsp *SystemOauthTokenResponse, err error) { var bs []byte bm := make(gopay.BodyMap) @@ -654,7 +608,7 @@ func systemOauthToken(appId string, t PKCSType, privateKey string, bm gopay.Body // privateKey:应用私钥,支持PKCS1和PKCS8 // signType:签名方式 alipay.RSA 或 alipay.RSA2,默认 RSA2 // bizContent:验签时该参数不做任何处理,{任意值},此参数具体看文档 -// 文档:https://docs.open.alipay.com/api_9/monitor.heartbeat.syn +// 文档:https://opendocs.alipay.com/apis/api_9/monitor.heartbeat.syn func MonitorHeartbeatSyn(appId string, t PKCSType, privateKey, signType, bizContent string) (rsp *MonitorHeartbeatSynResponse, err error) { var bs []byte bm := make(gopay.BodyMap)