feat(basePay): 添加测试环境支持和新功能

- 为 transPreorder 和 relationClose 添加测试环境请求方法
- 更新所有模块导入路径,统一使用新的 common 包
- 重构多个结构体和服务命名以提高一致性
- 新增 labs 包整合基础支付相关功能模块
- 创建 SDK 入口文件便于统一管理和调用
- 在 consts 中增加 BASE_TEST_URL 常量定义
- 优化请求数据结构体字段注释和文档标签
- 移除冗余代码并调整部分函数签名以增强可读性
menu^2
maguodong 2025-10-21 14:34:42 +08:00
parent 7b9657a9e8
commit 54917f8985
50 changed files with 158 additions and 83 deletions

View File

@ -1,8 +1,8 @@
package transpreorder
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
@ -23,3 +23,12 @@ func (tp *TransPreorder) TransPreorder(reqData *TransPreorderRequestData) (*Tran
}
return tp.client.DoRequest(consts.BASE_URL+consts.LKL_DCP_TRANS_PREORDER_URL, request)
}
func (tp *TransPreorder) TransPreorderTest(reqData *TransPreorderRequestData) (*TransPreorderResponse, error) {
// 构建请求结构体
request := &TransPreorderRequest{
ReqTime: gtime.Now().Format("YmdHis"),
Version: "3.0",
ReqData: reqData,
}
return tp.client.DoRequest(consts.BASE_TEST_URL+consts.LKL_DCP_TRANS_PREORDER_URL, request)
}

39
basePay/labs/labs.go Normal file
View File

@ -0,0 +1,39 @@
package labs
import (
"context"
relationclose "github.com/black1552/lkl_sdk/basePay/labs/relationClose"
"github.com/black1552/lkl_sdk/basePay/labs/relationRefund"
"github.com/black1552/lkl_sdk/basePay/labs/relationRevoked"
transmicropay "github.com/black1552/lkl_sdk/basePay/labs/transMicropay"
"github.com/black1552/lkl_sdk/basePay/labs/transMicropayEncry"
"github.com/black1552/lkl_sdk/basePay/labs/transPreorder"
"github.com/black1552/lkl_sdk/basePay/labs/transPreorederEncry"
transquery "github.com/black1552/lkl_sdk/basePay/labs/transQuery"
"github.com/black1552/lkl_sdk/common"
)
type Labs struct {
RelationClose *relationclose.RelationCloseServer
RelationRefund *relationRefund.RelationRefundServer
RelationRevoked *relationRevoked.RelationRevokedServer
TransMicropay *transmicropay.TransMicropayServer
TransMicropayEncry *transMicropayEncry.TransMicropayEncryServer
TransPreorder *transPreorder.TransPreorderServer
TransPreorderEncry *transPreorederEncry.TransPreorderEncryServer
TransQuery *transquery.TransQueryServer
}
func NewLabs(ctx context.Context, cfgJson string) *Labs {
return &Labs{
RelationClose: relationclose.NewRelationCloseServer(common.NewClient[relationclose.RelationCloseResponse](ctx, cfgJson)),
RelationRefund: relationRefund.NewRelationRefundServer(common.NewClient[relationRefund.RelationRefundResponse](ctx, cfgJson)),
RelationRevoked: relationRevoked.NewRelationRevokedServer(common.NewClient[relationRevoked.RelationRevokedResponse](ctx, cfgJson)),
TransMicropay: transmicropay.NewTransMicropayServer(common.NewClient[transmicropay.TransMicropayResponse](ctx, cfgJson)),
TransMicropayEncry: transMicropayEncry.NewTransMicropayEncryServer(common.NewClient[transMicropayEncry.TransMicropayEncryResponse](ctx, cfgJson)),
TransPreorder: transPreorder.NewTransPreorderServer(common.NewClient[transPreorder.TransPreorderResponse](ctx, cfgJson)),
TransPreorderEncry: transPreorederEncry.NewTransPreorderEncryServer(common.NewClient[transPreorederEncry.TransPreorederEncryResponse](ctx, cfgJson)),
TransQuery: transquery.NewTransQueryServer(common.NewClient[transquery.TransQueryResponse](ctx, cfgJson)),
}
}

View File

