Files
baseapi/platformapi/lakala/lakala_pay.go
邹宗楠 69a65dab98 1
2025-07-09 15:38:19 +08:00

128 lines
3.2 KiB
Go

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(PayProdUrl, 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(PayProdUrl, 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(PayProdUrl, 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(PayProdUrl, 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))
}
}