# SrunPayment **Repository Path**: zhanglianfeng/srun-payment ## Basic Information - **Project Name**: SrunPayment - **Description**: GO 集成种种支付方式的 package - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-01-26 - **Last Updated**: 2026-01-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # srun-payment 通用支付网关 Go SDK,支持迪科支付平台及多种支付方式接入。 ## 特性 - 统一的支付网关接口,便于切换不同支付平台 - 支持迪科支付平台(预下单、订单查询、票据查询、换票申请) - 内置 3DES 加密和 RSA 签名 - 支持异步通知和同步跳转解析 - 工厂模式,便于扩展其他支付网关 ## 安装 ```bash go get gitee.com/zhanglianfeng/srun-payment ``` 本地开发时,可在 `go.mod` 中使用 replace: ```go replace gitee.com/zhanglianfeng/srun-payment => ../gopacket/srun-payment ``` ## 快速开始 ```go package main import ( "context" "fmt" "log" payment "gitee.com/zhanglianfeng/srun-payment" _ "gitee.com/zhanglianfeng/srun-payment/dike" // 自动注册迪科网关 ) func main() { // 1. 创建配置 cfg := &payment.Config{ BaseURL: "https://pay.example.com", PartnerID: "PT0001", SchoolCode: "10019", ProjectID: "your-project-id", DesKey: "your-des-key-base64", PrivateKey: `-----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----`, PublicKey: `-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----`, NotifyURL: "https://your-server.com/pay/notify", ReturnURL: "https://your-server.com/pay/return", } // 2. 创建网关实例 gateway, err := payment.NewGateway(payment.GatewayTypeDike, cfg) if err != nil { log.Fatal(err) } // 3. 预下单 ctx := context.Background() resp, err := gateway.CreateOrder(ctx, &payment.CreateOrderRequest{ JourNo: "ORDER_20240101_001", Amount: 10000, // 100 元(单位:分) IDSerial: "stu001", Username: "张三", ProductDesc: "网费充值", ClientType: payment.ClientTypeWap, }) if err != nil { log.Fatal(err) } if resp.Success { fmt.Println("收银台URL:", resp.CashierURL) } else { fmt.Println("下单失败:", resp.Message) } } ``` ## 支持的支付方式 | 代码 | 支付方式 | |------|----------| | 01 | 支付宝 | | 02 | 微信支付 | | 03 | 绑定银行卡 | | 04 | 翼支付 | | 05 | 银联 | | 06 | 电子账户 | | 07 | 开普支付 | | 08 | 建行网银 | | 09 | 中信微信支付 | | 11 | 中行跨行付 | ## API 文档 ### Gateway 接口 ```go type Gateway interface { // CreateOrder 预下单,返回收银台URL CreateOrder(ctx context.Context, req *CreateOrderRequest) (*CreateOrderResponse, error) // QueryOrder 查询订单状态 QueryOrder(ctx context.Context, req *QueryOrderRequest) (*QueryOrderResponse, error) // QueryInvoiceStatus 查询票据状态 QueryInvoiceStatus(ctx context.Context, req *QueryInvoiceRequest) (*QueryInvoiceResponse, error) // ApplyInvoiceChange 换票申请 ApplyInvoiceChange(ctx context.Context, req *InvoiceChangeRequest) (*InvoiceChangeResponse, error) // ParseNotify 解析异步通知 ParseNotify(data []byte) (*NotifyResult, error) // ParseReturn 解析同步跳转 ParseReturn(data []byte) (*NotifyResult, error) } ``` ### 处理异步通知(Gin 示例) ```go func handleNotify(c *gin.Context) { body, _ := io.ReadAll(c.Request.Body) result, err := gateway.ParseNotify(body) if err != nil { c.String(200, "fail") return } if result.Success { // 处理支付成功逻辑 // - 更新订单状态 // - 记录支付流水 // - 触发后续业务 c.String(200, "success") } else { c.String(200, "fail") } } ``` ## 扩展其他支付网关 ```go // 实现 Gateway 接口 type MyGateway struct {} func (g *MyGateway) CreateOrder(ctx context.Context, req *payment.CreateOrderRequest) (*payment.CreateOrderResponse, error) { // 实现逻辑 } // ... 实现其他方法 // 注册网关 func init() { payment.RegisterGateway("my-gateway", func(cfg *payment.Config) (payment.Gateway, error) { return &MyGateway{}, nil }) } ``` ## 目录结构 ``` srun-payment/ ├── go.mod ├── README.md ├── gateway.go # 统一接口定义 ├── config.go # 配置结构 ├── types.go # 公共类型 ├── errors.go # 错误定义 ├── crypto/ │ ├── des3.go # 3DES 加密 │ └── rsa.go # RSA 签名 ├── dike/ # 迪科支付实现 │ ├── client.go │ ├── types.go │ └── callback.go └── examples/ └── basic/main.go ``` ## License MIT