@ -1,8 +1,8 @@
package relationclose
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
@ -30,10 +30,22 @@ func (a *RelationCloseServer) RelationClose(reqData *RelationCloseRequestData) (
Version: "3.0",
ReqData: reqData,
}
// 设置API路径 - 使用consts中的生产环境URL
url := consts.BASE_URL + consts.LKL_BASE_URL_RELATION_CLOSE_URL
// 发送请求 - 使用consts中定义的聚合扫码关单URL
return a.Client.DoRequest(url, request)
return a.Client.DoRequest(consts.BASE_URL+consts.LKL_BASE_URL_RELATION_CLOSE_URL, request)
}
// RelationCloseTest 执行聚合扫码关单测试请求
// - merchantNo: 商户号
// - termNo: 终端号
// - 原交易标识originOutTradeNo、originTradeNo、(originOutOrderSource+originOutOrderNo) 三者必选其一
// - locationInfo: 地址位置信息(风控要求必送)
func (a *RelationCloseServer) RelationCloseTest(reqData *RelationCloseRequestData) (*RelationCloseResponse, error) {
// 构建请求结构体
request := &RelationCloseRequest{
ReqTime: gtime.Now().Format("YmdHis"),
Version: "3.0",
ReqData: reqData,
}
// 发送请求 - 使用consts中定义的聚合扫码关单URL
return a.Client.DoRequest(consts.BASE_TEST_URL+consts.LKL_BASE_URL_RELATION_CLOSE_URL, request)
}

View File

