tansfer
This commit is contained in:
parent
00f3429c84
commit
4642e7e686
28
unify/pay.go
28
unify/pay.go
|
|
@ -4,8 +4,10 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.u8t.cn/open/gosdk/util"
|
||||
"net/url"
|
||||
|
||||
"git.u8t.cn/open/gosdk/util"
|
||||
"git.u8t.cn/open/goutil"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -219,3 +221,27 @@ func (p *Pay) RefundPartnerOrder(req *RefundOrderReq) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pay) Transfer(req *TransferReq) error {
|
||||
if err := req.Check(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqUrl := fmt.Sprintf("%s/api/pay/transfer?", p.address)
|
||||
result, err := util.HttpPostJson(reqUrl, map[string]string{
|
||||
"x-token": p.token,
|
||||
}, []byte(goutil.EncodeJSON(req)))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var rsp CommonResponse
|
||||
if err := json.Unmarshal([]byte(result), &rsp); err != nil {
|
||||
return err
|
||||
}
|
||||
if rsp.Code != 0 {
|
||||
return fmt.Errorf("%d:%s", rsp.Code, rsp.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package unify
|
||||
|
||||
import "errors"
|
||||
|
||||
type OrderUser struct {
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
|
|
@ -51,8 +53,35 @@ type RefundOrderReq struct {
|
|||
RefundFee int64 `json:"refundFee,omitempty"`
|
||||
}
|
||||
|
||||
type TransferReq struct {
|
||||
PayAmount int64 `json:"payAmount"`
|
||||
PayType string `json:"payType"`
|
||||
PayTitle string `json:"payTitle"`
|
||||
PayChannel string `json:"payChannel"`
|
||||
UserId string `json:"userId"`
|
||||
}
|
||||
|
||||
type CommonResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func (r *TransferReq) Check() error {
|
||||
if r.PayTitle == "" {
|
||||
return errors.New("PayTitle is nil")
|
||||
}
|
||||
if r.PayChannel == "" {
|
||||
return errors.New("PayChannel is nil")
|
||||
}
|
||||
if r.PayType == "" {
|
||||
return errors.New("PayType is nil")
|
||||
}
|
||||
if r.UserId == "" {
|
||||
return errors.New("UserId is nil")
|
||||
}
|
||||
if r.PayAmount < 0 {
|
||||
return errors.New("PayAmount is nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue