Files
2025-11-18 17:26:07 +08:00
..
2025-11-18 17:26:07 +08:00
2025-11-18 17:26:07 +08:00
2025-11-18 17:26:07 +08:00
2025-11-18 17:26:07 +08:00

M2Pool API Bridge

这是一个中间 API 服务,用于连接 WordPress 插件和基于 RabbitMQ 的支付系统。

功能

  • 接收 WordPress 插件的 HTTP 请求
  • 将请求转换为 RabbitMQ 消息
  • 监听 RabbitMQ 响应并返回给 WordPress

安装

cd api-bridge
go mod download
go build -o api-bridge main.go

配置

修改 main.go 中的 RabbitMQ 配置:

rmqConfig = RabbitMQConfig{
    URL:      "amqp://m2pool:m2pool@localhost:5672",
    Exchange: "pay.exchange",
    Queues: map[string]string{
        "pay":    "pay.auto.routing.key",
        "topup":  "pay.recharge.routing.key",
        "status": "pay.auto.return.routing.key",
    },
}

运行

./api-bridge

服务将在 http://localhost:8080 启动。

API 接口

创建支付请求

POST /api/payment/create

查询支付状态

GET /api/payment/status/{queue_id}

创建充值请求

POST /api/topup/create

查询充值状态

GET /api/topup/status/{queue_id}

注意事项

当前实现是基础版本,实际使用中需要:

  1. 实现状态缓存Redis 或数据库)
  2. 监听 RabbitMQ 响应队列
  3. 实现签名验证
  4. 添加错误处理和日志记录
  5. 添加认证和授权