@ -9,13 +9,13 @@ type LocationInfo struct {
// RelationCloseRequestData 聚合扫码关单请求数据结构体
type RelationCloseRequestData struct {
MerchantNo string `json:"merchant_no"` // 商户号 (必填)
TermNo string `json:"term_no"` // 终端号 (必填)
OriginOutTradeNo string `json:"origin_out_trade_no,omitempty"` // 原商户交易流水号 (可选)
OriginTradeNo string `json:"origin_trade_no,omitempty"` // 原交易拉卡拉交易流水号 (可选)
OriginOutOrderSource string `json:"origin_out_order_source,omitempty"` // 原订单外部订单来源 (可选)
OriginOutOrderNo string `json:"origin_out_order_no,omitempty"` // 原订单外部商户订单号 (可选)
LocationInfo *LocationInfo `json:"location_info"` // 地址位置信息 (必填)
MerchantNo string `json:"merchant_no" dc:"商户号 (必填)"` // 商户号 (必填)
TermNo string `json:"term_no" dc:"终端号 (必填)"` // 终端号 (必填)
OriginOutTradeNo string `json:"origin_out_trade_no,omitempty" dc:"原商户交易流水号 (可选)"` // 原商户交易流水号 (可选)
OriginTradeNo string `json:"origin_trade_no,omitempty" dc:"原交易拉卡拉交易流水号 (可选)"` // 原交易拉卡拉交易流水号 (可选)
OriginOutOrderSource string `json:"origin_out_order_source,omitempty" dc:"原订单外部订单来源 (可选)"` // 原订单外部订单来源 (可选)
OriginOutOrderNo string `json:"origin_out_order_no,omitempty" dc:"原订单外部商户订单号 (可选)"` // 原订单外部商户订单号 (可选)
LocationInfo *LocationInfo `json:"location_info" dc:"地址位置信息 (必填)"` // 地址位置信息 (必填)
}
// RelationCloseRequest 聚合扫码关单请求结构体

View File

@ -1,8 +1,8 @@
package relationRefund
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -1,8 +1,8 @@
package relationRevoked
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -1,8 +1,8 @@
package transmicropay
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -1,25 +1,25 @@
package transMicropayEncry
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
// TransMicropayEncryServer 聚合扫码被扫接口(全报文加密)服务结构体
type TransMicropayEncryServer[T any] struct {
Client *common.Client[T]
type TransMicropayEncryServer struct {
Client *common.Client[TransMicropayEncryResponse]
}
// NewTransMicropayEncryServer 创建聚合扫码被扫接口(全报文加密)服务实例
func NewTransMicropayEncryServer(client *common.Client[TransMicropayEncryResponse]) *TransMicropayEncryServer[TransMicropayEncryResponse] {
return &TransMicropayEncryServer[TransMicropayEncryResponse]{
func NewTransMicropayEncryServer(client *common.Client[TransMicropayEncryResponse]) *TransMicropayEncryServer {
return &TransMicropayEncryServer{
Client: client,
}
}
// TransMicropayEncry 聚合扫码被扫接口(全报文加密)接口
func (a *TransMicropayEncryServer[TransMicropayEncryResponse]) TransMicropayEncry(reqData *TransMicropayEncryRequestData) (*TransMicropayEncryResponse, error) {
func (a *TransMicropayEncryServer) TransMicropayEncry(reqData *TransMicropayEncryRequestData) (*TransMicropayEncryResponse, error) {
// 构建请求体
request := &TransMicropayEncryRequest{
ReqTime: gtime.Now().Format("20060102150405"),

View File

@ -1,17 +1,17 @@
package transPreorder
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
// API 聚合主扫API结构体
// TransPreorderServer 聚合主扫API结构体
type TransPreorderServer struct {
client *common.Client[TransPreorderResponse]
}
// NewAPI 创建聚合主扫API实例
// NewTransPreorderServer 创建聚合主扫API实例
func NewTransPreorderServer(client *common.Client[TransPreorderResponse]) *TransPreorderServer {
return &TransPreorderServer{
client: client,

View File

@ -22,7 +22,7 @@ type ResponseData struct {
PrepayId string `json:"prepay_id,omitempty"` // 预支付交易会话ID
}
// Response 预订单响应结构体
// TransPreorderResponse 预订单响应结构体
type TransPreorderResponse struct {
RespTime string `json:"resp_time"`
Code string `json:"code"`

View File

@ -1,25 +1,25 @@
package transPreorederEncry
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
// TransPreorderEncryServer 聚合扫码主扫交易(全报文加密)服务结构体
type TransPreorderEncryServer[T any] struct {
Client *common.Client[T]
type TransPreorderEncryServer struct {
Client *common.Client[TransPreorederEncryResponse]
}
// NewTransPreorderEncryServer 创建聚合扫码主扫交易(全报文加密)服务实例
func NewTransPreorderEncryServer(client *common.Client[TransPreorederEncryResponse]) *TransPreorderEncryServer[TransPreorederEncryResponse] {
return &TransPreorderEncryServer[TransPreorederEncryResponse]{
func NewTransPreorderEncryServer(client *common.Client[TransPreorederEncryResponse]) *TransPreorderEncryServer {
return &TransPreorderEncryServer{
Client: client,
}
}
// TransPreorderEncry 聚合扫码主扫交易(全报文加密)接口
func (a *TransPreorderEncryServer[TransPreorederEncryResponse]) TransPreorderEncry(reqData *TransPreorederEncryRequestData) (*TransPreorederEncryResponse, error) {
func (a *TransPreorderEncryServer) TransPreorderEncry(reqData *TransPreorederEncryRequestData) (*TransPreorederEncryResponse, error) {
// 构建请求体
request := &TransPreorederEncryRequest{
ReqTime: gtime.Now().Format("20060102150405"),

View File

@ -1,19 +1,19 @@
package transquery
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
// API 聚合扫码交易查询API结构体
type API struct {
type TransQueryServer struct {
Client *common.Client[TransQueryResponse]
}
// NewAPI 创建聚合扫码交易查询API实例
func NewAPI(client *common.Client[TransQueryResponse]) *API {
return &API{
func NewTransQueryServer(client *common.Client[TransQueryResponse]) *TransQueryServer {
return &TransQueryServer{
Client: client,
}
}
@ -23,7 +23,7 @@ func NewAPI(client *common.Client[TransQueryResponse]) *API {
// - termNo: 终端号
// - outTradeNo: 商户交易流水号可选与tradeNo二选一
// - tradeNo: 拉卡拉交易流水号可选与outTradeNo二选一
func (a *API) TransQuery(reqData *TransQueryRequestData) (*TransQueryResponse, error) {
func (a *TransQueryServer) TransQuery(reqData *TransQueryRequestData) (*TransQueryResponse, error) {
// 构建请求结构体
request := &TransQueryRequest{
ReqTime: gtime.Now().Format("YmdHis"),

View File

@ -1,8 +1,8 @@
package transShareCode
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -2,6 +2,7 @@ package consts
const (
BASE_URL = "https://s2.lakala.com/api"
BASE_TEST_URL = "https://test.wsmsd.cn/sit/api"
)
// basePay/labs 基础支付聚合扫码API地址

View File

@ -1,40 +0,0 @@
package unifiedreturn
import (
"context"
"github.com/black1552/lkl_sdk/lklsdk/common"
mergeRefund "github.com/black1552/lkl_sdk/lklsdk/unifiedReturn/mergeRefund"
"github.com/black1552/lkl_sdk/lklsdk/unifiedReturn/refund"
"github.com/black1552/lkl_sdk/lklsdk/unifiedReturn/refundquery"
)
type Server struct {
MergeRefound *mergeRefund.MergeRefund
Refound *refund.Refund
RefoundQuery *refundquery.RefundQuery
}
// NewServer 创建拉卡拉统一退货服务实例
func NewServer(ctx context.Context, cfgJson string) *Server {
return &Server{
MergeRefound: mergeRefund.NewMergeRefund(common.NewClient[mergeRefund.ResponseMergeRefund](ctx, cfgJson)),
Refound: refund.NewRefund(common.NewClient[refund.ResponseRefund](ctx, cfgJson)),
RefoundQuery: refundquery.NewRefundQuery(common.NewClient[refundquery.ResponseRefundQuery](ctx, cfgJson)),
}
}
// MergeRefund 合单退货
func (u *Server) MergeRefund(req *mergeRefund.RequestDataMergeRefund) (*mergeRefund.ResponseMergeRefund, error) {
return u.MergeRefound.MergeRefund(req)
}
// Refund 退货
func (u *Server) Refund(req *refund.RequestDataRefund) (*refund.ResponseRefund, error) {
return u.Refound.Refund(req)
}
// RefundQuery 退货查询
func (u *Server) RefundQuery(req *refundquery.RequestDataRefundQuery) (*refundquery.ResponseRefundQuery, error) {
return u.RefoundQuery.RefundQuery(req)
}

20
sdk.go Normal file
View File

@ -0,0 +1,20 @@
package lklSDK
import (
"context"
"github.com/black1552/lkl_sdk/basePay/labs"
"github.com/black1552/lkl_sdk/unifiedreturn"
)
type SDK struct {
labs *labs.Labs
unifiedReturn *unifiedreturn.Server
}
func NewSDK(ctx context.Context, cfgJson string) *SDK {
return &SDK{
labs: labs.NewLabs(ctx, cfgJson),
unifiedReturn: unifiedreturn.NewServer(ctx, cfgJson),
}
}

View File

@ -1,8 +1,8 @@
package mergerefund
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)
@ -24,3 +24,12 @@ func (t *MergeRefund) MergeRefund(req *RequestDataMergeRefund) (*ResponseMergeRe
}
return t.client.DoRequest(consts.BASE_URL+consts.LKL_UNIFIED_RETURN_MERGE_REFUND_URL, baseReq)
}
func (t *MergeRefund) MergeRefundTest(req *RequestDataMergeRefund) (*ResponseMergeRefund, error) {
// 构建BaseModel请求
baseReq := RequestMergeRefund{
ReqTime: gtime.Now().Format("YmdHis"),
Version: "3.0",
ReqData: req,
}
return t.client.DoRequest(consts.BASE_TEST_URL+consts.LKL_UNIFIED_RETURN_MERGE_REFUND_URL, baseReq)
}

View File

@ -1,8 +1,8 @@
package refund
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -1,8 +1,8 @@
package refundquery
import (
"github.com/black1552/lkl_sdk/common"
"github.com/black1552/lkl_sdk/consts"
"github.com/black1552/lkl_sdk/lklsdk/common"
"github.com/gogf/gf/v2/os/gtime"
)

View File

@ -0,0 +1,25 @@
package unifiedreturn
import (
"context"
"github.com/black1552/lkl_sdk/common"
mergeRefund "github.com/black1552/lkl_sdk/unifiedReturn/mergeRefund"
"github.com/black1552/lkl_sdk/unifiedReturn/refund"
"github.com/black1552/lkl_sdk/unifiedReturn/refundquery"
)
type Server struct {
MergeRefound *mergeRefund.MergeRefund
Refound *refund.Refund
RefoundQuery *refundquery.RefundQuery
}
// NewServer 创建拉卡拉统一退货服务实例
func NewServer(ctx context.Context, cfgJson string) *Server {
return &Server{
MergeRefound: mergeRefund.NewMergeRefund(common.NewClient[mergeRefund.ResponseMergeRefund](ctx, cfgJson)),
Refound: refund.NewRefund(common.NewClient[refund.ResponseRefund](ctx, cfgJson)),
RefoundQuery: refundquery.NewRefundQuery(common.NewClient[refundquery.ResponseRefundQuery](ctx, cfgJson)),
}
}