weixin
This commit is contained in:
@@ -2,7 +2,7 @@ package wxpayapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/sha256"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -28,7 +28,7 @@ const (
|
|||||||
|
|
||||||
sigKey = "sign"
|
sigKey = "sign"
|
||||||
sigTypeKey = "sign_type"
|
sigTypeKey = "sign_type"
|
||||||
sigType = "MD5"
|
sigType = "HMAC-SHA256"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -64,6 +64,17 @@ type RequestBase struct {
|
|||||||
SignType string `json:"sign_type,omitempty" xml:"sign_type,omitempty"`
|
SignType string `json:"sign_type,omitempty" xml:"sign_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestBase2 struct {
|
||||||
|
XMLName xml.Name `json:"-" xml:"xml"`
|
||||||
|
|
||||||
|
AppID string `json:"mch_appid" xml:"mch_appid"`
|
||||||
|
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"`
|
||||||
|
MchID string `json:"mchid" xml:"mchid"`
|
||||||
|
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 {
|
type IRequestBase interface {
|
||||||
SetAppID(appID string)
|
SetAppID(appID string)
|
||||||
SetMchID(mchID string)
|
SetMchID(mchID string)
|
||||||
@@ -222,6 +233,58 @@ type PayRefundResult struct {
|
|||||||
TransactionID string `json:"transaction_id"`
|
TransactionID string `json:"transaction_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MultiProfitSharing struct {
|
||||||
|
RequestBase
|
||||||
|
TransactionID string `json:"transaction_id" xml:"transaction_id"`
|
||||||
|
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
|
||||||
|
Receivers CData `json:"receivers" xml:"receivers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MultiProfitSharingResult struct {
|
||||||
|
ReturnCode string `json:"return_code" xml:"return_code"`
|
||||||
|
ReturnMsg string `json:"return_msg" xml:"return_msg"`
|
||||||
|
|
||||||
|
ResultCode string `json:"result_code" xml:"result_code"`
|
||||||
|
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"`
|
||||||
|
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"`
|
||||||
|
AppID string `json:"appid" xml:"appid"`
|
||||||
|
MchID string `json:"mch_id" xml:"mch_id"`
|
||||||
|
NonceStr string `json:"nonce_str" xml:"nonce_str"`
|
||||||
|
Sign string `json:"sign" xml:"sign"`
|
||||||
|
|
||||||
|
TransactionID string `json:"transaction_id" xml:"transaction_id"`
|
||||||
|
OutOrderNo string `json:"out_order_no" xml:"out_order_no"`
|
||||||
|
OrderID string `json:"order_id" xml:"order_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Transfers struct {
|
||||||
|
RequestBase2
|
||||||
|
PartnerTradeNo string `json:"partner_trade_no" xml:"partner_trade_no"`
|
||||||
|
OpenID string `json:"openid" xml:"openid"`
|
||||||
|
CheckName string `json:"check_name" xml:"check_name"`
|
||||||
|
ReUserName string `json:"re_user_name,omitempty" xml:"re_user_name,omitempty"`
|
||||||
|
Amount int `json:"amount" xml:"amount"`
|
||||||
|
Desc string `json:"desc" xml:"desc"`
|
||||||
|
SpbillCreateIP string `json:"spbill_create_ip" xml:"spbill_create_ip"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TransfersResult struct {
|
||||||
|
ReturnCode string `json:"return_code" xml:"return_code"`
|
||||||
|
ReturnMsg string `json:"return_msg" xml:"return_msg"`
|
||||||
|
|
||||||
|
ResultCode string `json:"result_code" xml:"result_code"`
|
||||||
|
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"`
|
||||||
|
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"`
|
||||||
|
AppID string `json:"appid" xml:"appid"`
|
||||||
|
MchID string `json:"mch_id" xml:"mch_id"`
|
||||||
|
NonceStr string `json:"nonce_str" xml:"nonce_str"`
|
||||||
|
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"`
|
||||||
|
|
||||||
|
PartnerTradeNo string `json:"partner_trade_no" xml:"partner_trade_no"`
|
||||||
|
PaymentNo string `json:"payment_no" xml:"payment_no"`
|
||||||
|
PaymentTime string `json:"payment_time" xml:"payment_time"`
|
||||||
|
}
|
||||||
|
|
||||||
func New(appID, appKey, mchID string, config ...*platformapi.APIConfig) *API {
|
func New(appID, appKey, mchID string, config ...*platformapi.APIConfig) *API {
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -277,7 +340,7 @@ func (a *API) signParam(params map[string]interface{}) (sig string) {
|
|||||||
sort.Sort(sort.StringSlice(valueList))
|
sort.Sort(sort.StringSlice(valueList))
|
||||||
valueList = append(valueList, fmt.Sprintf("key=%s", a.appKey))
|
valueList = append(valueList, fmt.Sprintf("key=%s", a.appKey))
|
||||||
sig = strings.Join(valueList, "&")
|
sig = strings.Join(valueList, "&")
|
||||||
sig = fmt.Sprintf("%X", md5.Sum([]byte(sig)))
|
sig = fmt.Sprintf("%X", sha256.Sum256([]byte(sig)))
|
||||||
return sig
|
return sig
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,3 +483,23 @@ func (a *API) PayRefund(param *PayRefundParam) (refundResult *PayRefundResult, e
|
|||||||
}
|
}
|
||||||
return refundResult, err
|
return refundResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//请求多次分账
|
||||||
|
//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) {
|
||||||
|
retVal, err := a.AccessAPI("secapi/pay/multiprofitsharing", param)
|
||||||
|
if err == nil {
|
||||||
|
err = a.translateResult(retVal, &result)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//企业付款
|
||||||
|
//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) {
|
||||||
|
retVal, err := a.AccessAPI("mmpaymkttransfers/promotion/transfers", param)
|
||||||
|
if err == nil {
|
||||||
|
err = a.translateResult(retVal, &result)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user