tlfs

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 11 Imported by: 0

README

tlfs

tlfs 是通联飞收的 Go SDK,提供:

  • 查询收款单列表
  • 查询收款单表单项
  • 生成收款跳转页 URL

安装

go get github.com/kainonly/tlfs

配置

初始化使用 tlfs.Option

字段 说明
base_url TLFS 服务地址
org_id 组织 ID,可选
app_id 应用 ID
key 签名密钥
seller_id 收款方 ID,用于生成跳转页链接

示例配置:

base_url: https://fstest.allinpaygd.com
org_id:
app_id: your-app-id
key: your-sign-key
seller_id: your-seller-id

快速开始

package main

import (
    "context"
    "fmt"

    "github.com/kainonly/tlfs"
)

func main() {
    client, err := tlfs.NewTlfs(tlfs.Option{
        BaseURL:  "https://fstest.allinpaygd.com",
        OrgID:    "",
        AppID:    "your-app-id",
        Key:      "your-sign-key",
        SellerID: "your-seller-id",
    })
    if err != nil {
        panic(err)
    }

    ctx := context.Background()

    result, err := client.PaymentQuery(ctx, tlfs.NewPaymentQueryDto("your-store-id"))
    if err != nil {
        panic(err)
    }

    for _, item := range result.List {
        fmt.Println(item.PaymentId, item.PaymentName)
    }
}

API

PaymentQuery

查询收款单列表。

PaymentContsQuery

查询收款单表单项。

PayRedirectURL
redirectURL, err := client.PayRedirectURL(&tlfs.PayRedirectURLDto{
    Id:        "your-payment-id",
    SellerId:  "your-seller-id",
    EnterType: "1",
    Amount:    "300",
    FontsMap: []*tlfs.FontsMapItem{
        tlfs.NewFontsMapItem("field-id-1", "value-1"),
        tlfs.NewFontsMapItem("field-id-2", "value-2"),
    },
})

生成收款页面跳转链接。Amount 单位为分,FontsMap 会编码到 URL 查询参数中。

错误处理

HTTP 状态码不是 200,或者上游业务码不是 200 时会返回错误。

测试

  1. 复制 config/values.example.ymlconfig/values.yml
  2. 填入有效的测试环境参数
  3. 执行测试:
go test ./...

当前测试覆盖:

  • 收款单列表查询
  • 收款单表单项查询
  • 收款跳转页 URL 生成

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FontsMapItem

type FontsMapItem struct {
	Id       string `json:"id"`                 // 表单项id
	Value    string `json:"value"`              // 值
	Disabled string `json:"disabled,omitempty"` // 禁用属性
}

func NewFontsMapItem

func NewFontsMapItem(id, value string) *FontsMapItem

func (*FontsMapItem) SetDisabled added in v1.1.0

func (x *FontsMapItem) SetDisabled() *FontsMapItem

type M

type M map[string]any

type Option

type Option struct {
	BaseURL  string `yaml:"base_url"`
	OrgID    string `yaml:"org_id"`
	AppID    string `yaml:"app_id"`
	Key      string `yaml:"key"`
	SellerID string `yaml:"seller_id"`
}

type PayRedirectURLDto

type PayRedirectURLDto struct {
	Id        string          `json:"id"`                 // 收款单id
	SellerId  string          `json:"sellerId"`           // 收款人Id
	EnterType string          `json:"enterType"`          // 类型
	Amount    string          `json:"amount"`             // 金额(分为单位)
	FontsMap  []*FontsMapItem `json:"fontsMap,omitempty"` // 表单数据
}

type PaymentContsQueryCont

