This commit is contained in:
苏尹岚
2020-02-06 14:13:40 +08:00
parent a7bbb61791
commit f615cae0a4
2 changed files with 28 additions and 25 deletions

View File

@@ -48,6 +48,10 @@ const (
OptYes = "Y"
OptNo = "N"
Relation = "PARTNER"
AccountTypeWx = "PERSONAL_WECHATID"
AccountTypeOpen = "PERSONAL_OPENID"
)
type API struct {
@@ -239,7 +243,7 @@ type PayRefundResult struct {
TransactionID string `json:"transaction_id"`
}
type MultiProfitSharing struct {
type MultiProfitSharingParam struct {
RequestBase
TransactionID string `json:"transaction_id" xml:"transaction_id"`
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
@@ -263,7 +267,7 @@ type MultiProfitSharingResult struct {
OrderID string `json:"order_id" xml:"order_id"`
}
type Transfers struct {
type TransfersParam struct {
RequestBase
PartnerTradeNo string `json:"partner_trade_no" xml:"partner_trade_no"`
OpenID string `json:"openid" xml:"openid"`
@@ -291,7 +295,7 @@ type TransfersResult struct {
PaymentTime string `json:"payment_time" xml:"payment_time"`
}
type ProfitSharingReceiver struct {
type ProfitSharingReceiverParam struct {
RequestBase
Receiver CData `json:"receiver" xml:"receiver"`
}
@@ -310,7 +314,7 @@ type ProfitSharingReceiverResult struct {
Receiver string `json:"receiver" xml:"receiver"`
}
type ReturnProfitSharing struct {
type ReturnProfitSharingParam struct {
RequestBase
OrderID string `json:"order_id" xml:"order_id"`
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
@@ -425,7 +429,7 @@ func (a *API) AccessAPI(action string, requestParam IRequestBase) (retVal map[st
requestParam.SetMchID(action, a.mchID)
requestParam.SetNonceStr(utils.GetUUID())
var sigType string
if action != specialAction {
if action == specialAction {
sigType = sigTypeSha256
requestParam.SetSignType(sigType)
} else {
@@ -560,7 +564,7 @@ func (a *API) PayRefund(param *PayRefundParam) (refundResult *PayRefundResult, e
//请求多次分账
//https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_6&index=2
func (a *API) MultiProfitSharing(param *MultiProfitSharing) (result *MultiProfitSharingResult, err error) {
func (a *API) MultiProfitSharing(param *MultiProfitSharingParam) (result *MultiProfitSharingResult, err error) {
retVal, err := a.AccessAPI("secapi/pay/multiprofitsharing", param)
if err == nil {
err = a.translateResult(retVal, &result)
@@ -570,7 +574,7 @@ func (a *API) MultiProfitSharing(param *MultiProfitSharing) (result *MultiProfit
//企业付款
//https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
func (a *API) Transfers(param *Transfers) (result *TransfersResult, err error) {
func (a *API) Transfers(param *TransfersParam) (result *TransfersResult, err error) {
retVal, err := a.AccessAPI(specialAction, param)
if err == nil {
err = a.translateResult(retVal, &result)
@@ -580,7 +584,7 @@ func (a *API) Transfers(param *Transfers) (result *TransfersResult, err error) {
//添加分账接收方
//https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_3&index=4
func (a *API) AddProfitSharingReceiver(param *ProfitSharingReceiver) (result *ProfitSharingReceiverResult, err error) {
func (a *API) AddProfitSharingReceiver(param *ProfitSharingReceiverParam) (result *ProfitSharingReceiverResult, err error) {
retVal, err := a.AccessAPI("pay/profitsharingaddreceiver", param)
if err == nil {
err = a.translateResult(retVal, &result)
@@ -590,7 +594,7 @@ func (a *API) AddProfitSharingReceiver(param *ProfitSharingReceiver) (result *Pr
//删除分账接收方
//https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_4&index=5
func (a *API) DeleteProfitSharingReceiver(param *ProfitSharingReceiver) (result *ProfitSharingReceiverResult, err error) {
func (a *API) DeleteProfitSharingReceiver(param *ProfitSharingReceiverParam) (result *ProfitSharingReceiverResult, err error) {
retVal, err := a.AccessAPI("pay/profitsharingremovereceiver", param)
if err == nil {
err = a.translateResult(retVal, &result)
@@ -600,7 +604,7 @@ func (a *API) DeleteProfitSharingReceiver(param *ProfitSharingReceiver) (result
//分账回退
//https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_7&index=7
func (a *API) ReturnProfitSharing(param *ReturnProfitSharing) (result *ReturnProfitSharingResult, err error) {
func (a *API) ReturnProfitSharing(param *ReturnProfitSharingParam) (result *ReturnProfitSharingResult, err error) {
retVal, err := a.AccessAPI("pay/profitsharingreturn", param)
if err == nil {
err = a.translateResult(retVal, &result)

View File

@@ -23,7 +23,7 @@ func init() {
baseapi.Init(sugarLogger)
certPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_cert.pem")
keyPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_key.pem")
api = NewWithCertificate("wx2bb99eb5d2c9b82c", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702", certPEMBlock, keyPEMBlock)
api = NewWithCertificate("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702", certPEMBlock, keyPEMBlock)
// api = New("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702")
}
@@ -104,10 +104,10 @@ func TestXml2Json(t *testing.T) {
}
func TestMultiProfitSharing(t *testing.T) {
result, err := api.MultiProfitSharing(&MultiProfitSharing{
TransactionID: "4200000503202002048392355582",
OutOrderNo: "1730C9A5473311EAAAEA7824AF852DFE",
Receivers: `[{"type":"PERSONAL_WECHATID","account":"wxid_r93tvy06srbp22","amount":1,"description":"分到个人"}]`,
result, err := api.MultiProfitSharing(&MultiProfitSharingParam{
TransactionID: "4200000519202002065628033681",
OutOrderNo: "1895BA2948A411EA88B97824AF852DFE",
Receivers: `[{"type":"PERSONAL_OPENID","account":"ojWb10ND2JBY_hOic5phWQNChWC0","amount":1,"description":"分到个人"}]`,
})
if err != nil {
t.Fatal(err)
@@ -117,12 +117,12 @@ func TestMultiProfitSharing(t *testing.T) {
func TestTransfers(t *testing.T) {
orderNo := utils.GetUUID()
result, err := api.Transfers(&Transfers{
result, err := api.Transfers(&TransfersParam{
PartnerTradeNo: orderNo,
OpenID: "oYN_usv1RPvrSxCvo1WsbwI8lZa0",
OpenID: "ojWb10ND2JBY_hOic5phWQNChWC0",
CheckName: "FORCE_CHECK",
ReUserName: "苏尹岚",
Amount: 100,
Amount: 10,
Desc: "测试",
SpbillCreateIP: "114.114.114.114",
})
@@ -133,11 +133,10 @@ func TestTransfers(t *testing.T) {
}
func TestAddProfitSharingReceiver(t *testing.T) {
result, err := api.AddProfitSharingReceiver(&ProfitSharingReceiver{
result, err := api.AddProfitSharingReceiver(&ProfitSharingReceiverParam{
Receiver: `{
"type": "PERSONAL_WECHATID",
"account":"wxid_r93tvy06srbp22",
"name": "苏尹岚",
"type": "PERSONAL_OPENID",
"account":"ojWb10ND2JBY_hOic5phWQNChWC0",
"relation_type": "STAFF"
}`,
})
@@ -148,10 +147,10 @@ func TestAddProfitSharingReceiver(t *testing.T) {
}
func TestDeleteProfitSharingReceiver(t *testing.T) {
result, err := api.DeleteProfitSharingReceiver(&ProfitSharingReceiver{
result, err := api.DeleteProfitSharingReceiver(&ProfitSharingReceiverParam{
Receiver: `{
"type": "PERSONAL_WECHATID",
"account":"wxid_r93tvy06srbp22"
"type": "PERSONAL_OPENID",
"account":"ojWb10ND2JBY_hOic5phWQNChWC0"
}`,
})
if err != nil {