From 4626be417c9094bd0784e62605fe53bf70ed2341 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 4 Feb 2020 17:41:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E4=BC=81=E4=B8=9A=E4=BB=98=E6=AC=BE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/wxpayapi/wxpayapi.go | 34 +++++++++++++++++++-------- platformapi/wxpayapi/wxpayapi_test.go | 9 +++---- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/platformapi/wxpayapi/wxpayapi.go b/platformapi/wxpayapi/wxpayapi.go index efc135d5..9c7c11dc 100644 --- a/platformapi/wxpayapi/wxpayapi.go +++ b/platformapi/wxpayapi/wxpayapi.go @@ -32,6 +32,8 @@ const ( sigTypeKey = "sign_type" sigTypeMd5 = "MD5" sigTypeSha256 = "HMAC-SHA256" + + specialAction = "mmpaymkttransfers/promotion/transfers" ) const ( @@ -59,28 +61,40 @@ type API struct { type RequestBase struct { XMLName xml.Name `json:"-" xml:"xml"` - AppID string `json:"appid" xml:"appid"` + AppID string `json:"appid" xml:"appid,omitempty"` + MchID string `json:"mch_id" xml:"mch_id,omitempty"` + // 企业付款基础参数不一样 + AppID2 string `json:"mch_appid,omitempty" xml:"mch_appid,omitempty"` + MchID2 string `json:"mchid,omitempty" xml:"mchid,omitempty"` + DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"` - MchID string `json:"mch_id" xml:"mch_id"` NonceStr string `json:"nonce_str" xml:"nonce_str"` Sign string `json:"sign" xml:"sign"` SignType string `json:"sign_type,omitempty" xml:"sign_type,omitempty"` } type IRequestBase interface { - SetAppID(appID string) - SetMchID(mchID string) + SetAppID(action, appID string) + SetMchID(action, mchID string) SetNonceStr(nonceStr string) SetSign(sign string) SetSignType(signType string) } -func (r *RequestBase) SetAppID(appID string) { - r.AppID = appID +func (r *RequestBase) SetAppID(action, appID string) { + if action != specialAction { + r.AppID = appID + } else { + r.AppID2 = appID + } } -func (r *RequestBase) SetMchID(mchID string) { - r.MchID = mchID +func (r *RequestBase) SetMchID(action, mchID string) { + if action != specialAction { + r.MchID = mchID + } else { + r.MchID2 = mchID + } } func (r *RequestBase) SetNonceStr(nonceStr string) { @@ -303,8 +317,8 @@ func mustMarshalXML(obj interface{}) []byte { } func (a *API) AccessAPI(action string, requestParam IRequestBase) (retVal map[string]interface{}, err error) { - requestParam.SetAppID(a.appID) - requestParam.SetMchID(a.mchID) + requestParam.SetAppID(action, a.appID) + requestParam.SetMchID(action, a.mchID) requestParam.SetNonceStr(utils.GetUUID()) sigType := sigTypeSha256 // sigType := sigTypeMd5 diff --git a/platformapi/wxpayapi/wxpayapi_test.go b/platformapi/wxpayapi/wxpayapi_test.go index 964c2a63..e02aa221 100644 --- a/platformapi/wxpayapi/wxpayapi_test.go +++ b/platformapi/wxpayapi/wxpayapi_test.go @@ -45,6 +45,7 @@ func TestCreateUnifiedOrder(t *testing.T) { SpbillCreateIP: "114.114.114.114", TradeType: TradeTypeNative, TotalFee: 1, + ProfitSharing: OptYes, }) if err != nil { t.Fatal(err) @@ -64,11 +65,11 @@ func TestCloseOrder(t *testing.T) { func TestPayRefund(t *testing.T) { result, err := api.PayRefund(&PayRefundParam{ TransactionID: "", - OutTradeNo: "8E0DD6260B7511EA908C186590E02977", + OutTradeNo: "88316516447981", NotifyURL: "http://callback.test.jxc4.com/wxpay/msg/", - OutRefundNo: utils.GetUUID(), - TotalFee: 1, - RefundFee: 1, + OutRefundNo: "88316516447981", + TotalFee: 8987, + RefundFee: 8987, }) if err != nil { t.Fatal(err)