type PaymentContsQueryCont struct {
	ID                string `json:"id"`
	Name              string `json:"name"`              // 信息项名称
	Type              string `json:"type"`              // 类型
	Sort              int    `json:"sort"`              // 排序
	Tip               string `json:"tip,omitempty"`     // 提示信息
	Descr             string `json:"descr,omitempty"`   // 字段描述
	Data              string `json:"data,omitempty"`    // 选项值
	Value             string `json:"value,omitempty"`   // 默认值
	Deposit           int64  `json:"deposit,omitempty"` // 商品押金,单位分
	SearchRequired    int    `json:"searchrequired,omitempty"`
	ReceivedRequired  int    `json:"receivedRequired,omitempty"`
	FoldRequired      int    `json:"foldRequired,omitempty"`
	MulPickerRequired int    `json:"mulPickerRequired,omitempty"`
	SmsCodeRequired   int    `json:"smsCodeRequired,omitempty"`
	RequireDeposit    int    `json:"requireDeposit,omitempty"`
	ScanRequired      int    `json:"scanRequired,omitempty"`
	FixAmountRequired int    `json:"fixAmountRequired,omitempty"`
	Desensitized      int    `json:"desensitized,omitempty"`
}

type PaymentContsQueryDto

type PaymentContsQueryDto struct {
	StoreId   string `json:"storeId"`   // 门店唯一标识
	PaymentId string `json:"paymentId"` // 门店收款单唯一标识
}

func NewPaymentContsQueryDto

func NewPaymentContsQueryDto(storeId string, paymentId string) *PaymentContsQueryDto

type PaymentContsQueryResult

type PaymentContsQueryResult struct {
	StoreId   string                  `json:"storeId"`   // 门店唯一标识
	PaymentId string                  `json:"paymentId"` // 收款单唯一标识
	Conts     []PaymentContsQueryCont `json:"conts"`     // 收款单信息列表
}

type PaymentQueryDto

type PaymentQueryDto struct {
	StoreId string `json:"storeId"` // 门店唯一标识
}

func NewPaymentQueryDto

func NewPaymentQueryDto(storeId string) *PaymentQueryDto

type PaymentQueryList

type PaymentQueryList struct {
	StoreId     string `json:"storeId"`     // 门店唯一标识
	PaymentId   string `json:"paymentId"`   // 收款单唯一标识
	PaymentName string `json:"paymentName"` // 收款单名称
	DataStatus  string `json:"dataStatus"`  // 收款单状态
	Type        string `json:"type"`        // 收款单类型
	CreatedDate string `json:"createdDate"` // 创建时间
}

type PaymentQueryResult

type PaymentQueryResult struct {
	List []PaymentQueryList `json:"list"`
}

type ResponseBody

type ResponseBody[T any] struct {
	Code string `json:"code"`           // 调用结果返回码
	Msg  string `json:"msg"`            // 调用结果返回码描述
	Sign string `json:"sign,omitempty"` // 商户请求参数的签名串
	Data T      `json:"data,omitempty"` // 返回参数的集合
}

type Tlfs

type Tlfs struct {
	Option *Option
	Client *resty.Client
}

func NewTlfs

func NewTlfs(opt Option) (x *Tlfs, err error)

func (*Tlfs) GetNow

func (x *Tlfs) GetNow(ctx context.Context) time.Time

func (*Tlfs) PayRedirectURL

func (x *Tlfs) PayRedirectURL(dto *PayRedirectURLDto) (_ string, err error)

func (*Tlfs) PaymentContsQuery

func (x *Tlfs) PaymentContsQuery(ctx context.Context, dto *PaymentContsQueryDto) (_ *PaymentContsQueryResult, err error)

func (*Tlfs) PaymentQuery

func (x *Tlfs) PaymentQuery(ctx context.Context, dto *PaymentQueryDto) (_ *PaymentQueryResult, err error)

func (*Tlfs) Request

func (x *Tlfs) Request(ctx context.Context, path string, content string) (_ []byte, err error)

func (*Tlfs) SetNow

func (x *Tlfs) SetNow(ctx context.Context, ts time.Time) context.Context

func (*Tlfs) Sign

func (x *Tlfs) Sign(params map[string]string) (sign string, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL