1
This commit is contained in:
127
platformapi/lakala/lakala_pay.go
Normal file
127
platformapi/lakala/lakala_pay.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package lakala
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AggregatePay 主扫聚合支付(小程序支付)
|
||||
func (a *API) AggregatePay(param *AggregatePayReq) (*AggregatePayResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version3,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(PayTestUrl, PayActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != PaySuccess {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &AggregatePayResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AggregateRefund 主扫退款 (已经对接了一个了)
|
||||
func (a *API) AggregateRefund(param *AggregateRefundReq) (*AggregateRefundResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version3,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(PayTestUrl, RefundActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != PaySuccess {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &AggregateRefundResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
// PayStatusQuery 支付查询
|
||||
func (a *API) PayStatusQuery(param *PayStatusQueryReq) (*PayStatusQueryResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version3,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(PayTestUrl, PayQueryActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != PaySuccess {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &PayStatusQueryResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ScannerPayMicroPay 扫码枪扫码支付
|
||||
func (a *API) ScannerPayMicroPay(param *PayMicroPayReq) (string, string, string, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version3,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(PayTestUrl, PayMicropayActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
switch result["code"].(string) {
|
||||
case PaySuccess, "BBS10000", "BBS11105":
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
resp := &PayMicroPayResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
return result["code"].(string), result["msg"].(string), resp.TradeNo, nil
|
||||
default:
|
||||
return "", "", "", fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user