通联宝apixiugai
This commit is contained in:
@@ -1 +1,52 @@
|
||||
package tonglianpayapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
MsgTypeUnkown = 0 // 未知
|
||||
MsgTypePay = "VSP501" // 支付结果回调
|
||||
MsgTypeRefund = "VSP503" // 退款结果回调
|
||||
|
||||
TrxStatusSuccess = "0000"
|
||||
)
|
||||
|
||||
type CallBackResult struct {
|
||||
AppID string `json:"appID"`
|
||||
OuttrxID string `json:"outtrxID"`
|
||||
TrxCode string `json:"trxCode"`
|
||||
TrxID string `json:"trxID"`
|
||||
TrxAmt int `json:"trxAmt"`
|
||||
TrxDate string `json:"trxDate"`
|
||||
PayTime string `json:"payTime"`
|
||||
ChnlTrxID string `json:"chnlTrxID"`
|
||||
TrxStatus string `json:"trxStatus"`
|
||||
CusID string `json:"cusID"`
|
||||
TermNo string `json:"termNo"`
|
||||
TermBatchid string `json:"termBatchid"`
|
||||
TermTraceno string `json:"termTraceno"`
|
||||
TermAuthno string `json:"termAuthno"`
|
||||
TermRefnum string `json:"termRefnum"`
|
||||
TrxReserved string `json:"trxReserved"`
|
||||
SrcTrxid string `json:"srcTrxid"`
|
||||
CusorderID string `json:"cusorderID"`
|
||||
Acct string `json:"acct"`
|
||||
Fee string `json:"fee"`
|
||||
SignType string `json:"signType"`
|
||||
Cmid string `json:"cmid"`
|
||||
Chnlid string `json:"chnlid"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
func (a *API) GetCallbackMsg(request *http.Request) (call *CallBackResult, err error) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
call = &CallBackResult{}
|
||||
json.Unmarshal(data, &call)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return call, err
|
||||
}
|
||||
|
||||
@@ -64,6 +64,34 @@ type PayInfo struct {
|
||||
Package string `json:"package"`
|
||||
SignType string `json:"signType"`
|
||||
PaySign string `json:"paySign"`
|
||||
PrepayID string `json:"prepayID"`
|
||||
}
|
||||
|
||||
type PayRefundParam struct {
|
||||
CusID string `json:"cusid"`
|
||||
AppID string `json:"appid"`
|
||||
Trxamt int `json:"trxamt"` //交易金额 单位为分
|
||||
Reqsn string `json:"reqsn"` //商户交易单号
|
||||
OldReqsn string `json:"oldReqsn"`
|
||||
Remark string `json:"remark"`
|
||||
RandomStr string `json:"randomStr"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
type PayRefundResult struct {
|
||||
RetCode string `json:"retCode"`
|
||||
RetMsg string `json:"retMsg"`
|
||||
CusID string `json:"cusID"`
|
||||
AppID string `json:"appID"`
|
||||
TrxID string `json:"trxID"`
|
||||
Reqsn string `json:"reqsn"`
|
||||
TrxStatus string `json:"trxStatus"`
|
||||
FinTime string `json:"finTime"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
RandomStr string `json:"randomStr"`
|
||||
Sign string `json:"sign"`
|
||||
Fee int `json:"fee"`
|
||||
TrxCode string `json:"trxCode"`
|
||||
}
|
||||
|
||||
func New(appID, appKey, cusID, subAppid string, config ...*platformapi.APIConfig) *API {
|
||||
@@ -108,9 +136,9 @@ func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal
|
||||
if action == sepcAction {
|
||||
params["paytype"] = payType
|
||||
params["sub_appid"] = a.subAppid
|
||||
signStr := a.signParam(params)
|
||||
params["sign"] = signStr
|
||||
}
|
||||
signStr := a.signParam(params)
|
||||
params["sign"] = signStr
|
||||
fullURL := utils.GenerateGetURL(prodURL, action, nil)
|
||||
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
@@ -151,3 +179,16 @@ func (a *API) CreateUnitorderOrder(param *CreateUnitorderOrderParam) (result *Cr
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (a *API) PayRefund(param *PayRefundParam) (result *PayRefundResult, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["trxamt"] = param.Trxamt
|
||||
params["reqsn"] = param.Reqsn
|
||||
params["oldreqsn"] = param.OldReqsn
|
||||
params["remark"] = param.Remark
|
||||
retVal, err := a.AccessAPI("unitorder/refund", params)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(retVal, &result, false)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user