微信支付对于企业付款处理
This commit is contained in:
@@ -32,6 +32,8 @@ const (
|
|||||||
sigTypeKey = "sign_type"
|
sigTypeKey = "sign_type"
|
||||||
sigTypeMd5 = "MD5"
|
sigTypeMd5 = "MD5"
|
||||||
sigTypeSha256 = "HMAC-SHA256"
|
sigTypeSha256 = "HMAC-SHA256"
|
||||||
|
|
||||||
|
specialAction = "mmpaymkttransfers/promotion/transfers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -59,28 +61,40 @@ type API struct {
|
|||||||
type RequestBase struct {
|
type RequestBase struct {
|
||||||
XMLName xml.Name `json:"-" xml:"xml"`
|
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"`
|
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"`
|
NonceStr string `json:"nonce_str" xml:"nonce_str"`
|
||||||
Sign string `json:"sign" xml:"sign"`
|
Sign string `json:"sign" xml:"sign"`
|
||||||
SignType string `json:"sign_type,omitempty" xml:"sign_type,omitempty"`
|
SignType string `json:"sign_type,omitempty" xml:"sign_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IRequestBase interface {
|
type IRequestBase interface {
|
||||||
SetAppID(appID string)
|
SetAppID(action, appID string)
|
||||||
SetMchID(mchID string)
|
SetMchID(action, mchID string)
|
||||||
SetNonceStr(nonceStr string)
|
SetNonceStr(nonceStr string)
|
||||||
SetSign(sign string)
|
SetSign(sign string)
|
||||||
SetSignType(signType string)
|
SetSignType(signType string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestBase) SetAppID(appID string) {
|
func (r *RequestBase) SetAppID(action, appID string) {
|
||||||
r.AppID = appID
|
if action != specialAction {
|
||||||
|
r.AppID = appID
|
||||||
|
} else {
|
||||||
|
r.AppID2 = appID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestBase) SetMchID(mchID string) {
|
func (r *RequestBase) SetMchID(action, mchID string) {
|
||||||
r.MchID = mchID
|
if action != specialAction {
|
||||||
|
r.MchID = mchID
|
||||||
|
} else {
|
||||||
|
r.MchID2 = mchID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestBase) SetNonceStr(nonceStr string) {
|
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) {
|
func (a *API) AccessAPI(action string, requestParam IRequestBase) (retVal map[string]interface{}, err error) {
|
||||||
requestParam.SetAppID(a.appID)
|
requestParam.SetAppID(action, a.appID)
|
||||||
requestParam.SetMchID(a.mchID)
|
requestParam.SetMchID(action, a.mchID)
|
||||||
requestParam.SetNonceStr(utils.GetUUID())
|
requestParam.SetNonceStr(utils.GetUUID())
|
||||||
sigType := sigTypeSha256
|
sigType := sigTypeSha256
|
||||||
// sigType := sigTypeMd5
|
// sigType := sigTypeMd5
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ func TestCreateUnifiedOrder(t *testing.T) {
|
|||||||
SpbillCreateIP: "114.114.114.114",
|
SpbillCreateIP: "114.114.114.114",
|
||||||
TradeType: TradeTypeNative,
|
TradeType: TradeTypeNative,
|
||||||
TotalFee: 1,
|
TotalFee: 1,
|
||||||
|
ProfitSharing: OptYes,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -64,11 +65,11 @@ func TestCloseOrder(t *testing.T) {
|
|||||||
func TestPayRefund(t *testing.T) {
|
func TestPayRefund(t *testing.T) {
|
||||||
result, err := api.PayRefund(&PayRefundParam{
|
result, err := api.PayRefund(&PayRefundParam{
|
||||||
TransactionID: "",
|
TransactionID: "",
|
||||||
OutTradeNo: "8E0DD6260B7511EA908C186590E02977",
|
OutTradeNo: "88316516447981",
|
||||||
NotifyURL: "http://callback.test.jxc4.com/wxpay/msg/",
|
NotifyURL: "http://callback.test.jxc4.com/wxpay/msg/",
|
||||||
OutRefundNo: utils.GetUUID(),
|
OutRefundNo: "88316516447981",
|
||||||
TotalFee: 1,
|
TotalFee: 8987,
|
||||||
RefundFee: 1,
|
RefundFee: 8987,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user