微信
This commit is contained in:
@@ -48,6 +48,10 @@ const (
|
|||||||
|
|
||||||
OptYes = "Y"
|
OptYes = "Y"
|
||||||
OptNo = "N"
|
OptNo = "N"
|
||||||
|
|
||||||
|
Relation = "PARTNER"
|
||||||
|
AccountTypeWx = "PERSONAL_WECHATID"
|
||||||
|
AccountTypeOpen = "PERSONAL_OPENID"
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
@@ -239,7 +243,7 @@ type PayRefundResult struct {
|
|||||||
TransactionID string `json:"transaction_id"`
|
TransactionID string `json:"transaction_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MultiProfitSharing struct {
|
type MultiProfitSharingParam struct {
|
||||||
RequestBase
|
RequestBase
|
||||||
TransactionID string `json:"transaction_id" xml:"transaction_id"`
|
TransactionID string `json:"transaction_id" xml:"transaction_id"`
|
||||||
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
|
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"`
|
OrderID string `json:"order_id" xml:"order_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transfers struct {
|
type TransfersParam struct {
|
||||||
RequestBase
|
RequestBase
|
||||||
PartnerTradeNo string `json:"partner_trade_no" xml:"partner_trade_no"`
|
PartnerTradeNo string `json:"partner_trade_no" xml:"partner_trade_no"`
|
||||||
OpenID string `json:"openid" xml:"openid"`
|
OpenID string `json:"openid" xml:"openid"`
|
||||||
@@ -291,7 +295,7 @@ type TransfersResult struct {
|
|||||||
PaymentTime string `json:"payment_time" xml:"payment_time"`
|
PaymentTime string `json:"payment_time" xml:"payment_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfitSharingReceiver struct {
|
type ProfitSharingReceiverParam struct {
|
||||||
RequestBase
|
RequestBase
|
||||||
Receiver CData `json:"receiver" xml:"receiver"`
|
Receiver CData `json:"receiver" xml:"receiver"`
|
||||||
}
|
}
|
||||||
@@ -310,7 +314,7 @@ type ProfitSharingReceiverResult struct {
|
|||||||
Receiver string `json:"receiver" xml:"receiver"`
|
Receiver string `json:"receiver" xml:"receiver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReturnProfitSharing struct {
|
type ReturnProfitSharingParam struct {
|
||||||
RequestBase
|
RequestBase
|
||||||
OrderID string `json:"order_id" xml:"order_id"`
|
OrderID string `json:"order_id" xml:"order_id"`
|
||||||
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
|
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.SetMchID(action, a.mchID)
|
||||||
requestParam.SetNonceStr(utils.GetUUID())
|
requestParam.SetNonceStr(utils.GetUUID())
|
||||||
var sigType string
|
var sigType string
|
||||||
if action != specialAction {
|
if action == specialAction {
|
||||||
sigType = sigTypeSha256
|
sigType = sigTypeSha256
|
||||||
requestParam.SetSignType(sigType)
|
requestParam.SetSignType(sigType)
|
||||||
} else {
|
} 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
|
//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)
|
retVal, err := a.AccessAPI("secapi/pay/multiprofitsharing", param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = a.translateResult(retVal, &result)
|
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
|
//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)
|
retVal, err := a.AccessAPI(specialAction, param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = a.translateResult(retVal, &result)
|
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
|
//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)
|
retVal, err := a.AccessAPI("pay/profitsharingaddreceiver", param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = a.translateResult(retVal, &result)
|
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
|
//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)
|
retVal, err := a.AccessAPI("pay/profitsharingremovereceiver", param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = a.translateResult(retVal, &result)
|
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
|
//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)
|
retVal, err := a.AccessAPI("pay/profitsharingreturn", param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = a.translateResult(retVal, &result)
|
err = a.translateResult(retVal, &result)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func init() {
|
|||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
certPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_cert.pem")
|
certPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_cert.pem")
|
||||||
keyPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_key.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")
|
// api = New("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,10 +104,10 @@ func TestXml2Json(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiProfitSharing(t *testing.T) {
|
func TestMultiProfitSharing(t *testing.T) {
|
||||||
result, err := api.MultiProfitSharing(&MultiProfitSharing{
|
result, err := api.MultiProfitSharing(&MultiProfitSharingParam{
|
||||||
TransactionID: "4200000503202002048392355582",
|
TransactionID: "4200000519202002065628033681",
|
||||||
OutOrderNo: "1730C9A5473311EAAAEA7824AF852DFE",
|
OutOrderNo: "1895BA2948A411EA88B97824AF852DFE",
|
||||||
Receivers: `[{"type":"PERSONAL_WECHATID","account":"wxid_r93tvy06srbp22","amount":1,"description":"分到个人"}]`,
|
Receivers: `[{"type":"PERSONAL_OPENID","account":"ojWb10ND2JBY_hOic5phWQNChWC0","amount":1,"description":"分到个人"}]`,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -117,12 +117,12 @@ func TestMultiProfitSharing(t *testing.T) {
|
|||||||
|
|
||||||
func TestTransfers(t *testing.T) {
|
func TestTransfers(t *testing.T) {
|
||||||
orderNo := utils.GetUUID()
|
orderNo := utils.GetUUID()
|
||||||
result, err := api.Transfers(&Transfers{
|
result, err := api.Transfers(&TransfersParam{
|
||||||
PartnerTradeNo: orderNo,
|
PartnerTradeNo: orderNo,
|
||||||
OpenID: "oYN_usv1RPvrSxCvo1WsbwI8lZa0",
|
OpenID: "ojWb10ND2JBY_hOic5phWQNChWC0",
|
||||||
CheckName: "FORCE_CHECK",
|
CheckName: "FORCE_CHECK",
|
||||||
ReUserName: "苏尹岚",
|
ReUserName: "苏尹岚",
|
||||||
Amount: 100,
|
Amount: 10,
|
||||||
Desc: "测试",
|
Desc: "测试",
|
||||||
SpbillCreateIP: "114.114.114.114",
|
SpbillCreateIP: "114.114.114.114",
|
||||||
})
|
})
|
||||||
@@ -133,11 +133,10 @@ func TestTransfers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddProfitSharingReceiver(t *testing.T) {
|
func TestAddProfitSharingReceiver(t *testing.T) {
|
||||||
result, err := api.AddProfitSharingReceiver(&ProfitSharingReceiver{
|
result, err := api.AddProfitSharingReceiver(&ProfitSharingReceiverParam{
|
||||||
Receiver: `{
|
Receiver: `{
|
||||||
"type": "PERSONAL_WECHATID",
|
"type": "PERSONAL_OPENID",
|
||||||
"account":"wxid_r93tvy06srbp22",
|
"account":"ojWb10ND2JBY_hOic5phWQNChWC0",
|
||||||
"name": "苏尹岚",
|
|
||||||
"relation_type": "STAFF"
|
"relation_type": "STAFF"
|
||||||
}`,
|
}`,
|
||||||
})
|
})
|
||||||
@@ -148,10 +147,10 @@ func TestAddProfitSharingReceiver(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteProfitSharingReceiver(t *testing.T) {
|
func TestDeleteProfitSharingReceiver(t *testing.T) {
|
||||||
result, err := api.DeleteProfitSharingReceiver(&ProfitSharingReceiver{
|
result, err := api.DeleteProfitSharingReceiver(&ProfitSharingReceiverParam{
|
||||||
Receiver: `{
|
Receiver: `{
|
||||||
"type": "PERSONAL_WECHATID",
|
"type": "PERSONAL_OPENID",
|
||||||
"account":"wxid_r93tvy06srbp22"
|
"account":"ojWb10ND2JBY_hOic5phWQNChWC0"
|
||||||
}`,
|
}`,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user