Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e1e22cebb | ||
|
|
9cfd4b6e1c | ||
|
|
8c4ead0169 | ||
|
|
2992a1f032 | ||
|
|
9e7707588f | ||
|
|
0db728dc52 | ||
|
|
6a2f3b6d6e | ||
|
|
e906090ba6 | ||
|
|
077070b2cb | ||
|
|
fff616c9d0 | ||
|
|
19504a7e2b | ||
|
|
0ed85860fc | ||
|
|
e7e1cae418 | ||
|
|
69bf33e06a | ||
|
|
ae4ed8f88e | ||
|
|
112584b850 | ||
|
|
7d926f4dae | ||
|
|
f966b31324 | ||
|
|
cd656eb455 | ||
|
|
7448512a97 | ||
|
|
84b3a81daa | ||
|
|
13388f197d | ||
|
|
0185003c19 | ||
|
|
27382565de | ||
|
|
0c175e3c82 | ||
|
|
a9a94a1413 | ||
|
|
8478d47abf | ||
|
|
a3c2693417 | ||
|
|
ec98e9d54b | ||
|
|
41f29e2c77 | ||
|
|
2e1aa7e44f | ||
|
|
b1785e047f | ||
|
|
28c9b6a923 | ||
|
|
3ecd0fcfa6 | ||
|
|
a0e5cc2790 | ||
|
|
c3140ccb32 | ||
|
|
cf0b09bf0f | ||
|
|
30457a71f5 | ||
|
|
ee63905620 | ||
|
|
953eb29877 | ||
|
|
5957b01401 | ||
|
|
f0cc80f368 | ||
|
|
bdce931178 | ||
|
|
9844fc277d | ||
|
|
f39929eab7 | ||
|
|
5176296506 | ||
|
|
e303768e08 | ||
|
|
d780dafc13 | ||
|
|
9c0f9e821d | ||
|
|
35cb4b847d | ||
|
|
534030bd2f | ||
|
|
858255fd94 | ||
|
|
c953a4a8a1 | ||
|
|
52b59bd609 | ||
|
|
d9605819e3 | ||
|
|
a6a77d84c9 | ||
|
|
1a91691eec | ||
|
|
6616232310 | ||
|
|
804da832bd | ||
|
|
0266e2be53 | ||
|
|
cf39f86361 | ||
|
|
e686b6cca0 | ||
|
|
ed5016be7b | ||
|
|
5a6be1c254 | ||
|
|
39c638e4ed | ||
|
|
3c0d765744 | ||
|
|
9e504853a3 | ||
|
|
21f45a79ba | ||
|
|
d6fb979267 | ||
|
|
f01dd47f7a | ||
|
|
1c6152f568 | ||
|
|
0e4ad019d4 | ||
|
|
a73b4e4737 | ||
|
|
062e61d6a5 | ||
|
|
bc7bced817 | ||
|
|
f7f308c639 | ||
|
|
8043da9eae | ||
|
|
3541cc02c6 | ||
|
|
5ee68958ce | ||
|
|
ab4661259f | ||
|
|
c4644e5615 | ||
|
|
6c03dab7c8 | ||
|
|
bdf6fab368 | ||
|
|
f5042b7799 | ||
|
|
3eaaf486e1 | ||
|
|
07b4fdb559 | ||
|
|
f38ad4943f | ||
|
|
9d1daeddbd | ||
|
|
9f2781cafd | ||
|
|
f334e42c83 | ||
|
|
54054d7866 | ||
|
|
669c47974d | ||
|
|
3c5f50e868 | ||
|
|
9ceff67d55 | ||
|
|
9c9100e65a | ||
|
|
f0f79846bc | ||
|
|
4062bbaf2a | ||
|
|
b6f60828bb | ||
|
|
2f62445f0f | ||
|
|
5862eb4e65 | ||
|
|
ddabbc4c81 | ||
|
|
58e38efe21 | ||
|
|
f944e34d81 | ||
|
|
8de86a2bf2 | ||
|
|
ee7a184a8f | ||
|
|
ee8c1579b9 | ||
|
|
f6bbc0ef76 | ||
|
|
a610af3277 | ||
|
|
dae2ced03d | ||
|
|
fff21291ec | ||
|
|
ef4b3293b3 | ||
|
|
0ef030caa7 | ||
|
|
6d43269ac1 |
@@ -0,0 +1,14 @@
|
||||
# 监听地址,格式为 ip:port,例如 :8080
|
||||
LISTEN=127.0.0.1:8080
|
||||
|
||||
# 日志文件保存路径
|
||||
LOG=/var/log/bepusdt/
|
||||
|
||||
# SQLite 数据库文件路径(如果使用 MySQL,此项可忽略)
|
||||
SQLITE=/var/lib/bepusdt/sqlite.db
|
||||
|
||||
# MySQL 数据库
|
||||
# MYSQL_DSN=user:password@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s&readTimeout=10s&writeTimeout=10s
|
||||
|
||||
# PostgreSQL 数据库
|
||||
# POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3
|
||||
@@ -0,0 +1,55 @@
|
||||
name: BUG 反馈|使用异常|功能建议|其它问题
|
||||
description: "提交在使用 BEpusdt 过程中遇到的 BUG 反馈、使用异常、对接失败等问题"
|
||||
body:
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: 完整性要求
|
||||
description: |-
|
||||
请勾选以下所有选项以证明您已经阅读并理解了以下要求,否则该 issue 将被关闭。
|
||||
options:
|
||||
- label: 我保证阅读了相关文档和 FAQ,确认问题不是由于误解功能或配置错误引起的。
|
||||
required: true
|
||||
- label: 我提供了完整环境和日志信息,而不是出于自己的判断只给出截取的部分。
|
||||
required: true
|
||||
- label: 我搜索了 issues, 没有发现已提出的类似问题。
|
||||
required: true
|
||||
- label: 问题在 Release 最新的版本上可以成功复现
|
||||
required: true
|
||||
- label: 我理解如果没有提供足够的信息,维护者可以直接关闭该 issue,而不需要进一步的解释。
|
||||
required: true
|
||||
- label: 我明白任何人针对我提交的问题没有义务提供帮助,包括项目维护者。
|
||||
required: true
|
||||
- label: 我没有阅读这个清单,只是闭眼选中了所有的复选框,请关闭这个 Issue 。
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: 问题类型
|
||||
description: 请选择您遇到的问题类型
|
||||
options:
|
||||
- BUG 反馈
|
||||
- 使用异常
|
||||
- 对接失败
|
||||
- 功能建议
|
||||
- 其它问题
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: 报告描述
|
||||
description: |-
|
||||
请提供问题的详细描述。以及你认为有价值的信息。
|
||||
如果问题在更新后出现,请提供**具体**出现问题的版本号。
|
||||
validations:
|
||||
required: true
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |-
|
||||
## 日志信息
|
||||
默认的日志目录在 `/var/log/bepusdt/` 下,请将相关时间段的日志内容粘贴在下面的代码块中。
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: 日志内容
|
||||
description: 请粘贴对应的日志信息,如果有的话
|
||||
placeholder: |
|
||||
请在这里粘贴日志内容...
|
||||
render: shell
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Telegram Group
|
||||
url: https://t.me/BEpusdtChat
|
||||
about: Telegram 交流群组
|
||||
@@ -14,9 +14,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
ref: 'main'
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
@@ -27,7 +29,9 @@ jobs:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Generate App Version
|
||||
run: echo APP_VERSION=`grep -o 'Version = "[^"]*"' ./app/version.go | cut -d'"' -f2` >> $GITHUB_ENV
|
||||
run: |
|
||||
echo "APP_VERSION=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
|
||||
echo "VERSION_TAG=$(git describe --tags --abbrev=0)-$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
@@ -37,8 +41,7 @@ jobs:
|
||||
linux/arm64
|
||||
push: true
|
||||
build-args: |
|
||||
APP_NAME=${{ env.APP_NAME }}
|
||||
APP_VERSION=${{ env.APP_VERSION }}
|
||||
VERSION=${{ env.VERSION_TAG }}
|
||||
tags: |
|
||||
${{ env.DOCKERHUB_REPO }}:latest
|
||||
${{ env.DOCKERHUB_REPO }}:${{ env.APP_VERSION }}
|
||||
@@ -12,9 +12,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
ref: 'main'
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
@@ -26,8 +28,9 @@ jobs:
|
||||
password: ${{ secrets.DOCKER_HUB_BETA_TOKEN }}
|
||||
- name: Generate App Version
|
||||
run: |
|
||||
echo "APP_VERSION=$(git rev-parse HEAD | cut -c 1-6)" >> $GITHUB_ENV
|
||||
echo "APP_VERSION=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
|
||||
echo "APP_DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
|
||||
echo "VERSION_TAG=$(git describe --tags --abbrev=0)-nightly-$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
@@ -39,8 +42,7 @@ jobs:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
APP_NAME=${{ env.APP_NAME }}
|
||||
APP_VERSION=${{ env.APP_VERSION }}
|
||||
VERSION=${{ env.VERSION_TAG }}
|
||||
tags: |
|
||||
${{ env.DOCKER_HUB_REPO }}:nightly
|
||||
${{ env.DOCKER_HUB_REPO }}:nightly-${{ env.APP_DATE }}-${{ env.APP_VERSION }}
|
||||
|
||||
@@ -11,9 +11,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
ref: 'main'
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
- name: Git Fetch Tags
|
||||
run: git fetch --force --tags
|
||||
- name: Set up Node.js
|
||||
@@ -32,6 +34,9 @@ jobs:
|
||||
run: |
|
||||
mkdir -p static/secure
|
||||
cp -r web/dist/* static/secure/
|
||||
- name: Generate App Version
|
||||
run: |
|
||||
echo "VERSION_TAG=$(git describe --tags --abbrev=0)-$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
@@ -43,4 +48,5 @@ jobs:
|
||||
version: latest
|
||||
args: release --clean --verbose
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
VERSION: ${{ env.VERSION_TAG }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
tmp
|
||||
.air.toml
|
||||
.DS_Store
|
||||
.env
|
||||
.idea
|
||||
conf.toml
|
||||
# Added by goreleaser init:
|
||||
dist/
|
||||
static/web
|
||||
*.log
|
||||
@@ -8,6 +8,7 @@ builds:
|
||||
main: ./main
|
||||
binary: bepusdt
|
||||
ldflags:
|
||||
- -X '{{ .ModulePath }}/app.Version={{ .Env.VERSION }}'
|
||||
- -s -w -buildid=
|
||||
goos:
|
||||
- windows
|
||||
@@ -23,8 +24,7 @@ archives:
|
||||
- goos: windows
|
||||
formats: [ zip ]
|
||||
files:
|
||||
- conf.example.toml
|
||||
- conf.simple.toml
|
||||
- .env.example
|
||||
- src: docs/bepusdt.service
|
||||
dst: .
|
||||
strip_parent: true
|
||||
|
||||
@@ -19,8 +19,13 @@ ADD . .
|
||||
|
||||
COPY --from=web_builder /web/dist ./static/secure
|
||||
|
||||
ARG VERSION=unknown
|
||||
|
||||
RUN set -x \
|
||||
&& CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -buildid=" -o bepusdt ./main
|
||||
&& MODULE_PATH=$(go list -m) \
|
||||
&& CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags="-X '${MODULE_PATH}/app.Version=${VERSION}' -s -w -buildid=" \
|
||||
-o bepusdt ./main
|
||||
|
||||
FROM alpine:3.20
|
||||
|
||||
|
||||
@@ -7,19 +7,29 @@
|
||||
# BEpusdt (Better Easy Payment USDT)
|
||||
|
||||
<p align="center">
|
||||
<img src="./static/payment/static/img/tether.svg" width="15%" alt="tether">
|
||||
<img src="./static/payment/assets/img/tether.svg" width="15%" alt="tether">
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLV3-blue" alt="license GPLV3"></a>
|
||||
<a href="https://golang.org"><img src="https://img.shields.io/badge/Golang-1.23-red" alt="Go version 1.23"></a>
|
||||
<a href="https://github.com/gin-gonic/gin"><img src="https://img.shields.io/badge/Gin-v1.9-blue" alt="Gin Web Framework v1.9"></a>
|
||||
<a href="https://github.com/go-telegram/bot"><img src="https://img.shields.io/badge/Go_Telegram_Bot-v1.15-blue" alt="Golang Telegram Bot"></a>
|
||||
<a href="https://github.com/v03413/bepusdt"><img src="https://img.shields.io/github/v/release/v03413/bepusdt" alt="Release v1.19.1"></a>
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html">
|
||||
<img src="https://img.shields.io/github/license/v03413/bepusdt" alt="license GPLV3">
|
||||
</a>
|
||||
<a href="https://github.com/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/github/v/release/v03413/bepusdt" alt="GitHub Release">
|
||||
</a>
|
||||
<a href="https://github.com/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/github/downloads/v03413/bepusdt/total" alt="GitHub Release">
|
||||
</a>
|
||||
<a href="https://hub.docker.com/r/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/docker/pulls/v03413/bepusdt?style=flat-square&logo=docker" alt="Docker Pulls">
|
||||
</a>
|
||||
<a href="https://github.com/gin-gonic/gin">
|
||||
<img src="https://img.shields.io/github/stars/v03413/bepusdt?style=flat-square&logo=github" alt="GitHub Stars">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## 🪧 介绍
|
||||
|
||||
**缘起于`Epusdt`,但不仅限于此,加入了一些新特性,致力于成为一款更好用的个人`加密货币`收款网关。**
|
||||
缘起于`Epusdt`,但不仅限于此,加入了一些新特性,致力于成为一款更好用的个人`加密货币`收款网关。
|
||||
|
||||
## 🎉 新特性
|
||||
|
||||
@@ -30,37 +40,44 @@
|
||||
|
||||
- ✅ 完全兼容 `Epusdt` 插件无缝替换
|
||||
- ️✅ 支持主流区块网络 不仅限于`USDT`
|
||||
- ✅ 支持主流法定货币 汇率自动更新同步
|
||||
- ✅ 无`MySQL Redis`依赖 支持`Docker`部署
|
||||
- ✅ 支持非订单交易监控 钱包余额变动通知
|
||||
- ✅ 支持自定义`USDT`支付精度与递增颗粒度
|
||||
- ✅ 底层区块扫描 提升订单确认速度与稳定性
|
||||
- ✅ 支持波场能量代理与能量回收监控通知
|
||||
- ✅ 原生兼容`易支付`收单接口 快捷接入
|
||||
- ✅ 支持创建订单 自定义地址 超时时长等
|
||||
- ✅ 完整支持`等待支付 支付超时`回调通知
|
||||
- ✅ 完整独立WEB后台 方便配置统计管理
|
||||
- ✅ 默认收银员支持中英切换 助力出海需求
|
||||
- ✅ 支持主流法定货币 汇率自动更新
|
||||
- ✅ 轻依赖 单体二进制文件 部署便捷
|
||||
- ✅ 支持非订单交易监控 余额变动通知
|
||||
- ✅ 支持自定义支付精度与递增颗粒度
|
||||
- ✅ 底层区块扫描 安全确认 速度稳定
|
||||
- ✅ 支持波场能量代理 回收实时监控
|
||||
- ✅ 原生兼容`易支付`收单 接入便捷
|
||||
- ✅ 完整独立WEB后台 方便配置管理
|
||||
- ✅ 收银台支持中英适配 助力出海需求
|
||||
- ✅ 快速迭代期 超多实用特性功能等你发现
|
||||
|
||||
## 🚀 安装部署
|
||||
## 🚀 快捷启动
|
||||
|
||||
- 安装:[Docker](docs/docker/docker.md)·[Linux](docs/linux/install.md)·[1Panel](./docs/1panel/README.md)·[宝塔](./docs/bt_panel/README.md)
|
||||
- 对接:[独角数卡](docs/dujiaoka/dujiaoka.md)·[异次元](./docs/acg-faka.md)·[萌次元](./docs/mcy-shop.md)·[彩虹易支付](https://github.com/v03413/Epay-BEpusdt)
|
||||
- 开发:[API对接](docs/api/api.md)·[订单回调](docs/notify/readme.md)·[Python SDK](https://github.com/luoyanglang/bepusdt-python-sdk)
|
||||
- 其它:[https 配置](./docs/ssl.md)·[时钟同步](docs/linux/systemd-timesyncd.md)·[自定义收银台](./docs/template/README.md)
|
||||
Docker 快速启动,执行完命令打开地址`http://服务器IP:8080`即可看到初始页面
|
||||
|
||||
```bash
|
||||
docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
|
||||
```
|
||||
## 📃 技术文档
|
||||
|
||||
- 安装:[Docker](docs/docker/docker.md) [Linux](docs/linux/install.md) [1Panel](./docs/1panel/README.md) [宝塔](./docs/bt_panel/README.md)
|
||||
- 开发:[API对接](docs/api/api.md) [订单回调](docs/notify/readme.md) [Python](https://github.com/luoyanglang/bepusdt-python-sdk) [PHP](https://github.com/v03413/bepusdt-php-sdk)
|
||||
- 对接:[独角数卡](docs/api/dujiaoka/dujiaoka.md) [彩虹易支付](https://github.com/v03413/Epay-BEpusdt) [whmcs](https://github.com/v03413/whmcs-gateway-epusdt) [其它](docs/api/other.md)
|
||||
- 其它:[https 配置](./docs/ssl.md) [时钟同步](docs/linux/systemd-timesyncd.md) [收银台修改](docs/payment-template/README.md)
|
||||
|
||||
## 🖼 功能截图
|
||||
|
||||
|
||||
| 前台收银 | 后台订单 | Telegram 通知 |
|
||||
|-------------------------------------------------|--------------------------------------------------|--------------------------------------------------------|
|
||||
| <img src=./docs/images/1.png alt=收银台 width=300> | <img src=./docs/images/2.png alt=后台订单 width=300> | <img src=./docs/images/3.png alt=Telegram通知 width=300> |
|
||||
|
||||
## ❓ 常见问题
|
||||
|
||||
- [服务器宽带占用过大解释](./docs/faq/bandwidth.md)
|
||||
- [服务器配置性能选型推荐 ⚡️](./docs/faq/server.md)
|
||||
- [服务器流量消耗说明解释](./docs/faq/bandwidth.md)
|
||||
- [后台入口账密忘记重置教程](./docs/faq/login-reset.md)
|
||||
- [Telegram 通知 Chat ID 获取教程](docs/faq/telegram-chat-id.md)
|
||||
- [推荐配置提高 Tron 扫块稳定性‼️](./docs/tron-grid/readme.md)
|
||||
|
||||
## ⚠️ 重要提示
|
||||
|
||||
|
||||
@@ -2,20 +2,37 @@ package cmd
|
||||
|
||||
import "github.com/urfave/cli/v3"
|
||||
|
||||
var SQLiteLogFlag = &cli.StringFlag{
|
||||
Name: "sqlite",
|
||||
Value: "/var/lib/bepusdt/sqlite.db",
|
||||
Usage: "SQLite 数据库文件路径",
|
||||
var SQLiteFlag = &cli.StringFlag{
|
||||
Name: "sqlite",
|
||||
Value: "/var/lib/bepusdt/sqlite.db",
|
||||
Usage: "SQLite 数据库文件路径",
|
||||
Sources: cli.EnvVars("SQLITE"),
|
||||
}
|
||||
|
||||
var MySQLDSNFlag = &cli.StringFlag{
|
||||
Name: "mysql",
|
||||
Value: "",
|
||||
Usage: "MySQL 数据库连接字符串 (DSN),例如: user:password@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s&readTimeout=10s&writeTimeout=10s",
|
||||
Sources: cli.EnvVars("MYSQL_DSN"),
|
||||
}
|
||||
|
||||
var PostgresDSNFlag = &cli.StringFlag{
|
||||
Name: "postgres",
|
||||
Value: "",
|
||||
Usage: "PostgreSQL 数据库连接字符串 (DSN),例如: postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3",
|
||||
Sources: cli.EnvVars("POSTGRESQL_DSN"),
|
||||
}
|
||||
|
||||
var LogFlag = &cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "/var/log/bepusdt/",
|
||||
Usage: "日志文件保存路径",
|
||||
Name: "log",
|
||||
Value: "/var/log/bepusdt/",
|
||||
Usage: "日志文件保存路径",
|
||||
Sources: cli.EnvVars("LOG"),
|
||||
}
|
||||
|
||||
var ListenFlag = &cli.StringFlag{
|
||||
Name: "listen",
|
||||
Value: ":8080",
|
||||
Usage: "监听地址,格式为 ip:port,例如 :8080",
|
||||
Name: "listen",
|
||||
Value: ":8080",
|
||||
Usage: "监听地址,格式为 ip:port,例如 :8080",
|
||||
Sources: cli.EnvVars("LISTEN"),
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ import (
|
||||
var Reset = &cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "忘记密码时,此命令可重置账号密码登录入口",
|
||||
Flags: []cli.Flag{SQLiteLogFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
if err := model.Init(c.String("sqlite")); err != nil {
|
||||
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,12 @@ import (
|
||||
var Start = &cli.Command{
|
||||
Name: "start",
|
||||
Usage: "启动收款网关",
|
||||
Flags: []cli.Flag{SQLiteLogFlag, LogFlag, ListenFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag, LogFlag, ListenFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
if err := model.Init(c.String("sqlite")); err != nil {
|
||||
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ const (
|
||||
const (
|
||||
UsdtErc20 = "0xdac17f958d2ee523a2206206994597c13d831ec7"
|
||||
UsdtBep20 = "0x55d398326f99059ff775485246999027b3197955"
|
||||
UsdtXlayer = "0x1e4a5963abfd975d8c9021ce480b42188849d41d"
|
||||
UsdtXlayer = "0x779ded0c9e1022225f8e0630b35a9b54be713736"
|
||||
UsdtPlasma = "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb"
|
||||
UsdtPolygon = "0xc2132d05d31c914a87c6611c10748aeb04b58e8f"
|
||||
UsdtArbitrum = "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"
|
||||
UsdtSolana = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
|
||||
@@ -44,6 +45,7 @@ const (
|
||||
UsdtBscDecimals = -18 // USDT BEP20小数位数
|
||||
UsdtEthDecimals = -6 // USDT ERC20小数位数
|
||||
UsdtXlayerDecimals = -6 // USDT Xlayer小数位数
|
||||
UsdtPlasmaDecimals = -6 // USDT Plasma小数位数
|
||||
UsdtPolygonDecimals = -6 // USDT Polygon小数位数
|
||||
UsdtArbitrumDecimals = -6 // USDT Arbitrum小数位数
|
||||
UsdtAptosDecimals = -6 // USDT Aptos小数位数
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package conf
|
||||
|
||||
const (
|
||||
Secret = "BEpusdt, a more user-friendly personal cryptocurrency payment gateway!"
|
||||
AdminTokenK = "admin_token"
|
||||
AdminSecureK = "admin_secure"
|
||||
)
|
||||
|
||||
@@ -9,9 +9,10 @@ const maxRecords = 1000
|
||||
|
||||
type stat struct {
|
||||
mu sync.RWMutex
|
||||
records []bool // true表示成功,false表示失败
|
||||
index int // 当前写入位置
|
||||
count int // 已记录的总数(最多maxRecords)
|
||||
records []bool
|
||||
index int // 当前位置
|
||||
total int // 已记录总数
|
||||
succ int // 成功记录数
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -30,10 +31,16 @@ func RecordSuccess(net string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.total >= maxRecords && !s.records[s.index] {
|
||||
s.succ++
|
||||
} else if s.total < maxRecords {
|
||||
s.succ++
|
||||
}
|
||||
|
||||
s.records[s.index] = true
|
||||
s.index = (s.index + 1) % maxRecords
|
||||
if s.count < maxRecords {
|
||||
s.count++
|
||||
if s.total < maxRecords {
|
||||
s.total++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +49,14 @@ func RecordFailure(net string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.total >= maxRecords && s.records[s.index] {
|
||||
s.succ--
|
||||
}
|
||||
|
||||
s.records[s.index] = false
|
||||
s.index = (s.index + 1) % maxRecords
|
||||
if s.count < maxRecords {
|
||||
s.count++
|
||||
if s.total < maxRecords {
|
||||
s.total++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,16 +65,9 @@ func GetSuccessRate(net string) string {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
if s.count == 0 {
|
||||
if s.total == 0 {
|
||||
return "100.00%"
|
||||
}
|
||||
|
||||
successCount := 0
|
||||
for i := 0; i < s.count; i++ {
|
||||
if s.records[i] {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f%%", float64(successCount)/float64(s.count)*100)
|
||||
return fmt.Sprintf("%.2f%%", float64(s.succ)/float64(s.total)*100)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (Conf) Del(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
model.Db.Where("`k` = ?", req.Key).Delete(&model.Conf{})
|
||||
model.Db.Where("k = ?", req.Key).Delete(&model.Conf{})
|
||||
|
||||
base.Ok(ctx, "删除成功")
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (Conf) Gets(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
var items = make([]model.Conf, 0)
|
||||
model.Db.Where("`k` IN ?", req.Keys).Find(&items)
|
||||
model.Db.Where("k IN ?", req.Keys).Find(&items)
|
||||
|
||||
var data = gin.H{}
|
||||
for _, item := range items {
|
||||
@@ -119,7 +119,7 @@ func (Conf) Sets(ctx *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
model.Db.Where("`k` IN ?", keys).Delete(&model.Conf{})
|
||||
model.Db.Where("k IN ?", keys).Delete(&model.Conf{})
|
||||
model.Db.Create(&data)
|
||||
|
||||
defer model.RefreshC()
|
||||
@@ -136,7 +136,7 @@ func (Conf) Notifier(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
var keys = []string{string(model.NotifierChannel), string(model.NotifierParams)}
|
||||
model.Db.Where("`k` IN ?", keys).Delete(&model.Conf{})
|
||||
model.Db.Where("k IN ?", keys).Delete(&model.Conf{})
|
||||
model.Db.Create(&[]model.Conf{
|
||||
{K: model.NotifierChannel, V: req.Channel},
|
||||
{K: model.NotifierParams, V: string(req.Params)},
|
||||
|
||||
@@ -4,8 +4,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/v03413/bepusdt/app/handler/base"
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
"github.com/v03413/bepusdt/app/task/notify"
|
||||
"github.com/v03413/bepusdt/app/utils"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
@@ -30,6 +33,70 @@ type paidReq struct {
|
||||
RefHash string `json:"ref_hash"`
|
||||
}
|
||||
|
||||
type createReq struct {
|
||||
Amount float64 `json:"amount" binding:"required"`
|
||||
OrderID string `json:"order_id" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Fiat model.Fiat `json:"fiat"`
|
||||
Currencies string `json:"currencies"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
func (Order) Create(ctx *gin.Context) {
|
||||
var req createReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
base.Response(ctx, 400, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
host := utils.GetRequestHost(ctx.Request)
|
||||
|
||||
// 创建待付款订单
|
||||
order, err := model.BuildPendingOrder(model.OrderParams{
|
||||
Money: decimal.NewFromFloat(req.Amount),
|
||||
ApiType: model.OrderApiTypeAdmin, // 使用 Admin 类型
|
||||
OrderId: req.OrderID,
|
||||
Name: req.Name,
|
||||
Timeout: req.Timeout,
|
||||
Fiat: req.Fiat,
|
||||
CurrencyLimit: req.Currencies,
|
||||
})
|
||||
if err != nil {
|
||||
base.Response(ctx, 400, gin.H{
|
||||
"status": "failed",
|
||||
"message": "failed to create order: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// NotifyURL RedirectURL 同为付款链接
|
||||
url := model.CheckoutCashier(host, order.TradeId)
|
||||
|
||||
// Update order with generated URLs
|
||||
hostUri := model.GetK(model.ApiAppUri)
|
||||
if hostUri == "" {
|
||||
hostUri = host
|
||||
}
|
||||
order.NotifyUrl = hostUri + "/api/v1/pay/notify"
|
||||
order.ReturnUrl = url
|
||||
|
||||
if err := model.Db.Save(&order).Error; err != nil {
|
||||
base.Response(ctx, 400, gin.H{
|
||||
"status": "failed",
|
||||
"message": "failed to update order urls: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回响应数据
|
||||
base.Response(ctx, 200, gin.H{
|
||||
"status": "success",
|
||||
"message": "order created",
|
||||
"payment_url": url,
|
||||
})
|
||||
}
|
||||
|
||||
func (Order) List(ctx *gin.Context) {
|
||||
var req oListReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
@@ -147,5 +214,56 @@ func (Order) Paid(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
go notify.Handle(order)
|
||||
|
||||
base.Ok(ctx, "操作成功")
|
||||
}
|
||||
|
||||
func (Order) ManualNotify(ctx *gin.Context) {
|
||||
var req base.IDRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
base.BadRequest(ctx, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var order model.Order
|
||||
model.Db.Where("id = ?", req.ID).Find(&order)
|
||||
if order.ID == 0 {
|
||||
base.BadRequest(ctx, "订单不存在")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if order.Status != model.OrderStatusSuccess {
|
||||
base.BadRequest(ctx, "订单状态不是交易成功,无法手动回调")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err := notify.Handle(order); err != nil {
|
||||
base.BadRequest(ctx, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
base.Ok(ctx, "订单回调成功!")
|
||||
}
|
||||
|
||||
func (Order) Del(ctx *gin.Context) {
|
||||
var req base.IDListRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
base.BadRequest(ctx, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err := model.Db.Delete(&model.Order{}, req.IDList).Error
|
||||
if err != nil {
|
||||
base.Error(ctx, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
base.Ok(ctx, "删除成功")
|
||||
}
|
||||
|
||||
@@ -97,7 +97,12 @@ func (Rate) SetSyntax(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (Rate) Sync(ctx *gin.Context) {
|
||||
model.CoingeckoRate()
|
||||
err := model.CoingeckoRate()
|
||||
if err != nil {
|
||||
base.BadRequest(ctx, "同步异常: "+err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
base.Ok(ctx, "同步完成。")
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ type Wallet struct {
|
||||
}
|
||||
|
||||
type wAddReq struct {
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Address string `json:"address" binding:"required"`
|
||||
TradeType string `json:"trade_type" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Address string `json:"address" binding:"required"`
|
||||
TradeType string `json:"trade_type" binding:"required"`
|
||||
OtherNotify uint8 `json:"other_notify"`
|
||||
}
|
||||
|
||||
type wModReq struct {
|
||||
@@ -57,7 +58,7 @@ func (Wallet) Add(ctx *gin.Context) {
|
||||
MatchAddr: strings.TrimSpace(req.Address),
|
||||
TradeType: req.TradeType,
|
||||
Status: model.WaStatusEnable,
|
||||
OtherNotify: model.WaOtherDisable,
|
||||
OtherNotify: req.OtherNotify,
|
||||
}
|
||||
|
||||
if !wallet.IsValid() {
|
||||
|
||||
@@ -271,6 +271,28 @@ func (Auth) Menu(ctx *gin.Context) {
|
||||
},
|
||||
{
|
||||
Id: "06",
|
||||
Path: "/create-order",
|
||||
Name: "create-order",
|
||||
Component: "order/create-order",
|
||||
Meta: meta{
|
||||
Title: "create-order",
|
||||
Hide: false,
|
||||
Disable: false,
|
||||
KeepAlive: true,
|
||||
Affix: false,
|
||||
Link: "",
|
||||
Iframe: false,
|
||||
IsFull: false,
|
||||
Roles: []string{"admin"},
|
||||
SvgIcon: "form",
|
||||
Icon: "",
|
||||
Sort: 1,
|
||||
Type: 2,
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
{
|
||||
Id: "07",
|
||||
Path: "/github-api-doc",
|
||||
Name: "github-api-doc",
|
||||
Component: "about/doc",
|
||||
|
||||
@@ -13,3 +13,7 @@ type ListRequest struct {
|
||||
type IDRequest struct {
|
||||
ID int `json:"id" form:"id" binding:"required"` // *ID(必须)
|
||||
}
|
||||
|
||||
type IDListRequest struct {
|
||||
IDList []int `json:"ids" form:"ids" binding:"required"` // *ID列表(必须)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package epay
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
"github.com/v03413/bepusdt/app/utils"
|
||||
)
|
||||
@@ -29,7 +27,7 @@ type submit struct {
|
||||
ReturnURL string `form:"return_url" json:"return_url" binding:"required"`
|
||||
OutTradeNo string `form:"out_trade_no" json:"out_trade_no" binding:"required"`
|
||||
Name string `form:"name" json:"name" binding:"required"`
|
||||
Money float64 `form:"money" json:"money" binding:"required,gt=0"`
|
||||
Money string `form:"money" json:"money" binding:"required,gt=0"`
|
||||
Sign string `form:"sign" json:"sign" binding:"required"`
|
||||
Fiat model.Fiat `form:"fiat" json:"fiat"`
|
||||
Rate string `form:"rate" json:"rate"`
|
||||
@@ -41,34 +39,39 @@ type submit struct {
|
||||
func (e Epay) Submit(ctx *gin.Context) {
|
||||
var err error
|
||||
var data submit
|
||||
|
||||
var dataMap = make(map[string]string)
|
||||
if ctx.Request.Method != http.MethodPost {
|
||||
err = ctx.ShouldBindQuery(&data)
|
||||
for key, values := range ctx.Request.URL.Query() {
|
||||
if len(values) > 0 {
|
||||
dataMap[key] = values[0]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = ctx.ShouldBind(&data)
|
||||
_ = ctx.Request.ParseForm()
|
||||
for key, values := range ctx.Request.PostForm {
|
||||
if len(values) > 0 {
|
||||
dataMap[key] = values[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data, err = e.verify(dataMap)
|
||||
if err != nil {
|
||||
ctx.String(200, "参数解析错误:"+err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
if data.Pid != Pid {
|
||||
ctx.String(200, "BEpusdt 易支付兼容模式,商户号【PID】必须固定为"+Pid)
|
||||
ctx.String(200, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if e.sign(data, model.AuthToken()) != data.Sign {
|
||||
if e.sign(dataMap, model.AuthToken()) != data.Sign {
|
||||
ctx.String(200, "签名错误")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
e.fillDefaultParams(&data)
|
||||
|
||||
money := decimal.NewFromFloat(data.Money)
|
||||
if money.LessThanOrEqual(decimal.Zero) {
|
||||
ctx.String(200, "参数 money 格式错误,必须是一个大于0的数字")
|
||||
money, err := decimal.NewFromString(data.Money)
|
||||
if err != nil {
|
||||
ctx.String(200, "参数 money 解析错误,"+err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
@@ -87,7 +90,7 @@ func (e Epay) Submit(ctx *gin.Context) {
|
||||
Fiat: data.Fiat,
|
||||
})
|
||||
if err2 != nil {
|
||||
ctx.String(200, fmt.Sprintf("订单创建失败:%v", err))
|
||||
ctx.String(200, fmt.Sprintf("订单创建失败:%v", err2))
|
||||
|
||||
return
|
||||
}
|
||||
@@ -101,47 +104,65 @@ func (e Epay) Submit(ctx *gin.Context) {
|
||||
ctx.Redirect(http.StatusFound, model.CheckoutCounter(host, order.TradeId))
|
||||
}
|
||||
|
||||
// 填充默认参数
|
||||
func (e Epay) fillDefaultParams(data *submit) {
|
||||
if data.Pid == "" {
|
||||
data.Pid = Pid
|
||||
// verify 验证请求参数
|
||||
func (e Epay) verify(data map[string]string) (submit, error) {
|
||||
var params = submit{}
|
||||
|
||||
pid, ok := data["pid"]
|
||||
if !ok || pid != Pid {
|
||||
|
||||
return params, fmt.Errorf("BEpusdt 易支付兼容模式,商户号【PID】必须固定为" + Pid)
|
||||
}
|
||||
if data.Type == "" {
|
||||
data.Type = string(model.UsdtTrc20)
|
||||
|
||||
var requiredFields = []string{"pid", "type", "out_trade_no", "notify_url", "return_url", "name", "money", "sign"}
|
||||
for _, field := range requiredFields {
|
||||
if _, ok := data[field]; !ok || data[field] == "" {
|
||||
|
||||
return params, fmt.Errorf("参数 %s 缺失或为空", field)
|
||||
}
|
||||
}
|
||||
if data.Fiat == "" {
|
||||
data.Fiat = model.CNY
|
||||
|
||||
params.Pid = pid
|
||||
params.Type = data["type"]
|
||||
params.OutTradeNo = data["out_trade_no"]
|
||||
params.NotifyURL = data["notify_url"]
|
||||
params.ReturnURL = data["return_url"]
|
||||
params.Name = data["name"]
|
||||
params.Money = data["money"]
|
||||
params.Sign = data["sign"]
|
||||
|
||||
if address, ok := data["address"]; ok {
|
||||
params.Address = address
|
||||
}
|
||||
if rate, ok := data["rate"]; ok && rate != "" {
|
||||
params.Rate = rate
|
||||
}
|
||||
if timeout, ok := data["timeout"]; ok && timeout != "" {
|
||||
params.Timeout = timeout
|
||||
}
|
||||
|
||||
fiat, ok := data["fiat"]
|
||||
if ok && fiat != "" {
|
||||
params.Fiat = model.Fiat(fiat)
|
||||
} else {
|
||||
params.Fiat = model.CNY
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func (e Epay) sign(params submit, token string) string {
|
||||
jsonBytes, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
result := gjson.ParseBytes(jsonBytes)
|
||||
fields := make(map[string]string)
|
||||
result.ForEach(func(k, value gjson.Result) bool {
|
||||
fields[k.String()] = value.String()
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
// 提取 keys 并排序
|
||||
var keys = make([]string, 0, len(fields))
|
||||
for k := range fields {
|
||||
func (e Epay) sign(data map[string]string, token string) string {
|
||||
var keys = make([]string, 0, len(data))
|
||||
for k := range data {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
// 构建签名字符串
|
||||
signStr := ""
|
||||
for _, k := range keys {
|
||||
if k != "sign" && k != "sign_type" && fields[k] != "" {
|
||||
signStr += fmt.Sprintf("%s=%s&", k, fields[k])
|
||||
if k != "sign" && k != "sign_type" && data[k] != "" {
|
||||
signStr += fmt.Sprintf("%s=%s&", k, data[k])
|
||||
}
|
||||
}
|
||||
signStr = signStr[:len(signStr)-1]
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -32,11 +34,46 @@ type createReq struct {
|
||||
Rate string `json:"rate"`
|
||||
}
|
||||
|
||||
type createOrderReq struct {
|
||||
Amount float64 `json:"amount" binding:"required"`
|
||||
OrderID string `json:"order_id" binding:"required"`
|
||||
NotifyURL string `json:"notify_url" binding:"required"`
|
||||
RedirectURL string `json:"redirect_url" binding:"required"`
|
||||
Signature string `json:"signature" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Fiat model.Fiat `json:"fiat"`
|
||||
Currencies string `json:"currencies"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
type updateOrderReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Currency string `json:"currency" binding:"required"`
|
||||
Network string `json:"network" binding:"required"`
|
||||
}
|
||||
|
||||
type cancelReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Signature string `json:"signature" binding:"required"`
|
||||
}
|
||||
|
||||
type methodsReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
}
|
||||
|
||||
type PaymentItem struct {
|
||||
Amount string `json:"amount"`
|
||||
ActualAmount string `json:"actual_amount"`
|
||||
Fiat string `json:"fiat"`
|
||||
ExchangeRate string `json:"exchange_rate"`
|
||||
Currency string `json:"currency"`
|
||||
Network string `json:"network"`
|
||||
TokenNetName string `json:"token_net_name"`
|
||||
TokenCustomName string `json:"token_custom_name"`
|
||||
IsPopular bool `json:"is_popular"`
|
||||
}
|
||||
|
||||
func (Epusdt) SignVerify(ctx *gin.Context) {
|
||||
rawData, err := ctx.GetRawData()
|
||||
if err != nil {
|
||||
@@ -73,10 +110,38 @@ func (Epusdt) SignVerify(ctx *gin.Context) {
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
var req createReq
|
||||
func (Epusdt) Notify(ctx *gin.Context) {
|
||||
rawData, err := ctx.GetRawData()
|
||||
if err != nil {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
m := make(map[string]any)
|
||||
if err = json.Unmarshal(rawData, &m); err != nil {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
sign, ok := m["signature"]
|
||||
if !ok {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
if utils.EpusdtSign(m, model.AuthToken()) != sign {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(200, "ok")
|
||||
}
|
||||
|
||||
// CreateOrder Order creation API
|
||||
func (Epusdt) CreateOrder(ctx *gin.Context) {
|
||||
var req createOrderReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("CreateOrder: request error: %s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
@@ -87,6 +152,116 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
host = "https://" + ctx.Request.Host
|
||||
}
|
||||
|
||||
if req.Fiat == "" {
|
||||
req.Fiat = model.CNY
|
||||
}
|
||||
|
||||
// 创建待付款订单
|
||||
order, err := model.BuildPendingOrder(model.OrderParams{
|
||||
Money: decimal.NewFromFloat(req.Amount),
|
||||
ApiType: model.OrderApiTypeEpusdt,
|
||||
OrderId: req.OrderID,
|
||||
RedirectUrl: req.RedirectURL,
|
||||
NotifyUrl: req.NotifyURL,
|
||||
Name: req.Name,
|
||||
Timeout: req.Timeout,
|
||||
Fiat: req.Fiat,
|
||||
CurrencyLimit: req.Currencies,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("CreateOrder: order create failed: %s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info(fmt.Sprintf("订单创建成功 商户订单:%s", req.OrderID))
|
||||
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"fiat": order.Fiat,
|
||||
"trade_id": order.TradeId,
|
||||
"order_id": order.OrderId,
|
||||
"name": order.Name,
|
||||
"status": order.Status,
|
||||
"amount": order.Money,
|
||||
"expiration_time": uint64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCashier(host, order.TradeId),
|
||||
"network": GetPaymentItem("", order),
|
||||
}))
|
||||
}
|
||||
|
||||
// UpdateOrder 更新订单,返回付款链接。更新订单不需要签名,因为创建订单时已经验证,只需要提交参数更新订单即可。
|
||||
func (Epusdt) UpdateOrder(ctx *gin.Context) {
|
||||
// 接收 trade_id, currency, network 三个参数
|
||||
var req updateOrderReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("UpdateOrder: request error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 解析请求地址
|
||||
host := "http://" + ctx.Request.Host
|
||||
if ctx.Request.TLS != nil {
|
||||
host = "https://" + ctx.Request.Host
|
||||
}
|
||||
|
||||
// 获取订单
|
||||
order, ok := model.GetTradeOrder(req.TradeID)
|
||||
if !ok {
|
||||
ctx.JSON(200, respFailJson("order not found"))
|
||||
return
|
||||
}
|
||||
|
||||
// 根据 currency 和 network 解析出 TradeType
|
||||
tradeType, err := model.GetTradeTypeByCurrencyAndNetwork(req.Currency, req.Network)
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("UpdateOrder: unsupported payment method: %s - %s", req.Currency, req.Network)))
|
||||
return
|
||||
}
|
||||
|
||||
// 重建订单(更新支付方式)
|
||||
// 注意:RebuildOrder 需要 OrderParams,我们需要从现有订单构造参数
|
||||
money, _ := decimal.NewFromString(order.Money)
|
||||
params := model.OrderParams{
|
||||
Money: money,
|
||||
OrderId: order.OrderId,
|
||||
TradeType: tradeType, // 新的交易类型
|
||||
RedirectUrl: order.ReturnUrl,
|
||||
NotifyUrl: order.NotifyUrl,
|
||||
Name: order.Name,
|
||||
Timeout: int64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
Fiat: order.Fiat,
|
||||
}
|
||||
|
||||
newOrder, err := model.RebuildOrder(order, params)
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("update order failed: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"fiat": newOrder.Fiat,
|
||||
"trade_type": newOrder.TradeType,
|
||||
"trade_id": newOrder.TradeId,
|
||||
"order_id": newOrder.OrderId,
|
||||
"status": newOrder.Status,
|
||||
"amount": newOrder.Money,
|
||||
"actual_amount": newOrder.Amount,
|
||||
"token": newOrder.Address,
|
||||
"expiration_time": uint64(newOrder.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCounter(host, newOrder.TradeId),
|
||||
}))
|
||||
}
|
||||
|
||||
func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
var req createReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if req.Fiat == "" {
|
||||
req.Fiat = model.CNY
|
||||
}
|
||||
@@ -118,6 +293,7 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"fiat": order.Fiat,
|
||||
"trade_type": order.TradeType,
|
||||
"trade_id": order.TradeId,
|
||||
"order_id": order.OrderId,
|
||||
"status": order.Status,
|
||||
@@ -125,7 +301,7 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
"actual_amount": order.Amount,
|
||||
"token": order.Address,
|
||||
"expiration_time": uint64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCounter(host, order.TradeId),
|
||||
"payment_url": model.CheckoutCounter(utils.GetRequestHost(ctx.Request), order.TradeId),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -191,6 +367,37 @@ func (Epusdt) CheckoutCounter(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) CheckoutCashier(ctx *gin.Context) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
order, ok := model.GetTradeOrder(tradeId)
|
||||
if !ok {
|
||||
ctx.String(200, "order not found")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
uri, err := url.ParseRequestURI(order.ReturnUrl)
|
||||
if err != nil {
|
||||
ctx.String(200, "sync address error")
|
||||
log.Error("CheckoutCashier: sync address error: ", err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, "cashier.html", gin.H{
|
||||
"http_host": uri.Host,
|
||||
"amount": order.Amount,
|
||||
"expire": int64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"return_url": order.ReturnUrl,
|
||||
"trade_id": tradeId,
|
||||
"order_id": order.OrderId,
|
||||
"name": order.Name,
|
||||
"money": order.Money,
|
||||
"fiat": order.Fiat,
|
||||
"network": GetPaymentItem("", order),
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) CheckStatus(ctx *gin.Context) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
order, ok := model.GetTradeOrder(tradeId)
|
||||
@@ -218,6 +425,116 @@ func (Epusdt) CheckStatus(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
var req methodsReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(500, respFailJson(fmt.Sprintf("request error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
order, ok := model.GetTradeOrder(req.TradeID)
|
||||
if !ok {
|
||||
ctx.JSON(400, respFailJson("order not found"))
|
||||
return
|
||||
}
|
||||
|
||||
if order.Status == model.OrderStatusExpired {
|
||||
ctx.JSON(400, respFailJson("order expired"))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"methods": GetPaymentItem(model.Crypto(req.Currency), order),
|
||||
}))
|
||||
}
|
||||
|
||||
func GetPaymentItem(crypto model.Crypto, order model.Order) []PaymentItem {
|
||||
fiat := order.Fiat
|
||||
|
||||
var methods = make([]PaymentItem, 0)
|
||||
allTrades := model.GetAllTradeConfig()
|
||||
|
||||
// 解析限定币种
|
||||
var whitelist = make(map[string]bool)
|
||||
var blacklist = make(map[string]bool)
|
||||
if order.CurrencyLimit != "" {
|
||||
for _, c := range strings.Split(order.CurrencyLimit, ",") {
|
||||
c = strings.TrimSpace(c)
|
||||
if strings.HasPrefix(c, "-") {
|
||||
blacklist[strings.ToUpper(strings.TrimPrefix(c, "-"))] = true
|
||||
} else {
|
||||
whitelist[strings.ToUpper(c)] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for tradeTypeStr, conf := range allTrades {
|
||||
// 如果指定了货币,则进行过滤
|
||||
if crypto != "" && conf.Crypto != crypto {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check blacklist
|
||||
if len(blacklist) > 0 && blacklist[string(conf.Crypto)] {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check whitelist
|
||||
if len(whitelist) > 0 && !whitelist[string(conf.Crypto)] {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查是否有可用钱包
|
||||
count := len(model.GetAvailableAddress(model.TradeType(tradeTypeStr)))
|
||||
if count == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取汇率配置的浮动语法
|
||||
syntax := model.GetK(model.ConfKey(fmt.Sprintf("rate_float_%s_%s", conf.Crypto, fiat)))
|
||||
|
||||
// 获取汇率
|
||||
rate, err := model.GetOrderRate(conf.Crypto, fiat, syntax)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("GetPaymentMethods: get order rate error: %s", err.Error()))
|
||||
continue
|
||||
}
|
||||
|
||||
// 计算实际支付金额 (加密货币)
|
||||
// Money 是法币金额
|
||||
moneyDecimal, _ := decimal.NewFromString(order.Money)
|
||||
|
||||
// 计算精度
|
||||
atom, precision := model.GetAtomicity(model.TradeType(tradeTypeStr))
|
||||
actualAmount := moneyDecimal.DivRound(rate, precision)
|
||||
if actualAmount.LessThan(atom) {
|
||||
actualAmount = atom
|
||||
}
|
||||
|
||||
methods = append(methods, PaymentItem{
|
||||
Amount: order.Money,
|
||||
ActualAmount: actualAmount.String(),
|
||||
Fiat: string(fiat),
|
||||
ExchangeRate: rate.String(),
|
||||
Currency: string(conf.Crypto),
|
||||
Network: string(conf.Network),
|
||||
TokenNetName: conf.NetworkName,
|
||||
TokenCustomName: "", // 暂为空
|
||||
IsPopular: false, // 暂为 false
|
||||
})
|
||||
}
|
||||
|
||||
// Sort by Currency A-Z
|
||||
sort.Slice(methods, func(i, j int) bool {
|
||||
if methods[i].Currency != methods[j].Currency {
|
||||
return methods[i].Currency < methods[j].Currency
|
||||
}
|
||||
return methods[i].Network < methods[j].Network
|
||||
})
|
||||
|
||||
return methods
|
||||
}
|
||||
|
||||
func respFailJson(message string) gin.H {
|
||||
|
||||
return gin.H{"status_code": 400, "message": message}
|
||||
|
||||
@@ -6,13 +6,14 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
Task *logrus.Logger
|
||||
bepusdt *logrus.Logger
|
||||
logFiles []*os.File
|
||||
Task *logrus.Logger
|
||||
be *logrus.Logger
|
||||
loggers []*lumberjack.Logger
|
||||
)
|
||||
|
||||
func newLogger(file string) (*logrus.Logger, error) {
|
||||
@@ -25,15 +26,16 @@ func newLogger(file string) (*logrus.Logger, error) {
|
||||
})
|
||||
|
||||
logger.SetLevel(logrus.InfoLevel)
|
||||
|
||||
output, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
output := &lumberjack.Logger{
|
||||
Filename: file,
|
||||
MaxSize: 300,
|
||||
MaxBackups: 5,
|
||||
MaxAge: 7,
|
||||
Compress: true,
|
||||
}
|
||||
|
||||
// 保存文件句柄
|
||||
logFiles = append(logFiles, output)
|
||||
logger.SetOutput(output)
|
||||
loggers = append(loggers, output)
|
||||
|
||||
return logger, nil
|
||||
}
|
||||
@@ -46,7 +48,7 @@ func Init(dir string) error {
|
||||
|
||||
var err error
|
||||
|
||||
bepusdt, err = newLogger(filepath.Join(dir, "bepusdt.log"))
|
||||
be, err = newLogger(filepath.Join(dir, "bepusdt.log"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -60,39 +62,34 @@ func Init(dir string) error {
|
||||
}
|
||||
|
||||
func Debug(args ...interface{}) {
|
||||
bepusdt.Debugln(args...)
|
||||
be.Debugln(args...)
|
||||
}
|
||||
|
||||
func Info(args ...interface{}) {
|
||||
bepusdt.Infoln(args...)
|
||||
be.Infoln(args...)
|
||||
}
|
||||
|
||||
func Error(args ...interface{}) {
|
||||
bepusdt.Errorln(args...)
|
||||
be.Errorln(args...)
|
||||
}
|
||||
|
||||
func Warn(args ...interface{}) {
|
||||
bepusdt.Warnln(args...)
|
||||
be.Warnln(args...)
|
||||
}
|
||||
|
||||
func GetWriter() *io.PipeWriter {
|
||||
|
||||
return bepusdt.Writer()
|
||||
return be.Writer()
|
||||
}
|
||||
|
||||
func Close() {
|
||||
var lastErr error
|
||||
for _, f := range logFiles {
|
||||
for _, f := range loggers {
|
||||
if f != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
lastErr = err
|
||||
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("日志句柄资源关闭错误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logFiles = nil
|
||||
|
||||
if lastErr != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("日志句柄资源关闭错误:%s", lastErr.Error()))
|
||||
}
|
||||
loggers = nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -16,8 +17,8 @@ import (
|
||||
var confCache sync.Map
|
||||
|
||||
type Conf struct {
|
||||
K ConfKey `gorm:"column:k;type:varchar(32);primaryKey" json:"key"`
|
||||
V string `gorm:"column:v;type:varchar(255)" json:"val"`
|
||||
K ConfKey `gorm:"column:k;type:varchar(32);not null;primaryKey" json:"key"`
|
||||
V string `gorm:"column:v;type:varchar(255);not null" json:"val"`
|
||||
}
|
||||
|
||||
func (c Conf) TableName() string {
|
||||
@@ -27,7 +28,7 @@ func (c Conf) TableName() string {
|
||||
|
||||
func SetK(k ConfKey, v string) {
|
||||
if err = Db.Transaction(func(db *gorm.DB) error {
|
||||
if err2 := db.Where("`k` = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
if err2 := db.Where("k = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
|
||||
return err2
|
||||
}
|
||||
@@ -104,43 +105,57 @@ func CheckoutCounter(host, id string) string {
|
||||
return fmt.Sprintf("%s/pay/checkout-counter/%s", uri, id)
|
||||
}
|
||||
|
||||
func CheckoutCashier(host, id string) string {
|
||||
uri := GetK(ApiAppUri)
|
||||
if uri == "" {
|
||||
uri = host
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/pay/cashier/%s", uri, id)
|
||||
}
|
||||
|
||||
func ConfInit() {
|
||||
var hash = utils.StrSha256(utils.Md5String(time.Now().String()))
|
||||
var secure = "/" + hash[:10]
|
||||
var token = utils.Md5String(hash[18:28])
|
||||
var token = strings.ToUpper(utils.Md5String(hash[18:28]))
|
||||
var username = hash[10:20]
|
||||
var password = hash[20:30]
|
||||
var encrypt, _ = bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
var data = map[ConfKey]string{
|
||||
ApiAppUri: "",
|
||||
ApiAuthToken: token,
|
||||
AdminSecure: secure,
|
||||
AdminUsername: username,
|
||||
AdminPassword: string(encrypt),
|
||||
RateSyncInterval: "3600",
|
||||
AtomUSDT: "0.01",
|
||||
AtomUSDC: "0.01",
|
||||
AtomTRX: "0.01",
|
||||
AtomBNB: "0.00001",
|
||||
AtomETH: "0.000001",
|
||||
MonitorMinAmount: "0.01",
|
||||
PaymentMinAmount: "0.01",
|
||||
PaymentMaxAmount: "99999",
|
||||
RpcEndpointTron: "grpc.trongrid.io:50051",
|
||||
RpcEndpointBsc: "https://binance-smart-chain-public.nodies.app/",
|
||||
RpcEndpointSolana: "https://solana-rpc.publicnode.com/",
|
||||
RpcEndpointXlayer: "https://xlayerrpc.okx.com/",
|
||||
RpcEndpointPolygon: "https://polygon-public.nodies.app/",
|
||||
RpcEndpointArbitrum: "https://arb1.arbitrum.io/rpc",
|
||||
RpcEndpointEthereum: "https://ethereum-public.nodies.app/",
|
||||
RpcEndpointBase: "https://base-public.nodies.app/",
|
||||
RpcEndpointAptos: "https://aptos-rest.publicnode.com/",
|
||||
RpcEndpointPlasma: "https://9745.rpc.thirdweb.com/",
|
||||
NotifyMaxRetry: "10",
|
||||
BlockHeightMaxDiff: "1000",
|
||||
PaymentTimeout: "1200", // 20分钟
|
||||
PaymentStaticPath: "",
|
||||
SystemInstallLock: "0",
|
||||
ApiAppUri: "",
|
||||
ApiAuthToken: token,
|
||||
AdminSecret: utils.StrSha256(hash),
|
||||
AdminSecure: secure,
|
||||
AdminUsername: username,
|
||||
AdminPassword: string(encrypt),
|
||||
RateSyncInterval: "3600",
|
||||
AtomUSDT: "0.01",
|
||||
AtomUSDC: "0.01",
|
||||
AtomTRX: "0.01",
|
||||
AtomBNB: "0.00001",
|
||||
AtomETH: "0.000001",
|
||||
MonitorMinAmount: "0.01",
|
||||
PaymentMinAmount: "0.01",
|
||||
PaymentMaxAmount: "99999",
|
||||
RpcEndpointTron: "grpc.trongrid.io:50051",
|
||||
RpcEndpointBsc: "https://binance-smart-chain-public.nodies.app/",
|
||||
RpcEndpointSolana: "https://solana-rpc.publicnode.com/",
|
||||
RpcEndpointXlayer: "https://xlayerrpc.okx.com/",
|
||||
RpcEndpointPolygon: "https://polygon-public.nodies.app/",
|
||||
RpcEndpointArbitrum: "https://arb1.arbitrum.io/rpc",
|
||||
RpcEndpointEthereum: "https://ethereum-public.nodies.app/",
|
||||
RpcEndpointBase: "https://base-public.nodies.app/",
|
||||
RpcEndpointAptos: "https://aptos-rest.publicnode.com/",
|
||||
RpcEndpointPlasma: "https://rpc.plasma.to/",
|
||||
NotifyMaxRetry: "10",
|
||||
BlockHeightMaxDiff: "1000",
|
||||
BlockOffsetConfirm: "0",
|
||||
PaymentTimeout: "1200", // 20分钟
|
||||
PaymentStaticPath: "",
|
||||
PaymentMatchMode: string(Classic),
|
||||
SystemInstallLock: "0",
|
||||
RateSyncCoingeckoApiUrl: "https://api.coingecko.com",
|
||||
RateSyncCoingeckoApiKey: "",
|
||||
}
|
||||
|
||||
var rows = make([]Conf, 0)
|
||||
@@ -148,6 +163,32 @@ func ConfInit() {
|
||||
rows = append(rows, Conf{K: k, V: v})
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("╔═══════════════════════════════════════════════════════════════════════")
|
||||
fmt.Println("║ 🎉 欢迎使用 BEpusdt - 首次运行检测,初始化配置完成")
|
||||
fmt.Println("╚═══════════════════════════════════════════════════════════════════════")
|
||||
fmt.Println()
|
||||
fmt.Println("┏━━ 🔐 后台登录信息 (请立即保存!)")
|
||||
fmt.Println("┃")
|
||||
fmt.Printf("┃ 👤 登录账号: %s\n", username)
|
||||
fmt.Printf("┃ 🔑 登录密码: %s\n", password)
|
||||
fmt.Printf("┃ 🛡️ 安全入口: %s\n", secure)
|
||||
fmt.Println("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
fmt.Println()
|
||||
fmt.Println("┏━━ 🔌 API 对接信息")
|
||||
fmt.Println("┃")
|
||||
fmt.Printf("┃ 🎫 对接令牌: %s\n", token)
|
||||
fmt.Println("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
fmt.Println()
|
||||
fmt.Println("⚠️ 重要提示:")
|
||||
fmt.Println(" • 以上信息仅显示一次,请务必妥善保存至安全位置")
|
||||
fmt.Println(" • 登录密码遗忘可通过 'reset' 命令重置")
|
||||
fmt.Println(" • API 令牌可在网页后台进行修改")
|
||||
fmt.Println(" • 建议定期更换密码以确保账户安全")
|
||||
fmt.Println()
|
||||
fmt.Println("═══════════════════════════════════════════════════════════════════════")
|
||||
fmt.Println()
|
||||
|
||||
Db.Create(&rows)
|
||||
|
||||
// 数据丢到缓存,前台首次访问时会展示这部分初始化信息;明文密码只这一次保存到缓存,不写入数据库
|
||||
|
||||
@@ -7,6 +7,7 @@ type Fiat string
|
||||
type CoinId string
|
||||
type Crypto string
|
||||
type TradeType string
|
||||
type MatchMode string
|
||||
type Network string
|
||||
type Range struct {
|
||||
MinAmount decimal.Decimal
|
||||
@@ -14,6 +15,7 @@ type Range struct {
|
||||
}
|
||||
type TradeTypeConf struct {
|
||||
Alias string // 类型别名,主要用户前端展示
|
||||
NetworkName string // 网络名称,用于前端展示
|
||||
Network Network // 所属区块链网络
|
||||
Crypto Crypto // 币种类型
|
||||
Native bool // 是否原生币
|
||||
@@ -29,6 +31,7 @@ const (
|
||||
AdminUsername ConfKey = "admin_username"
|
||||
AdminPassword ConfKey = "admin_password"
|
||||
AdminSecure ConfKey = "admin_secure"
|
||||
AdminSecret ConfKey = "admin_secret"
|
||||
AdminLoginIP ConfKey = "admin_login_ip"
|
||||
AdminLoginAt ConfKey = "admin_login_at"
|
||||
|
||||
@@ -46,6 +49,7 @@ const (
|
||||
PaymentMaxAmount ConfKey = "payment_max_amount"
|
||||
PaymentTimeout ConfKey = "payment_timeout" // 订单支付超时时间,单位秒
|
||||
PaymentStaticPath ConfKey = "payment_static_path" // 收银台静态资源路径
|
||||
PaymentMatchMode ConfKey = "payment_match_mode" // 订单金额匹配模式
|
||||
|
||||
RpcEndpointPlasma ConfKey = "rpc_endpoint_plasma" // Plasma RPC节点
|
||||
RpcEndpointBsc ConfKey = "rpc_endpoint_bsc" // BSC RPC节点
|
||||
@@ -59,9 +63,12 @@ const (
|
||||
RpcEndpointTron ConfKey = "rpc_endpoint_tron" // TRON RPC节点
|
||||
RpcEndpointTronGridApiKey ConfKey = "rpc_endpoint_tron_grid_api_key" // TRON RPC节点 TronGrid Api Key
|
||||
|
||||
RateSyncInterval ConfKey = "rate_sync_interval" // 汇率同步间隔,单位秒
|
||||
NotifyMaxRetry ConfKey = "notify_max_retry" // 最大重试次数,订单回调失败
|
||||
BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描
|
||||
RateSyncCoingeckoApiUrl ConfKey = "rate_sync_coingecko_api_url" // 汇率同步 Coingecko Api URL
|
||||
RateSyncCoingeckoApiKey ConfKey = "rate_sync_coingecko_api_key" // 汇率同步 Coingecko Api Key
|
||||
RateSyncInterval ConfKey = "rate_sync_interval" // 汇率同步间隔,单位秒
|
||||
NotifyMaxRetry ConfKey = "notify_max_retry" // 最大重试次数,订单回调失败
|
||||
BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描
|
||||
BlockOffsetConfirm ConfKey = "block_offset_confirm" // 区块偏移确认数,扫描时以当前区块高度减去此偏移量为准,避免重链导致的订单回调失败
|
||||
|
||||
NotifierParams ConfKey = "notifier_params" // 通知参数 (token, chat_id, email
|
||||
NotifierChannel ConfKey = "notifier_channel" // 通知渠道 (telegram, wechat, email
|
||||
@@ -82,6 +89,11 @@ const (
|
||||
BNB Crypto = "BNB"
|
||||
ETH Crypto = "ETH"
|
||||
)
|
||||
const (
|
||||
Classic MatchMode = "classic" // 经典模式,精确匹配
|
||||
HasPrefix MatchMode = "has_prefix" // 前缀匹配,允许多付
|
||||
RoundOff MatchMode = "round_off" // 数值修约,四舍五入,允许容错
|
||||
)
|
||||
|
||||
// USD 交易类型常见扫描范围
|
||||
var usdGeneralRange = Range{
|
||||
|
||||
@@ -6,17 +6,18 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var localLocation = time.Local
|
||||
|
||||
type Datetime time.Time
|
||||
|
||||
func (d *Datetime) MarshalJSON() ([]byte, error) {
|
||||
tTime := time.Time(*d)
|
||||
tTime := time.Time(*d).In(localLocation)
|
||||
return []byte(fmt.Sprintf("\"%v\"", tTime.Format("2006-01-02 15:04:05"))), nil
|
||||
}
|
||||
|
||||
func (d Datetime) Value() (driver.Value, error) {
|
||||
var zeroTime time.Time
|
||||
tlt := time.Time(d)
|
||||
// 判断给定时间是否和默认零时间的时间戳相同
|
||||
if tlt.UnixNano() == zeroTime.UnixNano() {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -26,34 +27,27 @@ func (d Datetime) Value() (driver.Value, error) {
|
||||
func (d *Datetime) Scan(v interface{}) error {
|
||||
if value, ok := v.(time.Time); ok {
|
||||
*d = Datetime(value)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("can not convert %v to timestamp", v)
|
||||
}
|
||||
|
||||
func (d *Datetime) String() string {
|
||||
|
||||
return time.Time(*d).Format(time.DateTime)
|
||||
return time.Time(*d).In(localLocation).Format(time.DateTime)
|
||||
}
|
||||
|
||||
func (d *Datetime) Year() string {
|
||||
|
||||
return time.Time(*d).Format("2006")
|
||||
return time.Time(*d).In(localLocation).Format("2006")
|
||||
}
|
||||
|
||||
func (d *Datetime) Before(u time.Time) bool {
|
||||
|
||||
return time.Time(*d).Before(u)
|
||||
}
|
||||
|
||||
func (d *Datetime) Time() time.Time {
|
||||
|
||||
return time.Time(*d)
|
||||
return time.Time(*d).In(localLocation)
|
||||
}
|
||||
|
||||
func (d *Datetime) Format(layout string) string {
|
||||
|
||||
return time.Time(*d).Format(layout)
|
||||
return time.Time(*d).In(localLocation).Format(layout)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -13,15 +16,26 @@ var Db *gorm.DB
|
||||
var err error
|
||||
|
||||
type Id struct {
|
||||
ID int64 `gorm:"column:id;type:INTEGER PRIMARY KEY AUTOINCREMENT;;not null;comment:主键ID" json:"id"`
|
||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement;not null;comment:主键ID" json:"id"`
|
||||
}
|
||||
|
||||
type AutoTimeAt struct {
|
||||
CreatedAt *Datetime `gorm:"column:created_at;type:Datetime;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;type:Datetime;not null;comment:最后更新时间" json:"updated_at"`
|
||||
CreatedAt *Datetime `gorm:"column:created_at;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;not null;comment:最后更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func Init(path string) error {
|
||||
func Init(path, mysql, postgres string) error {
|
||||
if postgres != "" {
|
||||
return initPostgres(postgres)
|
||||
}
|
||||
if mysql != "" {
|
||||
return initMySQL(mysql)
|
||||
}
|
||||
|
||||
return initSqlite(path)
|
||||
}
|
||||
|
||||
func initSqlite(path string) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
|
||||
|
||||
return fmt.Errorf("创建数据库目录失败:%w", err)
|
||||
@@ -67,6 +81,87 @@ func Init(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initMySQL(dsn string) error {
|
||||
var err error
|
||||
Db, err = gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: dsn,
|
||||
DefaultStringSize: 256, // string 类型字段的默认长度
|
||||
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||
SkipInitializeWithVersion: false, // 根据当前 MySQL 版本自动配置
|
||||
}), &gorm.Config{})
|
||||
if err != nil {
|
||||
|
||||
return fmt.Errorf("数据库初始化失败:%w", err)
|
||||
}
|
||||
|
||||
{
|
||||
sqlDB, err := Db.DB()
|
||||
if err != nil {
|
||||
|
||||
return fmt.Errorf("获取数据库连接失败:%w", err)
|
||||
}
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
sqlDB.SetMaxIdleConns(10)
|
||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
}
|
||||
|
||||
if err = AutoMigrate(); err != nil {
|
||||
|
||||
return fmt.Errorf("数据库结构迁移失败:%w", err)
|
||||
}
|
||||
|
||||
var count int64
|
||||
Db.Model(&Conf{}).Count(&count)
|
||||
if count == 0 {
|
||||
ConfInit()
|
||||
}
|
||||
|
||||
RefreshC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initPostgres(dsn string) error {
|
||||
// 首次启动可能出现 SLOW SQL 告警,这是由于连接池首次连接预热引起的,后续连接将正常
|
||||
|
||||
var err error
|
||||
Db, err = gorm.Open(postgres.New(postgres.Config{DSN: dsn, PreferSimpleProtocol: true}), &gorm.Config{})
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
{
|
||||
sqlDB, err := Db.DB()
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
sqlDB.SetMaxIdleConns(10)
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
sqlDB.SetConnMaxLifetime(30 * time.Minute)
|
||||
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
|
||||
}
|
||||
|
||||
if err = AutoMigrate(); err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var count int64
|
||||
Db.Model(&Conf{}).Count(&count)
|
||||
if count == 0 {
|
||||
ConfInit()
|
||||
}
|
||||
|
||||
RefreshC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func AutoMigrate() error {
|
||||
return Db.AutoMigrate(&Wallet{}, &Order{}, &NotifyRecord{}, &Conf{}, &Rate{})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package model
|
||||
|
||||
type NotifyRecord struct {
|
||||
Id
|
||||
Txid string `gorm:"type:varchar(64);uniqueIndex;not null;comment:交易哈希"`
|
||||
Txid string `gorm:"type:varchar(128);uniqueIndex;not null;comment:交易哈希"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
|
||||
@@ -49,33 +49,35 @@ const (
|
||||
const (
|
||||
OrderApiTypeEpusdt = "epusdt" // epusdt
|
||||
OrderApiTypeEpay = "epay" // 彩虹易支付
|
||||
OrderApiTypeAdmin = "admin" // 管理后台
|
||||
)
|
||||
|
||||
var calcMutex sync.Mutex
|
||||
|
||||
type Order struct {
|
||||
Id
|
||||
OrderId string `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
|
||||
TradeId string `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
|
||||
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
|
||||
Fiat Fiat `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
|
||||
Crypto Crypto `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
|
||||
Rate string `gorm:"column:rate;type:varchar(10);not null;comment:交易汇率" json:"rate"`
|
||||
Amount string `gorm:"column:amount;type:varchar(32);not null;default:0.00;comment:交易数额" json:"amount"`
|
||||
Money string `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
|
||||
Address string `gorm:"column:address;type:varchar(64);index;not null;comment:收款地址" json:"address"`
|
||||
FromAddress string `gorm:"column:from_address;type:varchar(34);not null;default:'';comment:支付地址" json:"from_address"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;type:int(11);not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;type:tinyint(1);not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';unique;comment:交易哈希" json:"ref_hash"`
|
||||
RefBlockNum int64 `gorm:"column:ref_block_num;type:bigint(20);not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;type:timestamp;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt time.Time `gorm:"column:confirmed_at;type:timestamp;null;comment:交易确认时间" json:"confirmed_at"`
|
||||
OrderId string `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
|
||||
TradeId string `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
|
||||
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
|
||||
Fiat Fiat `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
|
||||
Crypto Crypto `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
|
||||
CurrencyLimit string `gorm:"column:currency_limit;type:varchar(255);not null;default:'';comment:限定币种" json:"currency_limit"`
|
||||
Rate string `gorm:"column:rate;type:varchar(10);not null;comment:交易汇率" json:"rate"`
|
||||
Amount string `gorm:"column:amount;type:varchar(32);not null;default:0.00;comment:交易数额" json:"amount"`
|
||||
Money string `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
|
||||
Address string `gorm:"column:address;type:varchar(128);index;not null;comment:收款地址" json:"address"`
|
||||
FromAddress string `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
|
||||
Status int `gorm:"column:status;not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
|
||||
RefBlockNum int `gorm:"column:ref_block_num;not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt *time.Time `gorm:"column:confirmed_at;not null;comment:交易确认时间" json:"confirmed_at"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
@@ -103,11 +105,11 @@ func (o *Order) SetFailed() {
|
||||
Db.Save(o)
|
||||
}
|
||||
|
||||
func (o *Order) MarkConfirming(blockNum int64, from, hash string, at time.Time) {
|
||||
func (o *Order) MarkConfirming(blockNum int, from, hash string, at time.Time) {
|
||||
o.FromAddress = from
|
||||
o.ConfirmedAt = at
|
||||
o.ConfirmedAt = &at
|
||||
o.RefHash = hash
|
||||
o.RefBlockNum = blockNum
|
||||
o.RefBlockNum = int(blockNum)
|
||||
o.Status = OrderStatusConfirming
|
||||
|
||||
Db.Save(o)
|
||||
@@ -121,17 +123,14 @@ func (o *Order) SetNotifyState(state int) error {
|
||||
}
|
||||
|
||||
func (o *Order) GetStatusLabel() string {
|
||||
var label = "🟢收款成功"
|
||||
label := "🟢收款成功"
|
||||
if o.Status == OrderStatusExpired {
|
||||
|
||||
label = "🔴交易过期"
|
||||
}
|
||||
if o.Status == OrderStatusWaiting {
|
||||
|
||||
label = "🟡等待支付"
|
||||
}
|
||||
if o.Status == OrderStatusCanceled {
|
||||
|
||||
label = "⚪️订单取消"
|
||||
}
|
||||
|
||||
@@ -139,17 +138,14 @@ func (o *Order) GetStatusLabel() string {
|
||||
}
|
||||
|
||||
func (o *Order) GetStatusEmoji() string {
|
||||
var label = "🟢"
|
||||
label := "🟢"
|
||||
if o.Status == OrderStatusExpired {
|
||||
|
||||
label = "🔴"
|
||||
}
|
||||
if o.Status == OrderStatusWaiting {
|
||||
|
||||
label = "🟡"
|
||||
}
|
||||
if o.Status == OrderStatusCanceled {
|
||||
|
||||
label = "⚪️"
|
||||
}
|
||||
|
||||
@@ -157,24 +153,22 @@ func (o *Order) GetStatusEmoji() string {
|
||||
}
|
||||
|
||||
func (o *Order) GetTxUrl() string {
|
||||
|
||||
return GetTxUrl(o.TradeType, o.RefHash)
|
||||
}
|
||||
|
||||
func (o *Order) TableName() string {
|
||||
|
||||
return "bep_order"
|
||||
}
|
||||
|
||||
func GetTradeOrder(tradeId string) (Order, bool) {
|
||||
var order Order
|
||||
var res = Db.Where("trade_id = ?", tradeId).Take(&order)
|
||||
res := Db.Where("trade_id = ?", tradeId).Limit(1).Find(&order)
|
||||
|
||||
return order, res.Error == nil
|
||||
return order, res.RowsAffected > 0
|
||||
}
|
||||
|
||||
func GetOrderByStatus(Status int) []Order {
|
||||
var orders = make([]Order, 0)
|
||||
orders := make([]Order, 0)
|
||||
|
||||
Db.Where("status = ?", Status).Find(&orders)
|
||||
|
||||
@@ -183,7 +177,7 @@ func GetOrderByStatus(Status int) []Order {
|
||||
|
||||
func GetNotifyFailedTradeOrders() ([]Order, error) {
|
||||
var orders []Order
|
||||
var res = Db.Where("status = ?", OrderStatusSuccess).
|
||||
res := Db.Where("status = ?", OrderStatusSuccess).
|
||||
Where("notify_num <= ?", GetC(NotifyMaxRetry)).
|
||||
Where("notify_state = ?", OrderNotifyStateFail).Find(&orders)
|
||||
|
||||
@@ -196,20 +190,19 @@ func CalcTradeAmount(address []string, rate, money decimal.Decimal, t TradeType)
|
||||
defer calcMutex.Unlock()
|
||||
|
||||
var orders []Order
|
||||
var lock = make(map[string]bool)
|
||||
var status = []int{OrderStatusConfirming, OrderStatusWaiting}
|
||||
lock := make(map[string]bool)
|
||||
status := []int{OrderStatusConfirming, OrderStatusWaiting}
|
||||
Db.Where("status in (?) and trade_type = ?", status, t).Find(&orders)
|
||||
for _, order := range orders {
|
||||
lock[order.Address+order.Amount] = true
|
||||
}
|
||||
|
||||
var atom, precision = getAtomicity(t)
|
||||
atom, precision := GetAtomicity(t)
|
||||
if rate.LessThanOrEqual(decimal.Zero) || precision <= 0 {
|
||||
|
||||
return "", "", errors.New(fmt.Sprintf("[%v - %v]原子颗粒度计算异常,联系管理员处理!", atom, precision))
|
||||
}
|
||||
|
||||
var amount = money.DivRound(rate, precision)
|
||||
amount := money.DivRound(rate, precision)
|
||||
if amount.LessThan(atom) { // 低于最小原子精度,从最小原子精度开始计算
|
||||
amount = atom
|
||||
}
|
||||
@@ -218,7 +211,6 @@ func CalcTradeAmount(address []string, rate, money decimal.Decimal, t TradeType)
|
||||
for _, addr := range address {
|
||||
k := addr + amount.String()
|
||||
if _, ok := lock[k]; ok {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -233,20 +225,19 @@ func CalcTradeAmount(address []string, rate, money decimal.Decimal, t TradeType)
|
||||
// CalcTradeExpiredAt 计算订单过期时间 最小180,最大3600,默认1200
|
||||
func CalcTradeExpiredAt(sec int64) time.Time {
|
||||
if sec >= 180 && sec <= 3600 {
|
||||
|
||||
return time.Now().Add(time.Duration(sec) * time.Second)
|
||||
}
|
||||
|
||||
return time.Now().Add(time.Duration(cast.ToUint64(GetK(PaymentTimeout))) * time.Second)
|
||||
}
|
||||
|
||||
func getAtomicity(t TradeType) (decimal.Decimal, int32) {
|
||||
func GetAtomicity(t TradeType) (decimal.Decimal, int32) {
|
||||
confKey, ok := GetTradeAtomKey(t)
|
||||
if !ok {
|
||||
confKey = "atom_usdt"
|
||||
}
|
||||
|
||||
var atom, _ = decimal.NewFromString(GetK(confKey))
|
||||
atom, _ := decimal.NewFromString(GetK(confKey))
|
||||
|
||||
return atom, cast.ToInt32(math.Abs(float64(atom.Exponent())))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@@ -44,7 +45,7 @@ func (r *Rate) BeforeCreate(*gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CoingeckoRate() {
|
||||
func CoingeckoRate() error {
|
||||
var fiats = make([]string, 0)
|
||||
for k := range supportFiat {
|
||||
fiats = append(fiats, string(k))
|
||||
@@ -57,34 +58,38 @@ func CoingeckoRate() {
|
||||
tokens[id] = token
|
||||
}
|
||||
|
||||
var url = fmt.Sprintf("https://api.coingecko.com/api/v3/simple/price?ids=%s&vs_currencies=%s", strings.Join(ids, ","), strings.Join(fiats, ","))
|
||||
var url = fmt.Sprintf("%s/api/v3/simple/price?ids=%s&vs_currencies=%s", GetC(RateSyncCoingeckoApiUrl), strings.Join(ids, ","), strings.Join(fiats, ","))
|
||||
var client = &http.Client{Timeout: 15 * time.Second}
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
log.Warn("汇率同步错误", err)
|
||||
|
||||
return
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("x-cg-demo-api-key", GetC(RateSyncCoingeckoApiKey))
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Warn("汇率同步错误", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Warn("汇率同步错误 StatusCode != 200", resp.StatusCode)
|
||||
|
||||
return
|
||||
return errors.New("CoingeckoRate: " + http.StatusText(resp.StatusCode))
|
||||
}
|
||||
|
||||
var data = gjson.ParseBytes(body)
|
||||
if data.Get("status.error_code").Exists() {
|
||||
log.Warn(fmt.Sprintf("汇率同步错误 %s", data.Get("status.error_message").String()))
|
||||
|
||||
return
|
||||
return errors.New("CoingeckoRate: " + data.Get("status.error_message").String())
|
||||
}
|
||||
|
||||
var rows = make([]Rate, 0)
|
||||
@@ -106,13 +111,13 @@ func CoingeckoRate() {
|
||||
}
|
||||
|
||||
if len(rows) == 0 {
|
||||
log.Warn("汇率同步错误 无数据")
|
||||
|
||||
return
|
||||
return errors.New("CoingeckoRate: no data")
|
||||
}
|
||||
|
||||
Db.Create(&rows)
|
||||
log.Info("汇率同步成功")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseFloatRate(syntax string, rawVal float64) float64 {
|
||||
@@ -166,7 +171,7 @@ func round(val float64, precision int) float64 {
|
||||
return math.Floor(val*p+0.5) / p
|
||||
}
|
||||
|
||||
func getOrderRate(token Crypto, fiat Fiat, syntax string) (decimal.Decimal, error) {
|
||||
func GetOrderRate(token Crypto, fiat Fiat, syntax string) (decimal.Decimal, error) {
|
||||
var r Rate
|
||||
Db.Where("crypto = ? and fiat = ?", token, fiat).Order("created_at desc").Limit(1).Find(&r)
|
||||
if r.ID == 0 {
|
||||
|
||||
@@ -30,16 +30,18 @@ var supportCrypto = map[Crypto]CoinId{
|
||||
var registry = map[TradeType]TradeTypeConf{
|
||||
UsdtPlasma: {
|
||||
Alias: "USDT・Plasma",
|
||||
NetworkName: "Plasma",
|
||||
Network: conf.Plasma,
|
||||
Crypto: USDT,
|
||||
Contract: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
|
||||
Decimal: -6,
|
||||
Contract: conf.UsdtPlasma,
|
||||
Decimal: conf.UsdtPlasmaDecimals,
|
||||
AmountRange: usdGeneralRange,
|
||||
ExplorerFmt: "https://plasmascan.to/tx/%s",
|
||||
EndpointKey: RpcEndpointPlasma,
|
||||
},
|
||||
UsdtTrc20: {
|
||||
Alias: "USDT・TRC20",
|
||||
NetworkName: "TRC20",
|
||||
Network: conf.Tron,
|
||||
Crypto: USDT,
|
||||
Contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // 占位,目前实际没使用
|
||||
@@ -51,6 +53,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtErc20: {
|
||||
Alias: "USDT・ERC20",
|
||||
NetworkName: "ERC20",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtErc20,
|
||||
@@ -61,6 +64,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtBep20: {
|
||||
Alias: "USDT・BEP20",
|
||||
NetworkName: "BEP20",
|
||||
Network: conf.Bsc,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtBep20,
|
||||
@@ -71,6 +75,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtAptos: {
|
||||
Alias: "USDT・Aptos",
|
||||
NetworkName: "Aptos",
|
||||
Network: conf.Aptos,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtAptos,
|
||||
@@ -81,6 +86,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtXlayer: {
|
||||
Alias: "USDT・X Layer",
|
||||
NetworkName: "X Layer",
|
||||
Network: conf.Xlayer,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtXlayer,
|
||||
@@ -91,6 +97,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtSolana: {
|
||||
Alias: "USDT・Solana",
|
||||
NetworkName: "Solana",
|
||||
Network: conf.Solana,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtSolana,
|
||||
@@ -102,6 +109,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtPolygon: {
|
||||
Alias: "USDT・Polygon",
|
||||
NetworkName: "Polygon",
|
||||
Network: conf.Polygon,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtPolygon,
|
||||
@@ -112,6 +120,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtArbitrum: {
|
||||
Alias: "USDT・Arbitrum",
|
||||
NetworkName: "Arbitrum",
|
||||
Network: conf.Arbitrum,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtArbitrum,
|
||||
@@ -122,6 +131,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcErc20: {
|
||||
Alias: "USDC・ERC20",
|
||||
NetworkName: "ERC20",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcErc20,
|
||||
@@ -132,6 +142,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcBep20: {
|
||||
Alias: "USDC・BEP20",
|
||||
NetworkName: "BEP20",
|
||||
Network: conf.Bsc,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcBep20,
|
||||
@@ -142,6 +153,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcXlayer: {
|
||||
Alias: "USDC・X Layer",
|
||||
NetworkName: "X Layer",
|
||||
Network: conf.Xlayer,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcXlayer,
|
||||
@@ -152,6 +164,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcPolygon: {
|
||||
Alias: "USDC・Polygon",
|
||||
NetworkName: "Polygon",
|
||||
Network: conf.Polygon,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcPolygon,
|
||||
@@ -162,6 +175,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcArbitrum: {
|
||||
Alias: "USDC・Arbitrum",
|
||||
NetworkName: "Arbitrum",
|
||||
Network: conf.Arbitrum,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcArbitrum,
|
||||
@@ -172,6 +186,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcBase: {
|
||||
Alias: "USDC・Base",
|
||||
NetworkName: "Base",
|
||||
Network: conf.Base,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcBase,
|
||||
@@ -182,6 +197,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcTrc20: {
|
||||
Alias: "USDC・TRC20",
|
||||
NetworkName: "TRC20",
|
||||
Network: conf.Tron,
|
||||
Crypto: USDC,
|
||||
Contract: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8", // 占位,目前实际没使用
|
||||
@@ -193,6 +209,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcSolana: {
|
||||
Alias: "USDC・Solana",
|
||||
NetworkName: "Solana",
|
||||
Network: conf.Solana,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcSolana,
|
||||
@@ -204,6 +221,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcAptos: {
|
||||
Alias: "USDC・Aptos",
|
||||
NetworkName: "Aptos",
|
||||
Network: conf.Aptos,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcAptos,
|
||||
@@ -213,11 +231,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
EndpointKey: RpcEndpointAptos,
|
||||
},
|
||||
TronTrx: {
|
||||
Alias: "Tron・Trx",
|
||||
Network: conf.Tron,
|
||||
Crypto: TRX,
|
||||
Native: true,
|
||||
Decimal: -6,
|
||||
Alias: "Tron・Trx",
|
||||
NetworkName: "Tron",
|
||||
Network: conf.Tron,
|
||||
Crypto: TRX,
|
||||
Native: true,
|
||||
Decimal: -6,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.1),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -227,11 +246,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
AddrCaseSens: true,
|
||||
},
|
||||
EthereumEth: {
|
||||
Alias: "Ethereum・Eth",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: ETH,
|
||||
Native: true,
|
||||
Decimal: conf.EthereumEthDecimals,
|
||||
Alias: "Ethereum・Eth",
|
||||
NetworkName: "Ethereum",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: ETH,
|
||||
Native: true,
|
||||
Decimal: conf.EthereumEthDecimals,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.000001),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -240,11 +260,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
EndpointKey: RpcEndpointEthereum,
|
||||
},
|
||||
BscBnb: {
|
||||
Alias: "Bsc・Bnb",
|
||||
Network: conf.Bsc,
|
||||
Crypto: BNB,
|
||||
Native: true,
|
||||
Decimal: conf.BscBnbDecimals,
|
||||
Alias: "Bsc・Bnb",
|
||||
NetworkName: "Bsc",
|
||||
Network: conf.Bsc,
|
||||
Crypto: BNB,
|
||||
Native: true,
|
||||
Decimal: conf.BscBnbDecimals,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.00001),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -293,6 +314,16 @@ func GetAllAlias() map[string]string {
|
||||
return alias
|
||||
}
|
||||
|
||||
func GetAllTradeConfig() map[string]TradeTypeConf {
|
||||
var config = make(map[string]TradeTypeConf)
|
||||
|
||||
for t, c := range registry {
|
||||
config[string(t)] = c
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func GetNetworkTrades(n Network) []TradeType {
|
||||
list, ok := networkTradesMap[n]
|
||||
if !ok {
|
||||
@@ -319,7 +350,9 @@ func GetContractDecimal(addr string) int32 {
|
||||
|
||||
func GetTxUrl(t TradeType, hash string) string {
|
||||
if url, ok := explorerUrlMap[t]; ok {
|
||||
|
||||
if url == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(url, hash)
|
||||
}
|
||||
|
||||
@@ -391,3 +424,12 @@ func AddrCaseSens(t TradeType) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func GetTradeTypeByCurrencyAndNetwork(currency, network string) (TradeType, error) {
|
||||
for t, c := range registry {
|
||||
if string(c.Crypto) == currency && (string(c.Network) == network || c.NetworkName == network) {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no matching trade type found for currency %s on network %s", currency, network)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cast"
|
||||
@@ -12,17 +13,18 @@ import (
|
||||
)
|
||||
|
||||
type OrderParams struct {
|
||||
Money decimal.Decimal `json:"money"` // 交易金额 (单位:法币)s
|
||||
ApiType string `json:"api_type"` // 支付 API 类型
|
||||
Address string `json:"address"` // 收款地址
|
||||
OrderId string `json:"order_id"` // 商户订单 ID
|
||||
TradeType TradeType `json:"trade_type"` // 交易类型
|
||||
RedirectUrl string `json:"redirect_url"` // 成功跳转地址
|
||||
NotifyUrl string `json:"notify_url"` // 异步通知地址
|
||||
Name string `json:"name"` // 商品名称
|
||||
Timeout int64 `json:"timeout"` // 订单超时时间(秒)
|
||||
Rate string `json:"rate"` // 强制指定汇率
|
||||
Fiat Fiat `json:"fiat"` // 法币类型
|
||||
Money decimal.Decimal `json:"money"` // 交易金额 (单位:法币)s
|
||||
ApiType string `json:"api_type"` // 支付 API 类型
|
||||
Address string `json:"address"` // 收款地址
|
||||
OrderId string `json:"order_id"` // 商户订单 ID
|
||||
TradeType TradeType `json:"trade_type"` // 交易类型
|
||||
RedirectUrl string `json:"redirect_url"` // 成功跳转地址
|
||||
NotifyUrl string `json:"notify_url"` // 异步通知地址
|
||||
Name string `json:"name"` // 商品名称
|
||||
Timeout int64 `json:"timeout"` // 订单超时时间(秒)
|
||||
Rate string `json:"rate"` // 强制指定汇率
|
||||
Fiat Fiat `json:"fiat"` // 法币类型
|
||||
CurrencyLimit string `json:"currency_limit"` // 限定币种
|
||||
}
|
||||
|
||||
type Trade struct {
|
||||
@@ -32,6 +34,8 @@ type Trade struct {
|
||||
Amount string
|
||||
}
|
||||
|
||||
var buildMutex sync.Mutex
|
||||
|
||||
func BuildOrder(p OrderParams) (Order, error) {
|
||||
var order Order
|
||||
|
||||
@@ -69,9 +73,15 @@ func BuildOrder(p OrderParams) (Order, error) {
|
||||
return RebuildOrder(order, p)
|
||||
}
|
||||
|
||||
var lock sync.Mutex
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
buildMutex.Lock()
|
||||
defer buildMutex.Unlock()
|
||||
Db.Where("order_id = ?", p.OrderId).Order("id desc").Limit(1).Find(&order)
|
||||
if order.Status == OrderStatusSuccess || order.Status == OrderStatusConfirming {
|
||||
return order, nil
|
||||
}
|
||||
if order.Status == OrderStatusWaiting {
|
||||
return RebuildOrder(order, p)
|
||||
}
|
||||
|
||||
data, err := BuildTrade(p)
|
||||
if err != nil {
|
||||
@@ -101,6 +111,8 @@ func RebuildOrder(t Order, p OrderParams) (Order, error) {
|
||||
t.Amount = data.Amount
|
||||
t.TradeType = p.TradeType
|
||||
t.Address = data.Address
|
||||
t.Crypto = data.Crypto
|
||||
t.Rate = fmt.Sprintf("%v", data.Rate)
|
||||
t.ExpiredAt = CalcTradeExpiredAt(p.Timeout)
|
||||
|
||||
return t, Db.Save(&t).Error
|
||||
@@ -112,26 +124,28 @@ func NewOrder(p OrderParams, data Trade) (Order, error) {
|
||||
return Order{}, err
|
||||
}
|
||||
|
||||
crypto, _ := GetCrypto(p.TradeType)
|
||||
zero := time.Unix(0, 0)
|
||||
tradeOrder := Order{
|
||||
OrderId: p.OrderId,
|
||||
TradeId: tradeId,
|
||||
RefHash: tradeId,
|
||||
TradeType: p.TradeType,
|
||||
Rate: fmt.Sprintf("%v", data.Rate),
|
||||
Amount: data.Amount,
|
||||
Money: p.Money.String(),
|
||||
Address: data.Address,
|
||||
Status: OrderStatusWaiting,
|
||||
Name: p.Name,
|
||||
ApiType: p.ApiType,
|
||||
ReturnUrl: p.RedirectUrl,
|
||||
NotifyUrl: p.NotifyUrl,
|
||||
NotifyNum: 0,
|
||||
NotifyState: OrderNotifyStateFail,
|
||||
ExpiredAt: CalcTradeExpiredAt(p.Timeout),
|
||||
Fiat: p.Fiat,
|
||||
Crypto: crypto,
|
||||
OrderId: p.OrderId,
|
||||
TradeId: tradeId,
|
||||
RefHash: tradeId,
|
||||
TradeType: p.TradeType,
|
||||
Rate: fmt.Sprintf("%v", data.Rate),
|
||||
Amount: data.Amount,
|
||||
Money: p.Money.String(),
|
||||
Address: data.Address,
|
||||
Status: OrderStatusWaiting,
|
||||
Name: p.Name,
|
||||
ApiType: p.ApiType,
|
||||
ReturnUrl: p.RedirectUrl,
|
||||
NotifyUrl: p.NotifyUrl,
|
||||
NotifyNum: 0,
|
||||
NotifyState: OrderNotifyStateFail,
|
||||
ExpiredAt: CalcTradeExpiredAt(p.Timeout),
|
||||
Fiat: p.Fiat,
|
||||
Crypto: data.Crypto,
|
||||
CurrencyLimit: p.CurrencyLimit,
|
||||
ConfirmedAt: &zero, // 默认填充一个0值时间,尽量避免数据库出现允许 NULL 值存在
|
||||
}
|
||||
|
||||
if tradeOrder.Name == "" {
|
||||
@@ -154,7 +168,7 @@ func BuildTrade(p OrderParams) (Trade, error) {
|
||||
}
|
||||
|
||||
// 获取订单汇率
|
||||
rate, err := getOrderRate(crypto, p.Fiat, p.Rate)
|
||||
rate, err := GetOrderRate(crypto, p.Fiat, p.Rate)
|
||||
if err != nil {
|
||||
return Trade{}, err
|
||||
}
|
||||
@@ -188,3 +202,41 @@ func BuildTrade(p OrderParams) (Trade, error) {
|
||||
Amount: amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BuildPendingOrder 创建待支付订单(不锁定地址和汇率)
|
||||
func BuildPendingOrder(p OrderParams) (Order, error) {
|
||||
var order Order
|
||||
|
||||
maxAmount := decimal.NewFromFloat(cast.ToFloat64(GetC(PaymentMaxAmount)))
|
||||
minAmount := decimal.NewFromFloat(cast.ToFloat64(GetC(PaymentMinAmount)))
|
||||
if p.Money.GreaterThan(maxAmount) || p.Money.LessThan(minAmount) {
|
||||
return order, fmt.Errorf("交易金额必须在 %s - %s 之间", minAmount.String(), maxAmount.String())
|
||||
}
|
||||
|
||||
Db.Where("order_id = ?", p.OrderId).Order("id desc").Limit(1).Find(&order)
|
||||
if order.Status == OrderStatusSuccess || order.Status == OrderStatusConfirming || order.Status == OrderStatusWaiting {
|
||||
return order, nil
|
||||
}
|
||||
|
||||
// 默认使用 USDT
|
||||
crypto := USDT
|
||||
if p.TradeType != "" {
|
||||
c, err := GetCrypto(p.TradeType)
|
||||
if err == nil {
|
||||
crypto = c
|
||||
}
|
||||
} else if p.CurrencyLimit != "" {
|
||||
// 如果指定了唯一的币种限制,且不是黑名单模式,则使用该币种
|
||||
cur := strings.ToUpper(p.CurrencyLimit)
|
||||
if !strings.Contains(cur, ",") && !strings.HasPrefix(cur, "-") {
|
||||
crypto = Crypto(cur)
|
||||
}
|
||||
}
|
||||
|
||||
return NewOrder(p, Trade{
|
||||
Crypto: crypto,
|
||||
Rate: decimal.Zero,
|
||||
Amount: "0",
|
||||
Address: "",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type TronTransfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type TronResource struct {
|
||||
|
||||
@@ -14,11 +14,11 @@ const (
|
||||
type Wallet struct {
|
||||
Id
|
||||
Name string `gorm:"column:name;type:varchar(32);not null;default:-';comment:名称" json:"name"`
|
||||
Status uint8 `gorm:"column:status;type:tinyint(1);not null;default:1;comment:地址状态" json:"status"`
|
||||
Address string `gorm:"column:address;type:varchar(64);not null;index;comment:钱包地址" json:"address"`
|
||||
MatchAddr string `gorm:"column:match_addr;type:varchar(64);not null;uniqueIndex:idx_address;comment:匹配地址" json:"match_addr"`
|
||||
Status uint8 `gorm:"column:status;not null;default:1;comment:地址状态" json:"status"`
|
||||
Address string `gorm:"column:address;type:varchar(128);not null;index;comment:钱包地址" json:"address"`
|
||||
MatchAddr string `gorm:"column:match_addr;type:varchar(128);not null;uniqueIndex:idx_address;comment:匹配地址" json:"match_addr"`
|
||||
TradeType string `gorm:"column:trade_type;type:varchar(20);not null;uniqueIndex:idx_address;comment:交易类型" json:"trade_type"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;type:tinyint(1);not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);not null;default:'';comment:备注" json:"remark"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type Telegram struct {
|
||||
}
|
||||
|
||||
func (t *Telegram) Initialize(params string) error {
|
||||
var info = gjson.Parse(params)
|
||||
info := gjson.Parse(params)
|
||||
|
||||
t.token = info.Get("bot_token").String()
|
||||
t.chatID = info.Get("chat_id").Int()
|
||||
@@ -44,7 +44,6 @@ func (t *Telegram) Initialize(params string) error {
|
||||
|
||||
func (t *Telegram) Success(o model.Order) {
|
||||
if o.Status != model.OrderStatusSuccess {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,7 +57,7 @@ func (t *Telegram) Success(o model.Order) {
|
||||
|
||||
token := string(tokenType)
|
||||
|
||||
var text = `
|
||||
text := `
|
||||
\#收款成功 \#订单交易 \#` + token + `
|
||||
\-\-\-
|
||||
` + "```" + `
|
||||
@@ -106,7 +105,7 @@ func (t *Telegram) NotifyFail(o model.Order, reason string) {
|
||||
|
||||
token := string(tokenT)
|
||||
|
||||
var text = fmt.Sprintf(`
|
||||
text := fmt.Sprintf(`
|
||||
\#回调失败 \#订单交易 \#`+token+`
|
||||
\-\-\-
|
||||
`+"```"+`
|
||||
@@ -124,7 +123,7 @@ func (t *Telegram) NotifyFail(o model.Order, reason string) {
|
||||
o.Money, o.Rate,
|
||||
strings.ToUpper(tradeType),
|
||||
o.ConfirmedAt.Format(time.DateTime),
|
||||
utils.CalcNextNotifyTime(o.ConfirmedAt, o.NotifyNum+1).Format(time.DateTime),
|
||||
utils.CalcNextNotifyTime(*o.ConfirmedAt, o.NotifyNum+1).Format(time.DateTime),
|
||||
reason,
|
||||
)
|
||||
|
||||
@@ -142,12 +141,12 @@ func (t *Telegram) NotifyFail(o model.Order, reason string) {
|
||||
}
|
||||
|
||||
func (t *Telegram) NonOrderTransfer(trans model.TronTransfer, wa model.Wallet) {
|
||||
var title = "收入"
|
||||
title := "收入"
|
||||
if trans.RecvAddress != wa.Address {
|
||||
title = "支出"
|
||||
}
|
||||
|
||||
var text = fmt.Sprintf(
|
||||
text := fmt.Sprintf(
|
||||
"\\#账户%s \\#非订单交易\n\\-\\-\\-\n```\n💲交易数额:%v \n💍交易类别:"+strings.ToUpper(string(trans.TradeType))+"\n⏱️交易时间:%v\n✅接收地址:%v\n🅾️发送地址:%v```\n",
|
||||
title,
|
||||
trans.Amount.String(),
|
||||
@@ -170,12 +169,12 @@ func (t *Telegram) NonOrderTransfer(trans model.TronTransfer, wa model.Wallet) {
|
||||
}
|
||||
|
||||
func (t *Telegram) TronResourceChange(res model.TronResource) {
|
||||
var title = "代理"
|
||||
title := "代理"
|
||||
if res.Type == core.Transaction_Contract_UnDelegateResourceContract {
|
||||
title = "回收"
|
||||
}
|
||||
|
||||
var text = fmt.Sprintf(
|
||||
text := fmt.Sprintf(
|
||||
"\\#资源动态 \\#能量"+title+"\n\\-\\-\\-\n```\n🔋质押数量:"+cast.ToString(res.Balance/1000000)+"\n⏱️交易时间:%v\n✅操作地址:%v\n🅾️资源来源:%v```\n",
|
||||
res.Timestamp.Format(time.DateTime),
|
||||
utils.MaskAddress(res.RecvAddress),
|
||||
@@ -196,7 +195,7 @@ func (t *Telegram) TronResourceChange(res model.TronResource) {
|
||||
}
|
||||
|
||||
func (t *Telegram) Welcome() {
|
||||
var text = `
|
||||
text := `
|
||||
👋 欢迎使用 BEpusdt,` + conf.Desc + `,如果您看到此消息,说明系统已启动成功!
|
||||
|
||||
📌当前版本:` + app.Version + `
|
||||
@@ -232,12 +231,11 @@ func (t *Telegram) sendMessage(p *bot.SendMessageParams) {
|
||||
p.ChatID = t.chatID
|
||||
p.MessageThreadID = t.topicID
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
_, err := t.api.SendMessage(ctx, p)
|
||||
if err != nil {
|
||||
|
||||
log.Warn("Bot Send Message Error:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,11 @@ func adminInit(e *gin.Engine) {
|
||||
var orderHdr = new(admin.Order)
|
||||
{
|
||||
PostRegister(orderRtr, "/list", true, orderHdr.List)
|
||||
PostRegister(orderRtr, "/create", true, orderHdr.Create)
|
||||
PostRegister(orderRtr, "/detail", true, orderHdr.Detail)
|
||||
PostRegister(orderRtr, "/paid", true, orderHdr.Paid)
|
||||
PostRegister(orderRtr, "/manual_notify", true, orderHdr.ManualNotify)
|
||||
PostRegister(orderRtr, "/del", true, orderHdr.Del)
|
||||
}
|
||||
|
||||
var rateRtr = e.Group("/api/rate")
|
||||
|
||||
@@ -10,6 +10,7 @@ func epusdtInit(engine *gin.Engine) {
|
||||
epHdr := new(epusdt.Epusdt)
|
||||
{
|
||||
epGrp.GET("/checkout-counter/:trade_id", epHdr.CheckoutCounter)
|
||||
epGrp.GET("/cashier/:trade_id", epHdr.CheckoutCashier)
|
||||
epGrp.GET("/check-status/:trade_id", epHdr.CheckStatus)
|
||||
}
|
||||
|
||||
@@ -18,5 +19,13 @@ func epusdtInit(engine *gin.Engine) {
|
||||
orderGrp.Use(epHdr.SignVerify)
|
||||
orderGrp.POST("/create-transaction", epHdr.CreateTransaction)
|
||||
orderGrp.POST("/cancel-transaction", epHdr.CancelTransaction)
|
||||
orderGrp.POST("/create-order", epHdr.CreateOrder)
|
||||
}
|
||||
|
||||
payApiGrp := engine.Group("/api/v1/pay")
|
||||
{
|
||||
payApiGrp.POST("/methods", epHdr.GetPaymentMethods)
|
||||
payApiGrp.POST("/update-order", epHdr.UpdateOrder)
|
||||
payApiGrp.POST("/notify", epHdr.Notify)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ func Handler() *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
engine = gin.New()
|
||||
|
||||
session := memstore.NewStore([]byte(conf.Secret))
|
||||
session := memstore.NewStore([]byte(model.GetK(model.AdminSecret)))
|
||||
session.Options(sessions.Options{
|
||||
MaxAge: 86400,
|
||||
HttpOnly: true,
|
||||
|
||||
@@ -31,8 +31,8 @@ func initCustomPayment(e *gin.Engine, path string) {
|
||||
template.Must(tmpl.ParseFS(static.Secure, "secure/secure.html"))
|
||||
e.SetHTMLTemplate(tmpl)
|
||||
|
||||
e.StaticFS("/payment", http.Dir(filepath.Join(path, "static")))
|
||||
e.StaticFS("/static", http.FS(subFS(static.Secure, "secure/static")))
|
||||
e.StaticFS("/payment/assets", http.Dir(filepath.Join(path, "assets")))
|
||||
e.StaticFS("/secure/assets", http.FS(subFS(static.Secure, "secure/assets")))
|
||||
|
||||
log.Info("成功注册自定义静态资源路径:", path)
|
||||
}
|
||||
@@ -44,8 +44,8 @@ func initDefaultPayment(e *gin.Engine) {
|
||||
template.Must(tmpl.ParseFS(static.Payment, "payment/views/*.html"))
|
||||
e.SetHTMLTemplate(tmpl)
|
||||
|
||||
e.StaticFS("/payment", http.FS(subFS(static.Payment, "payment/static")))
|
||||
e.StaticFS("/static", http.FS(subFS(static.Secure, "secure/static")))
|
||||
e.StaticFS("/payment/assets", http.FS(subFS(static.Payment, "payment/assets")))
|
||||
e.StaticFS("/secure/assets", http.FS(subFS(static.Secure, "secure/assets")))
|
||||
}
|
||||
|
||||
func subFS(src fs.FS, dir string) fs.FS {
|
||||
|
||||
@@ -22,17 +22,17 @@ import (
|
||||
)
|
||||
|
||||
type aptos struct {
|
||||
versionChunkSize int64
|
||||
versionConfirmedOffset int64
|
||||
lastVersion int64
|
||||
versionChunkSize int
|
||||
versionConfirmedOffset int
|
||||
lastVersion int
|
||||
versionQueue *chanx.UnboundedChan[version]
|
||||
client *http.Client
|
||||
earliestBlockTs atomic.Int64
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Start int64
|
||||
Limit int64
|
||||
Start int
|
||||
Limit int
|
||||
}
|
||||
|
||||
var apt aptos
|
||||
@@ -68,7 +68,7 @@ func newAptos() aptos {
|
||||
}
|
||||
|
||||
func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
if syncBreak(conf.Aptos) {
|
||||
if syncBreak(conf.Aptos, a.versionQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "ledger_version").Int()
|
||||
now := int(gjson.GetBytes(body, "ledger_version").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncVersionForward Error: invalid ledger_version:", now)
|
||||
|
||||
@@ -116,7 +116,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.versionQueue.In <- version{Start: a.lastVersion, Limit: sub}
|
||||
} else {
|
||||
chunks := (sub + a.versionChunkSize - 1) / a.versionChunkSize
|
||||
for i := int64(0); i < chunks; i++ {
|
||||
for i := 0; i < chunks; i++ {
|
||||
limit := a.versionChunkSize
|
||||
start := a.lastVersion + a.versionChunkSize*i
|
||||
if i == chunks-1 {
|
||||
@@ -133,7 +133,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.lastVersion = now
|
||||
}
|
||||
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int64) {
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Aptos)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)",
|
||||
@@ -153,7 +153,7 @@ func (a *aptos) syncVersionBackward(ctx context.Context, now int64) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if syncBreak(conf.Aptos) {
|
||||
if syncBreak(conf.Aptos, a.versionQueue.Len()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func (a *aptos) versionParse(n any) {
|
||||
timestamp := time.Unix(tsNano/1e9, tsNano%1e9)
|
||||
a.recordEarliestBlockTs(timestamp.Unix())
|
||||
|
||||
ver := trans.Get("version").Int()
|
||||
ver := int(trans.Get("version").Int())
|
||||
hash := trans.Get("hash").String()
|
||||
addrOwner := make(map[string]string) // [address] => owner address
|
||||
addrType := make(map[string]model.TradeType) // [address] => tradeType
|
||||
@@ -408,6 +408,15 @@ func (a *aptos) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if a.lastVersion == 0 {
|
||||
return
|
||||
}
|
||||
if a.lastVersion-o.RefBlockNum < a.versionConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", model.Endpoint(conf.Aptos)+"v1/transactions/by_hash/"+o.RefHash, nil)
|
||||
resp, err := a.client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -33,7 +32,7 @@ var chainBlockNum sync.Map
|
||||
|
||||
type block struct {
|
||||
RollDelayOffset int64 // 延迟偏移量,某些RPC节点如果不延迟,会报错 block is out of range,目前发现 https://rpc.xlayer.tech/ 存在此问题
|
||||
ConfirmedOffset int64 // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
ConfirmedOffset int // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
}
|
||||
|
||||
type evmNative struct {
|
||||
@@ -57,7 +56,7 @@ type evmBlock struct {
|
||||
}
|
||||
|
||||
func (e *evm) syncBlocksForward(ctx context.Context) {
|
||||
if syncBreak(e.Network) {
|
||||
if syncBreak(e.Network, e.blockScanQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -88,6 +87,12 @@ func (e *evm) syncBlocksForward(ctx context.Context) {
|
||||
}
|
||||
|
||||
var res = gjson.ParseBytes(body)
|
||||
if !res.IsObject() {
|
||||
log.Task.Warn(fmt.Sprintf("EVM 数据解析错误(%s): %s", e.Network, string(body)))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var now = utils.HexStr2Int(res.Get("result").String()).Int64() - e.Block.RollDelayOffset
|
||||
if now <= 0 {
|
||||
|
||||
@@ -144,7 +149,7 @@ func (e *evm) syncBlocksBackward(now int64) {
|
||||
defer ticker.Stop()
|
||||
|
||||
for from := start; from <= now; from += blockParseMaxNum {
|
||||
if syncBreak(e.Network) {
|
||||
if syncBreak(e.Network, e.blockScanQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -229,6 +234,8 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
return
|
||||
}
|
||||
|
||||
conf.RecordSuccess(e.Network)
|
||||
|
||||
nativeTransfers := make([]transfer, 0)
|
||||
blockTimestamp := make(map[string]time.Time)
|
||||
for _, itm := range gjson.ParseBytes(body).Array() {
|
||||
@@ -240,7 +247,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
return
|
||||
}
|
||||
|
||||
timestamp := utils.HexStr2Int(itm.Get("result.blockTimestamp").String()).Int64()
|
||||
timestamp := utils.HexStr2Int(itm.Get("result.timestamp").String()).Int64()
|
||||
blockTime := time.Unix(timestamp, 0)
|
||||
blockNumHex := itm.Get("result.number").String()
|
||||
blockTimestamp[blockNumHex] = blockTime
|
||||
@@ -248,7 +255,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
var array = itm.Get("result.transactions").Array()
|
||||
if e.Native.Parse && len(array) != 0 {
|
||||
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, utils.HexStr2Int(blockNumHex).Int64(), blockTime)...)
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, int(utils.HexStr2Int(blockNumHex).Int64()), blockTime)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +278,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
log.Task.Info(fmt.Sprintf("区块扫描完成(%s): %d → %d 成功率:%s", e.Network, b.From, b.To, conf.GetSuccessRate(e.Network)))
|
||||
}
|
||||
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int64, timestamp time.Time) []transfer {
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int, timestamp time.Time) []transfer {
|
||||
nativeTransfers := make([]transfer, 0)
|
||||
for _, tx := range array {
|
||||
if tx.Get("input").String() != "0x" {
|
||||
@@ -364,20 +371,13 @@ func (e *evm) parseEventTransfer(b evmBlock, timestamp map[string]time.Time) ([]
|
||||
continue
|
||||
}
|
||||
|
||||
blockNum, err := strconv.ParseInt(itm.Get("blockNumber").String(), 0, 64)
|
||||
if err != nil {
|
||||
log.Task.Warn("evmBlockParse Error parsing block number:", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
transfers = append(transfers, transfer{
|
||||
Network: e.Network,
|
||||
FromAddress: from,
|
||||
RecvAddress: recv,
|
||||
Amount: decimal.NewFromBigInt(amount, model.GetContractDecimal(to)),
|
||||
TxHash: itm.Get("transactionHash").String(),
|
||||
BlockNum: blockNum,
|
||||
BlockNum: cast.ToInt(itm.Get("blockNumber").String()),
|
||||
Timestamp: timestamp[itm.Get("blockNumber").String()],
|
||||
TradeType: tradeType,
|
||||
})
|
||||
@@ -391,6 +391,16 @@ func (e *evm) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
last, ok := chainBlockNum.Load(e.Network)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if last.(int)-o.RefBlockNum < e.Block.ConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["%s"],"id":1}`, o.RefHash))
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", e.rpcEndpoint(), bytes.NewBuffer(post))
|
||||
if err != nil {
|
||||
@@ -444,24 +454,30 @@ func (e *evm) rpcEndpoint() string {
|
||||
return model.Endpoint(model.Network(e.Network))
|
||||
}
|
||||
|
||||
func syncBreak(network string) bool {
|
||||
token := model.GetNetworkTrades(model.Network(network))
|
||||
if len(token) == 0 {
|
||||
func syncBreak(network string, num int) bool {
|
||||
if num >= blockQueueLimit {
|
||||
log.Task.Warn(fmt.Sprintf("%s 同步阻塞,当前区块消费堆积数量:%d", network, num))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
trades := model.GetNetworkTrades(model.Network(network))
|
||||
if len(trades) == 0 {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var count int64
|
||||
model.Db.Model(&model.Order{}).
|
||||
Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, token).
|
||||
model.Db.Model(&model.Wallet{}).
|
||||
Where("other_notify = ? and trade_type in (?)", model.WaOtherEnable, trades).
|
||||
Count(&count)
|
||||
if count > 0 {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
model.Db.Model(&model.Wallet{}).
|
||||
Where("other_notify = ? and trade_type in (?)", model.WaOtherEnable, token).
|
||||
model.Db.Model(&model.Order{}).
|
||||
Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trades).
|
||||
Count(&count)
|
||||
|
||||
return count == 0
|
||||
|
||||
@@ -25,9 +25,8 @@ func notifyRetry(context.Context) {
|
||||
}
|
||||
|
||||
for _, order := range tradeOrders {
|
||||
var next = utils.CalcNextNotifyTime(order.ConfirmedAt, order.NotifyNum)
|
||||
next := utils.CalcNextNotifyTime(*order.ConfirmedAt, order.NotifyNum)
|
||||
if time.Now().Unix() >= next.Unix() {
|
||||
|
||||
go notify.Handle(order)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package notify
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -31,55 +32,58 @@ type EpNotify struct {
|
||||
Status int `json:"status"` // 1:等待支付,2:支付成功,3:订单超时
|
||||
}
|
||||
|
||||
func Handle(order model.Order) {
|
||||
func Handle(order model.Order) error {
|
||||
if order.Status != model.OrderStatusSuccess {
|
||||
|
||||
return
|
||||
return errors.New("订单未支付 无法回调")
|
||||
}
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
var err error
|
||||
if order.ApiType == model.OrderApiTypeEpay {
|
||||
epay(ctx, order)
|
||||
|
||||
return
|
||||
err = epay(ctx, order)
|
||||
} else {
|
||||
err = epusdt(ctx, order)
|
||||
}
|
||||
|
||||
epusdt(ctx, order)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单回调成功:", order.TradeId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func epay(ctx context.Context, order model.Order) {
|
||||
func epay(ctx context.Context, order model.Order) error {
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
var notifyUrl = fmt.Sprintf("%s?%s", order.NotifyUrl, epay2.BuildNotifyParams(order))
|
||||
|
||||
postReq, err2 := http.NewRequestWithContext(ctx, "GET", notifyUrl, nil)
|
||||
if err2 != nil {
|
||||
log.Error("Notify NewRequest Error:", err2)
|
||||
|
||||
return
|
||||
return err2
|
||||
}
|
||||
|
||||
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
|
||||
resp, err := client.Do(postReq)
|
||||
if err != nil {
|
||||
log.Error("Notify Handle Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
markNotifyFail(order, fmt.Sprintf("resp.StatusCode != 200"))
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode)
|
||||
}
|
||||
|
||||
all, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
markNotifyFail(order, fmt.Sprintf("io.ReadAll(resp.Body) Error: %v", err))
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
var bodyStr = strings.ToLower(strings.TrimSpace(string(all)))
|
||||
@@ -88,19 +92,17 @@ func epay(ctx context.Context, order model.Order) {
|
||||
if !strings.Contains(bodyStr, "success") && !strings.Contains(bodyStr, "ok") {
|
||||
markNotifyFail(order, "商户系统必须响应 success 或 ok 才会认定回调成功")
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统必须响应 success 或 ok 才会认定回调成功,实际响应:%s", string(all))
|
||||
}
|
||||
|
||||
if err = order.SetNotifyState(model.OrderNotifyStateSucc); err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单通知成功:", order.OrderId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func epusdt(ctx context.Context, order model.Order) {
|
||||
func epusdt(ctx context.Context, order model.Order) error {
|
||||
var data = make(map[string]interface{})
|
||||
var body = EpNotify{
|
||||
TradeId: order.TradeId,
|
||||
@@ -113,15 +115,11 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
}
|
||||
var jsonBody, err = json.Marshal(body)
|
||||
if err != nil {
|
||||
log.Error("Notify Json Marshal Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(jsonBody, &data); err != nil {
|
||||
log.Error("Notify JSON Unmarshal Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
// 签名
|
||||
@@ -132,9 +130,9 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
var postReq, err2 = http.NewRequestWithContext(ctx, "POST", order.NotifyUrl, strings.NewReader(string(jsonBody)))
|
||||
if err2 != nil {
|
||||
markNotifyFail(order, err.Error())
|
||||
markNotifyFail(order, err2.Error())
|
||||
|
||||
return
|
||||
return err2
|
||||
}
|
||||
|
||||
postReq.Header.Set("Content-Type", "application/json")
|
||||
@@ -144,35 +142,33 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
if err != nil {
|
||||
markNotifyFail(order, err.Error())
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
markNotifyFail(order, fmt.Sprintf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode))
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode)
|
||||
}
|
||||
|
||||
if err = order.SetNotifyState(model.OrderNotifyStateSucc); err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单通知成功:", order.OrderId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Bepusdt(order model.Order) {
|
||||
if order.ApiType != model.OrderApiTypeEpusdt {
|
||||
func Bepusdt(o model.Order) {
|
||||
if o.ApiType != model.OrderApiTypeEpusdt {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var todo = func() error {
|
||||
var o model.Order
|
||||
var db = model.Db.Begin()
|
||||
if err := db.Where("trade_id = ? and status = ?", order.TradeId, order.Status).First(&o).Error; err != nil {
|
||||
if err := db.Where("trade_id = ? and status = ?", o.TradeId, o.Status).Limit(1).Find(&o).Error; err != nil {
|
||||
db.Rollback()
|
||||
|
||||
return err
|
||||
@@ -220,7 +216,7 @@ func Bepusdt(order model.Order) {
|
||||
if err2 != nil {
|
||||
db.Rollback()
|
||||
|
||||
return err
|
||||
return err2
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -241,7 +237,7 @@ func Bepusdt(order model.Order) {
|
||||
|
||||
all, _ := io.ReadAll(resp.Body)
|
||||
|
||||
log.Info(fmt.Sprintf("订单回调成功[%d]:%s %s", order.Status, o.TradeId, string(all)))
|
||||
log.Info(fmt.Sprintf("订单回调成功[%d]:%s %s", o.Status, o.TradeId, string(all)))
|
||||
|
||||
db.Commit()
|
||||
|
||||
@@ -254,8 +250,8 @@ func Bepusdt(order model.Order) {
|
||||
}()
|
||||
}
|
||||
|
||||
func markNotifyFail(order model.Order, reason string) {
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", order.TradeId, reason, order.SetNotifyState(model.OrderNotifyStateFail)))
|
||||
func markNotifyFail(o model.Order, reason string) {
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", o.TradeId, reason, o.SetNotifyState(model.OrderNotifyStateFail)))
|
||||
|
||||
notifier.NotifyFail(order, reason)
|
||||
notifier.NotifyFail(o, reason)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func plasmaInit() {
|
||||
ctx := context.Background()
|
||||
pol := evm{
|
||||
xpl := evm{
|
||||
Network: conf.Plasma,
|
||||
Block: block{
|
||||
ConfirmedOffset: 40,
|
||||
@@ -20,7 +20,7 @@ func plasmaInit() {
|
||||
blockScanQueue: chanx.NewUnboundedChan[evmBlock](ctx, 30),
|
||||
}
|
||||
|
||||
Register(Task{Callback: pol.blockDispatch})
|
||||
Register(Task{Callback: pol.syncBlocksForward, Duration: time.Second * 5})
|
||||
Register(Task{Callback: pol.tradeConfirmHandle, Duration: time.Second * 5})
|
||||
Register(Task{Callback: xpl.blockDispatch})
|
||||
Register(Task{Callback: xpl.syncBlocksForward, Duration: time.Second * 5})
|
||||
Register(Task{Callback: xpl.tradeConfirmHandle, Duration: time.Second * 5})
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/v03413/bepusdt/app/log"
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
)
|
||||
|
||||
@@ -19,12 +21,16 @@ type Rate struct {
|
||||
|
||||
func (Rate) Sync(ctx context.Context) {
|
||||
var lastAt model.Rate
|
||||
model.Db.Model(&lastAt).Order("id desc").Find(&lastAt)
|
||||
model.Db.Model(&lastAt).Order("id desc").Limit(1).Find(&lastAt)
|
||||
var interval = cast.ToInt64(model.GetC(model.RateSyncInterval))
|
||||
if lastAt.ID != 0 && time.Now().Unix()-lastAt.CreatedAt.Time().Unix() < interval {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
model.CoingeckoRate()
|
||||
err := model.CoingeckoRate()
|
||||
if err != nil {
|
||||
|
||||
log.Warn(fmt.Sprintf("同步汇率失败: %s", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import (
|
||||
// - https://github.com/solana-program/token/blob/6d18ff73b1dd30703a30b1ca941cb0f1d18c2b2a/program/src/instruction.rs
|
||||
|
||||
type solana struct {
|
||||
slotConfirmedOffset int64
|
||||
lastSlotNum int64
|
||||
slotQueue *chanx.UnboundedChan[int64]
|
||||
slotConfirmedOffset int
|
||||
lastSlotNum int
|
||||
slotQueue *chanx.UnboundedChan[int]
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ func newSolana() solana {
|
||||
return solana{
|
||||
slotConfirmedOffset: 60,
|
||||
lastSlotNum: 0,
|
||||
slotQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
slotQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
client: utils.NewHttpClient(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
if syncBreak(conf.Solana) {
|
||||
if syncBreak(conf.Solana, s.slotQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "result").Int()
|
||||
now := int(gjson.GetBytes(body, "result").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncSlotForward Error: invalid slot number:", now)
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.syncSlotBackward(now)
|
||||
}
|
||||
|
||||
if now-s.lastSlotNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
if now-s.lastSlotNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
func (s *solana) syncSlotBackward(now int64) {
|
||||
func (s *solana) syncSlotBackward(now int) {
|
||||
if now == 0 || s.lastSlotNum != 0 {
|
||||
|
||||
return
|
||||
@@ -132,14 +132,14 @@ func (s *solana) syncSlotBackward(now int64) {
|
||||
}
|
||||
|
||||
// Solana 大概1秒3个区块(大概值,实际存在波动)
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3 // 计算需要反向扫描的区块数量
|
||||
num := int((time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3) // 计算需要反向扫描的区块数量
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Millisecond * 125)
|
||||
defer ticker.Stop()
|
||||
|
||||
for i := int64(0); i < num; i++ {
|
||||
if syncBreak(conf.Solana) {
|
||||
for i := 0; i < num; i++ {
|
||||
if syncBreak(conf.Solana, s.slotQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (s *solana) slotDispatch(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (s *solana) slotParse(n any) {
|
||||
slot := n.(int64)
|
||||
slot := n.(int)
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[%d,{"encoding":"json","maxSupportedTransactionVersion":0,"transactionDetails":"full","rewards":false}]}`, slot))
|
||||
network := conf.Solana
|
||||
|
||||
@@ -361,6 +361,15 @@ func (s *solana) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if s.lastSlotNum == 0 {
|
||||
return
|
||||
}
|
||||
if s.lastSlotNum-o.RefBlockNum < s.slotConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["%s"],{"searchTransactionHistory":true}]}`, o.RefHash))
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", model.Endpoint(conf.Solana), bytes.NewBuffer(post))
|
||||
resp, err := s.client.Do(req)
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
)
|
||||
|
||||
// 区块扫描队列最大长度,避免可能因为 Rpc Rate Limit 问题导致消费队列堆积,进而导致OOM,暂时简单限制队列长度
|
||||
// 如果直接使用固定长度的 Channel 控制,会导致区块高度同步时也彻底阻塞,无法对外界输出日志导致无法观察,彻底垮掉
|
||||
// 如果确实是因为 Rate Limit 问题导致的异常,优先考虑的是提升 Rpc 节点的质量和稳定性
|
||||
const blockQueueLimit = 100
|
||||
|
||||
type Task struct {
|
||||
Duration time.Duration
|
||||
Callback func(ctx context.Context)
|
||||
|
||||
@@ -23,7 +23,7 @@ type transfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType model.TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type resource struct {
|
||||
@@ -40,7 +40,8 @@ var resourceQueue = chanx.NewUnboundedChan[[]resource](context.Background(), 30)
|
||||
var notOrderQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 非订单队列
|
||||
var transferQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 交易转账队列
|
||||
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const orderCheckInterval = time.Second * 10 // 订单过期检查间隔
|
||||
|
||||
func init() {
|
||||
Register(Task{Callback: orderTransferHandle})
|
||||
@@ -50,6 +51,7 @@ func init() {
|
||||
|
||||
func orderTransferHandle(ctx context.Context) {
|
||||
var batch = make([]transfer, 0, 1000)
|
||||
var lastCheckTime = time.Now()
|
||||
ticker := time.NewTicker(batchInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
@@ -63,11 +65,22 @@ func orderTransferHandle(ctx context.Context) {
|
||||
}
|
||||
batch = append(batch, transfers...)
|
||||
case <-ticker.C:
|
||||
// 每10秒强制检查一次过期订单,即使没有交易,防止无交易时订单不过期
|
||||
var shouldCheck = time.Since(lastCheckTime) >= orderCheckInterval
|
||||
if len(batch) == 0 && !shouldCheck {
|
||||
continue
|
||||
}
|
||||
|
||||
if shouldCheck {
|
||||
lastCheckTime = time.Now()
|
||||
}
|
||||
|
||||
var other = make([]transfer, 0)
|
||||
// getAllWaitingOrders 内部包含过期检查逻辑
|
||||
var orders = getAllWaitingOrders()
|
||||
if len(batch) == 0 {
|
||||
continue
|
||||
}
|
||||
var other = make([]transfer, 0)
|
||||
var orders = getAllWaitingOrders()
|
||||
for _, t := range batch {
|
||||
// 判断数额是否在允许范围内
|
||||
if !model.IsAmountValid(t.TradeType, t.Amount) {
|
||||
@@ -84,12 +97,14 @@ func orderTransferHandle(ctx context.Context) {
|
||||
var matched bool
|
||||
for _, o := range orderList {
|
||||
// 金额前缀匹配
|
||||
if !strings.HasPrefix(t.Amount.String(), o.Amount) {
|
||||
if !amountMatch(t.Amount, o.Amount, string(o.TradeType)) {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// 有效期检测
|
||||
if !o.CreatedAt.Before(t.Timestamp) || !o.ExpiredAt.After(t.Timestamp) {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -255,3 +270,40 @@ func getConfirmingOrders(tradeType []model.TradeType) []model.Order {
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func amountMatch(amount decimal.Decimal, target, tradeType string) bool {
|
||||
mode := model.GetC(model.PaymentMatchMode)
|
||||
switch model.MatchMode(mode) {
|
||||
case model.Classic:
|
||||
return amount.String() == target
|
||||
case model.HasPrefix:
|
||||
return strings.HasPrefix(amount.String(), target)
|
||||
case model.RoundOff:
|
||||
t, err := decimal.NewFromString(target)
|
||||
if err != nil {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
_, precision := model.GetAtomicity(model.TradeType(tradeType)) // 标准精度
|
||||
precision2 := abs(t.Exponent()) // 实际精度
|
||||
if precision2 != precision {
|
||||
|
||||
precision = precision2
|
||||
}
|
||||
|
||||
a := amount.Round(precision)
|
||||
t = t.Round(precision)
|
||||
|
||||
return a.Equal(t)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func abs(n int32) int32 {
|
||||
if n < 0 {
|
||||
return -n
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
@@ -32,10 +32,11 @@ var usdtTrc20ContractAddress = []byte{0x41, 0xa6, 0x14, 0xf8, 0x03, 0xb6, 0xfd,
|
||||
var usdcTrc20ContractAddress = []byte{0x41, 0x34, 0x87, 0xb6, 0x3d, 0x30, 0xb5, 0xb2, 0xc8, 0x7f, 0xb7, 0xff, 0xa8, 0xbc, 0xfa, 0xde, 0x38, 0xea, 0xac, 0x1a, 0xbe}
|
||||
|
||||
type tron struct {
|
||||
lastBlockNum int64
|
||||
blockScanQueue *chanx.UnboundedChan[int64]
|
||||
conn map[string]*grpc.ClientConn
|
||||
connMu sync.RWMutex
|
||||
lastBlockNum int
|
||||
blockConfirmedOffset int
|
||||
blockScanQueue *chanx.UnboundedChan[int]
|
||||
conn map[string]*grpc.ClientConn
|
||||
connMu sync.RWMutex
|
||||
}
|
||||
|
||||
var tr tron
|
||||
@@ -49,9 +50,10 @@ func init() {
|
||||
|
||||
func newTron() tron {
|
||||
return tron{
|
||||
lastBlockNum: 0,
|
||||
blockScanQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
conn: make(map[string]*grpc.ClientConn),
|
||||
lastBlockNum: 0,
|
||||
blockConfirmedOffset: 30,
|
||||
blockScanQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
conn: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +81,10 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var now = block.BlockHeader.RawData.Number
|
||||
var now = int(block.BlockHeader.RawData.Number)
|
||||
|
||||
// 区块高度变化过大,强制丢块重扫
|
||||
if now-t.lastBlockNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
if now-t.lastBlockNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
t.syncBlocksBackward(now)
|
||||
t.lastBlockNum = now - 1
|
||||
}
|
||||
@@ -103,7 +105,7 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
}
|
||||
|
||||
// syncBlocksBackward 反向同步区块,针对程序启动前就已经存在待支付订单时,补齐之前的区块数据,自适应偏移数量
|
||||
func (t *tron) syncBlocksBackward(now int64) {
|
||||
func (t *tron) syncBlocksBackward(now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Tron)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trade).Order("created_at asc").Limit(1).Find(&o)
|
||||
@@ -114,7 +116,7 @@ func (t *tron) syncBlocksBackward(now int64) {
|
||||
|
||||
// 波场出块速度大概3秒一个,同时再冗余5个区块
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) / 3 // 计算需要反向扫描的区块数量
|
||||
start := now - num - 5 // 计算反向扫描的起始区块高度
|
||||
start := now - int(num) - 5 // 计算反向扫描的起始区块高度
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
@@ -156,7 +158,7 @@ func (t *tron) blockDispatch(context.Context) {
|
||||
}
|
||||
|
||||
func (t *tron) blockParse(n any) {
|
||||
var num = n.(int64)
|
||||
var num = n.(int)
|
||||
|
||||
var conn *grpc.ClientConn
|
||||
var err error
|
||||
@@ -169,11 +171,11 @@ func (t *tron) blockParse(n any) {
|
||||
conf.RecordSuccess(conf.Tron)
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: num})
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: int64(num)})
|
||||
cancel()
|
||||
if err2 != nil {
|
||||
conf.RecordFailure(conf.Tron)
|
||||
t.blockScanQueue.In <- num
|
||||
t.blockScanQueue.In <- int(num)
|
||||
log.Task.Warn("GetBlockByNum2 ", err2)
|
||||
|
||||
return
|
||||
@@ -248,7 +250,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: t.base58CheckEncode(foo.ToAddress),
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.TronTrx,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -278,7 +280,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.UsdtTrc20,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -304,7 +306,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -319,7 +321,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: to,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -395,6 +397,12 @@ func (t *tron) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if t.lastBlockNum == 0 || t.lastBlockNum-o.RefBlockNum < t.blockConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := t.client()
|
||||
if err != nil {
|
||||
log.Task.Error("grpc.NewClient", err)
|
||||
@@ -460,6 +468,12 @@ func (t *tron) base58CheckEncode(input []byte) string {
|
||||
}
|
||||
|
||||
func (t *tron) syncBreak() bool {
|
||||
if t.blockScanQueue.Len() >= blockQueueLimit {
|
||||
log.Task.Warn("tron 同步阻塞,当前区块消费堆积数量:", t.blockScanQueue.Len())
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var count int64 = 0
|
||||
trade := []model.TradeType{model.TronTrx, model.UsdtTrc20, model.UsdcTrc20}
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trade).Count(&count)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -204,3 +205,34 @@ func StrSha256(str string) string {
|
||||
hash.Write([]byte(str))
|
||||
return fmt.Sprintf("%x", hash.Sum(nil))
|
||||
}
|
||||
|
||||
// GetRequestHost 识别完整的请求主机地址
|
||||
func GetRequestHost(r *http.Request) string {
|
||||
scheme := "http"
|
||||
|
||||
if r.TLS != nil {
|
||||
scheme = "https"
|
||||
} else {
|
||||
// 检查各种代理转发的协议头
|
||||
// Nginx、Apache、Caddy 通用
|
||||
if proto := r.Header.Get("X-Forwarded-Proto"); proto == "https" {
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("X-Forwarded-Ssl") == "on" {
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("Front-End-Https") == "on" {
|
||||
// Apache mod_proxy
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("X-Url-Scheme") == "https" {
|
||||
// Caddy
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("CF-Visitor") != "" {
|
||||
// Cloudflare
|
||||
// CF-Visitor 格式: {"scheme":"https"}
|
||||
if strings.Contains(r.Header.Get("CF-Visitor"), `"scheme":"https"`) {
|
||||
scheme = "https"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scheme + "://" + r.Host
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
package app
|
||||
|
||||
// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
|
||||
const Version = "1.23.0"
|
||||
var Version = "dev-unknown-version"
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
services:
|
||||
bepusdt:
|
||||
image: v03413/bepusdt:latest # 如果想使用最新的开发版本,可以将镜像名 latest 替换为 beta
|
||||
container_name: bepusdt
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./conf.toml:/usr/local/bepusdt/conf.toml
|
||||
- ./data:/var/lib/bepusdt
|
||||
@@ -1,51 +0,0 @@
|
||||
# 异次元发卡对接教程
|
||||
|
||||
异次元发卡开源地址:https://github.com/lizhipay/acg-faka
|
||||
后台插件实际支持epusdt,但存在一些问题,这里做了一些修复并且增加了对TRX的支持,修复兼容版下载地址:[点击下载](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/acg-faka/Epusdt.zip)
|
||||
|
||||
## 对接教程
|
||||
|
||||
### 1. 插件替换
|
||||
|
||||
如果已经安装了原版epusdt插件,请先卸载删除原版插件,然后将下载的修复兼容版解压上传到异次元网站跟目录`app/Pay`,
|
||||
最后确保插件目录结构如下:
|
||||
|
||||
```
|
||||
├── Epusdt
|
||||
│ ├── Config
|
||||
│ │ ├── Config.php
|
||||
│ │ ├── Info.php
|
||||
│ │ └── Submit.php
|
||||
│ └── Impl
|
||||
│ ├── Pay.php
|
||||
│ └── Signature.php
|
||||
```
|
||||
|
||||
⚠️ 注意:请确保插件整个目录的权限为`www:www`(一般都是这个),如果不是请自行修改,否则无法正常使用。
|
||||
|
||||
返回异次元后台,点击`支付插件`,如果发现以下如图所示,说明插件安装成功。
|
||||

|
||||
|
||||
### 2. 插件配置
|
||||
|
||||
- 支付网关:必须`http(s)://`开头,斜杠`/`结尾
|
||||
- 密钥:搭建`Bepusdt`时候的参数`AUTH_TOKEN`
|
||||
|
||||

|
||||
|
||||
找到插件,点击右侧的`配置`按钮,填写好相关参数,点击`确认`保存即可。
|
||||
|
||||
### 3. 添加支付
|
||||
|
||||
#### 添加支付
|
||||
|
||||
异次元后台 -> 支付接口 -> 添加支付 -> 选择`Epusdt`
|
||||
|
||||

|
||||

|
||||
|
||||
#### 支付配置
|
||||
|
||||

|
||||
|
||||
如上图所示,重点就是`支付类型`,按你的需求选择`USDT-TRC20`或者`TRON-TRX`,其他参数按照实际情况填写即可。
|
||||
|
Before Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 314 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 346 KiB |
@@ -0,0 +1,53 @@
|
||||
# 异次元发卡 BEpusdt 对接指南
|
||||
|
||||
异次元应用商店提供的 `Epusdt` 插件存在一些问题,本文档提供优化适配版本的安装和配置方案。
|
||||
|
||||
## 对接流程
|
||||
|
||||
### 1. 前置条件
|
||||
|
||||
请先按照异次元官方文档完成 `Epusdt` 支付插件的标准安装流程。
|
||||
|
||||
- 位置:应用商店 → 支付接口
|
||||
- 搜索并安装官方 `Epusdt` 插件
|
||||
|
||||
### 2. 插件更新
|
||||
|
||||
[下载兼容适配版本](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/api/acg-faka/Epusdt.zip)
|
||||
|
||||
**安装步骤:**
|
||||
|
||||
1. 进入异次元网站根目录
|
||||
2. 定位到 `app/Plugins/Epusdt` 目录
|
||||
3. 删除目录内所有文件
|
||||
4. 解压下载的插件包,将所有文件移入该目录
|
||||
|
||||
**权限配置:**
|
||||
|
||||
⚠️ 确保插件目录权限为 `www:www`(通常为默认配置)。如权限不符,请执行:
|
||||
|
||||
```bash
|
||||
chown -R www:www app/Plugins/Epusdt
|
||||
chmod -R 755 app/Plugins/Epusdt
|
||||
```
|
||||
|
||||
### 3. 插件配置
|
||||
|
||||
在异次元后台进行以下配置:
|
||||
|
||||
| 配置项 | 说明 | 示例 |
|
||||
|------|------------------------------|----------------------------|
|
||||
| 支付网关 | 必须以 `http(s)://` 开头,以 `/` 结尾 | `https://api.example.com/` |
|
||||
| 对接密钥 | 从 BEpusdt 后台获取 | - |
|
||||
| 法币单位 | 按需选择,默认推荐 `CNY` | `CNY` `USD` `JPY` |
|
||||
|
||||
### 4. 创建支付方式
|
||||
|
||||
在异次元后台完成以下操作:
|
||||
|
||||
1. 导航到:支付接口 → 添加支付
|
||||
2. 选择支付插件:`BEpusdt`
|
||||
3. 根据业务需求填写相关参数
|
||||
4. 保存配置
|
||||
|
||||
配置完成后,系统将自动启用该支付方式。
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
## 接口列表
|
||||
|
||||
### 1. 创建订单
|
||||
### 1. 创建交易
|
||||
|
||||
创建支付订单并获取收银台地址。
|
||||
创建支付订单并获取收银台付款地址。
|
||||
|
||||
> **注意**:使用相同 `order_id` 创建订单时,系统会根据最新参数重建订单(订单金额、交易类型、收款地址、法币类型),同时超时时间重置。这意味着商户可以基于同一订单号实现独立收银台,灵活变更支付参数。
|
||||
|
||||
@@ -37,7 +37,7 @@ POST /api/v1/order/create-transaction
|
||||
| fiat | string | ❌ | 法币类型,默认 `CNY`<br/>可选:`CNY`、`USD`、`EUR`、`GBP`、`JPY` |
|
||||
| address | string | ❌ | 指定收款地址(留空则自动分配) |
|
||||
| name | string | ❌ | 商品名称 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 60 秒<br/>留空则使用配置文件 `expire_time`,默认 600 秒 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 120 秒<br/>留空则使用配置 `payment_timeout`,默认 600 秒 |
|
||||
| rate | string | ❌ | 强制指定汇率,支持多种写法:<br/>• `7.4` - 固定汇率 7.4<br/>• `~1.02` - 最新汇率上浮 2%<br/>• `~0.97` - 最新汇率下浮 3%<br/>• `+0.3` - 最新汇率加 0.3<br/>• `-0.2` - 最新汇率减 0.2<br/>留空则使用系统配置汇率 |
|
||||
|
||||
#### 请求示例
|
||||
@@ -69,9 +69,10 @@ POST /api/v1/order/create-transaction
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.actual_amount | string | 实际支付金额(加密货币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.token | string | 收款地址 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台地址 |
|
||||
| data.payment_url | string | 收银台付款链接地址 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
@@ -89,6 +90,7 @@ POST /api/v1/order/create-transaction
|
||||
"actual_amount": "4.25",
|
||||
"token": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
||||
"expiration_time": 1200,
|
||||
"status": 1,
|
||||
"payment_url": "https://example.com/pay/checkout-counter/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
@@ -97,7 +99,7 @@ POST /api/v1/order/create-transaction
|
||||
|
||||
---
|
||||
|
||||
### 2. 取消订单
|
||||
### 2. 取消交易订单
|
||||
|
||||
取消指定订单,系统将停止监控该订单并释放金额占用。
|
||||
|
||||
@@ -138,7 +140,271 @@ POST /api/v1/order/cancel-transaction
|
||||
|
||||
---
|
||||
|
||||
### 3. 支付回调通知
|
||||
### 3. 创建订单
|
||||
|
||||
创建支付订单并获取收银台付款链接,让用户自由选择已添加的付款方式。
|
||||
|
||||
> **注意**:使用相同 `order_id` 创建订单时,系统会根据最新参数重建订单(订单金额、交易类型、收款地址、法币类型),同时超时时间重置。这意味着商户可以基于同一订单号实现独立收银台,灵活变更支付参数。
|
||||
|
||||
#### 请求地址
|
||||
|
||||
```http
|
||||
POST /api/v1/order/create-order
|
||||
```
|
||||
|
||||
#### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------------|--------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| order_id | string | ✅ | 商户订单编号(唯一标识) |
|
||||
| amount | number | ✅ | 支付金额(法币金额) |
|
||||
| notify_url | string | ✅ | 支付结果异步回调地址 |
|
||||
| redirect_url | string | ✅ | 支付成功后商户跳转地址 |
|
||||
| signature | string | ✅ | 签名字符串(详见[签名算法](#签名算法)) |
|
||||
| currencies | string | ❌ | 限定交易币种,留空则提不限制付款币种。<br/>多个币种请使用半角逗号分隔,黑名单模式以短横线开头。<br/>例如可配置为:<br/>`USDT`(仅限 USDT)<br/>`USDT,USDC` (限 USDT/USDC)<br/>`-ETH,-BNB` (表示排除 ETH/BNB 两个币种) |
|
||||
| fiat | string | ❌ | 法币类型,默认 `CNY`<br/>可选:`CNY`、`USD`、`EUR`、`GBP`、`JPY` |
|
||||
| name | string | ❌ | 商品名称 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 180 秒<br/>留空则使用配置 `payment_timeout`,默认 600 秒 |
|
||||
|
||||
#### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"order_id": "20250120001",
|
||||
"amount": 28.88,
|
||||
"fiat": "CNY",
|
||||
"currencies": "USDT,USDC",
|
||||
"name": "测试商品",
|
||||
"notify_url": "https://example.com/notify",
|
||||
"redirect_url": "https://example.com/success",
|
||||
"timeout": 1200,
|
||||
"signature": "1cd4b52df5587cfb1968b0c0c6e156cd"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应参数
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
|----------------------|--------|--------------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 订单数据 |
|
||||
| data.fiat | string | 交易法币类型 |
|
||||
| data.trade_id | string | 系统交易 ID |
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台订单链接 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
#### 响应示例
|
||||
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"fiat": "CNY",
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"order_id": "20250120001",
|
||||
"amount": "28.88",
|
||||
"expiration_time": 1200,
|
||||
"payment_url": "https://example.com/pay/order/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. 更新订单付款方式
|
||||
|
||||
用于向订单付款链接传递付款方式,得到收银台付款地址。
|
||||
|
||||
> **注意**:使用相同 `trade_id` 更新订单时,系统会根据最新交易类型更新订单付款方式。
|
||||
|
||||
#### 请求地址
|
||||
|
||||
```http
|
||||
POST /api/v1/pay/update-order
|
||||
```
|
||||
|
||||
#### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------------|--------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| trade_id | string | ✅ | 系统交易 ID |
|
||||
| currency | string | ✅ | 加密货币币种<br/>您已添加的加密货币币种,可选:`USDT`、`USDC`、`TRX` 等。 |
|
||||
| network | string | ✅ | 加密货币所属的网络名<br/>例如:`tron`、`polygon`、`bsc` 等。 |
|
||||
|
||||
#### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"currency": "USDT",
|
||||
"network": "tron"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应参数
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
|----------------------|--------|--------------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 订单数据 |
|
||||
| data.fiat | string | 交易法币类型 |
|
||||
| data.trade_id | string | 系统交易 ID |
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.actual_amount | string | 实际支付金额(加密货币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台订单链接 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
#### 响应示例
|
||||
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"fiat": "CNY",
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"order_id": "20250120001",
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"expiration_time": 1200,
|
||||
"status": 1,
|
||||
"payment_url": "https://example.com/pay/order/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. 订单可用付款方式列表:
|
||||
|
||||
## 接口说明
|
||||
- **URL**:`POST /api/v1/pay/methods`
|
||||
|
||||
---
|
||||
|
||||
## 请求参数
|
||||
|
||||
### 请求体(JSON)
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| trade_id | string | 是 | 系统交易 ID |
|
||||
| currency | string | 否 | 货币名称(如 USDT / USDC / TRX),不传则返回全部可用方式 |
|
||||
|
||||
### 请求示例
|
||||
```json
|
||||
{
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 响应参数
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 数据对象 |
|
||||
| data.methods | array | 可用付款方式列表 |
|
||||
|
||||
### methods 字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| amount | number | 应付金额(法币) |
|
||||
| actual_amount | number | 实际支付金额(加密货币) |
|
||||
| fiat | string | 应付金额法币单位 |
|
||||
| exchange_rate | number | 汇率 |
|
||||
| currency | string | 货币名称 |
|
||||
| network | string | 网络名称 |
|
||||
| token_net_name | string | 代币协议标准名 |
|
||||
| token_custom_name | string | 用户自定义显示名称 |
|
||||
| is_popular | boolean | 是否为流行网络 |
|
||||
|
||||
---
|
||||
|
||||
## 响应示例
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"methods": [
|
||||
{
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "USDT",
|
||||
"network": "bsc",
|
||||
"token_net_name": "BEP20",
|
||||
"token_custom_name": "",
|
||||
"is_popular": true
|
||||
},
|
||||
{
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "USDC",
|
||||
"network": "arbitrum",
|
||||
"token_net_name": "Arbitrum",
|
||||
"token_custom_name": "ARBITRUM-ONE",
|
||||
"is_popular": true
|
||||
},
|
||||
{
|
||||
"amount": "34.28",
|
||||
"actual_amount": "10",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "TRX",
|
||||
"network": "tron",
|
||||
"token_net_name": "TRC20",
|
||||
"token_custom_name": "",
|
||||
"is_popular": true
|
||||
},
|
||||
]
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
TODO: `is_popular` 当前临时返回为 `false` 待后期完善该功能。
|
||||
|
||||
TODO: `token_custom_name` 当前临时返回为空字符串,待后期完善该功能。
|
||||
|
||||
## 如果货币不存在则不响应内容
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"methods": [
|
||||
]
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 6. 支付回调通知
|
||||
|
||||
订单状态变更时,系统会向 `notify_url` 发送 POST 请求。
|
||||
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
# Dujiao-Next 对接教程
|
||||
|
||||
本文档介绍如何在 [Dujiao-Next](https://github.com/dujiao-next/dujiao-next)(独角next)中对接 BEpusdt。
|
||||
|
||||
## 前置条件
|
||||
|
||||
- BEpusdt 已成功安装并运行
|
||||
- Dujiao-Next 已部署
|
||||
|
||||
## 配置步骤
|
||||
|
||||
### 1. 进入支付渠道配置
|
||||
|
||||
Dujiao-Next 后台 → 支付渠道 → 新增渠道
|
||||
|
||||
### 2. 基本参数填写
|
||||
|
||||
| 参数名称 | 填写内容 | 说明 |
|
||||
|---------|---------|------|
|
||||
| 渠道名称 | USDT-TRC20 支付 | 自定义名称,建议包含币种 |
|
||||
| 渠道类型 | `epusdt` | 固定值,选择 BEpusdt |
|
||||
| 支付方式 | `usdt-trc20` / `usdc-trc20` / `trx` | 选择支持的币种 |
|
||||
| 交互方式 | `qr` 或 `redirect` | 二维码或跳转收银台 |
|
||||
|
||||
### 3. 支持的渠道类型
|
||||
|
||||
Dujiao-Next 支持以下 BEpusdt 币种:
|
||||
|
||||
| 渠道类型 | 说明 | 对应 trade_type |
|
||||
|---------|------|----------------|
|
||||
| `usdt-trc20` | USDT (TRC20) | `usdt.trc20` |
|
||||
| `usdc-trc20` | USDC (TRC20) | `usdc.trc20` |
|
||||
| `trx` | TRX | `tron.trx` |
|
||||
|
||||
> **注意**:选择渠道类型后,系统会自动设置对应的 `trade_type`,无需手动填写。
|
||||
|
||||
### 4. 渠道配置参数
|
||||
|
||||
在「渠道配置」中填写以下 JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"gateway_url": "https://your-bepusdt-domain.com",
|
||||
"auth_token": "your-api-token",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://your-api-domain.com/api/v1/payments/callback",
|
||||
"return_url": "https://your-user-domain.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 配置参数说明
|
||||
|
||||
| 参数 | 必填 | 说明 | 示例 |
|
||||
|------|------|------|------|
|
||||
| `gateway_url` | ✅ | BEpusdt 网关地址 | `https://pay.example.com` |
|
||||
| `auth_token` | ✅ | BEpusdt API Token | 从 BEpusdt 后台获取 |
|
||||
| `trade_type` | ❌ | 交易类型(自动设置) | `usdt.trc20` / `usdc.trc20` / `tron.trx` |
|
||||
| `fiat` | ❌ | 法币类型,默认 `CNY` | `CNY` / `USD` |
|
||||
| `notify_url` | ✅ | 异步回调地址 | `https://api.example.com/api/v1/payments/callback` |
|
||||
| `return_url` | ✅ | 支付成功跳转地址 | `https://shop.example.com/pay` |
|
||||
|
||||
> **重要提示**:
|
||||
> - `trade_type` 会根据「支付方式」自动设置,无需在配置中填写
|
||||
> - `notify_url` 路径必须是 `/api/v1/payments/callback`(不是 `/api/public/payment/callback`)
|
||||
> - `return_url` 路径必须是 `/pay`(不是 `/order` 或 `/payment`)
|
||||
|
||||
## 获取 API Token
|
||||
|
||||
1. 登录 BEpusdt 后台
|
||||
2. 系统管理 → 基本设置 → API 设置
|
||||
3. 复制「对接令牌」
|
||||
|
||||
## 配置示例
|
||||
|
||||
### 示例 1:USDT-TRC20 支付
|
||||
|
||||
```
|
||||
渠道名称: USDT-TRC20 支付
|
||||
渠道类型: epusdt
|
||||
支付方式: usdt-trc20
|
||||
交互方式: qr
|
||||
|
||||
渠道配置:
|
||||
{
|
||||
"gateway_url": "http://127.0.0.1:8088",
|
||||
"auth_token": "your-token-here",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://api.example.com/api/v1/payments/callback",
|
||||
"return_url": "https://shop.example.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
### 示例 2:TRX 支付
|
||||
|
||||
```
|
||||
渠道名称: TRX 支付
|
||||
渠道类型: epusdt
|
||||
支付方式: trx
|
||||
交互方式: redirect
|
||||
|
||||
渠道配置:
|
||||
{
|
||||
"gateway_url": "http://127.0.0.1:8088",
|
||||
"auth_token": "your-token-here",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://api.example.com/api/v1/payments/callback",
|
||||
"return_url": "https://shop.example.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
## 回调机制说明
|
||||
|
||||
### 异步通知(notify_url)
|
||||
|
||||
BEpusdt 会在支付状态变化时,向 `notify_url` 发送 POST 请求:
|
||||
|
||||
```
|
||||
POST /api/v1/payments/callback
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
order_id=xxx&trade_id=xxx&amount=xxx&actual_amount=xxx&token=xxx&...&signature=xxx
|
||||
```
|
||||
|
||||
Dujiao-Next 会验证签名并更新订单状态。
|
||||
|
||||
### 同步跳转(return_url)
|
||||
|
||||
用户支付完成后,BEpusdt 会跳转到 `return_url`,并附带参数:
|
||||
|
||||
```
|
||||
https://shop.example.com/pay?order_id=xxx&epusdt_return=1
|
||||
```
|
||||
|
||||
Dujiao-Next 前端会检测 `epusdt_return=1` 参数,自动查询订单状态并显示支付结果。
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 支付创建失败
|
||||
|
||||
**可能原因**:
|
||||
- `gateway_url` 配置错误或 BEpusdt 服务未运行
|
||||
- `auth_token` 与 BEpusdt 配置不一致
|
||||
- 网络连接问题(检查防火墙)
|
||||
|
||||
**解决方法**:
|
||||
- 检查 BEpusdt 服务状态:`curl http://your-bepusdt/health`
|
||||
- 验证 API Token 是否正确
|
||||
- 查看 Dujiao-Next 后端日志
|
||||
|
||||
### 2. 回调未收到或订单状态未更新
|
||||
|
||||
**可能原因**:
|
||||
- `notify_url` 配置错误(路径必须是 `/api/v1/payments/callback`)
|
||||
- BEpusdt 无法访问回调地址(网络/防火墙问题)
|
||||
- 签名验证失败
|
||||
|
||||
**解决方法**:
|
||||
- 确认回调地址可被外网访问:`curl https://your-api/api/v1/payments/callback`
|
||||
- 检查 BEpusdt 日志中的回调错误
|
||||
- 检查 Dujiao-Next 后端日志中的签名验证信息
|
||||
|
||||
### 3. 支付完成后跳转错误
|
||||
|
||||
**可能原因**:
|
||||
- `return_url` 路径配置错误(必须是 `/pay` 不是 `/payment` 或 `/order`)
|
||||
- 前端路由配置问题
|
||||
|
||||
**解决方法**:
|
||||
- 确认 `return_url` 配置为:`https://your-user-domain.com/pay`
|
||||
- 清除浏览器缓存后重试
|
||||
|
||||
### 4. 签名验证失败
|
||||
|
||||
**可能原因**:
|
||||
- `auth_token` 不一致(注意前后空格)
|
||||
- 回调参数被中间件修改
|
||||
|
||||
**解决方法**:
|
||||
- 确保 `auth_token` 完全一致
|
||||
- 检查是否有反向代理修改了请求参数
|
||||
|
||||
### 5. 金额不匹配
|
||||
|
||||
**可能原因**:
|
||||
- 汇率波动导致实际支付金额与订单金额不同
|
||||
- BEpusdt 配置的汇率源问题
|
||||
|
||||
**解决方法**:
|
||||
- BEpusdt 会返回 `actual_amount`(实际支付金额),Dujiao-Next 会记录此金额
|
||||
- 可在订单详情中查看实际支付金额
|
||||
|
||||
## 技术支持
|
||||
|
||||
- Dujiao-Next: [GitHub Issues](https://github.com/dujiao-next/dujiao-next/issues)
|
||||
- BEpusdt: [Telegram 群组](https://t.me/BEpusdtChat)
|
||||
|
||||
---
|
||||
|
||||
**贡献者**: 狼哥 ([@luoyanglang](https://github.com/luoyanglang) | Telegram: [@luoyanglang](https://t.me/luoyanglang))
|
||||
|
||||
> 本文档适用于 Dujiao-Next 最新版本和 BEpusdt 最新版本
|
||||
> 最后更新:2026-02-13
|
||||
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 125 KiB |
@@ -43,7 +43,7 @@
|
||||
| 参数名称 | 填写内容 | 说明 |
|
||||
|------------|-----------------------------------------------------------|---------------------------------------------------------------------------|
|
||||
| **商户ID** | 与 `BEpusdt` 中 `AUTH_TOKEN` 参数保持一致 | 用于身份验证 |
|
||||
| **支付标识** | 收款交易类型 | 可选值:`tron.trx`、`usdt.trc20`、`usdt.erc20` 等<br/>[完整列表参考](../trade-type.md) |
|
||||
| **支付标识** | 收款交易类型 | 可选值:`tron.trx`、`usdt.trc20`、`usdt.erc20` 等<br/>[完整列表参考](../../trade-type.md) |
|
||||
| **商户密钥** | `https://your-domain.com/api/v1/order/create-transaction` | ⚠️ 请将 `your-domain.com` 替换为实际域名 |
|
||||
| **支付处理路由** | `pay/epusdt` | 固定值,无需修改 |
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
|
||||
> 路径:后台 -> 插件管理 -> 应用商店 -> 支付插件 -> 易支付
|
||||
|
||||

|
||||

|
||||
|
||||
找到这个插件,并把他安装下来,随后启用。
|
||||
|
||||

|
||||

|
||||
|
||||
### 2.支付配置
|
||||
|
||||
点击添加配置,配置自己的`Bepusdt`信息,参考如下:
|
||||
|
||||

|
||||

|
||||
|
||||
### 3.增加支付通道
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
,需有对原版代码进行替换;请把这个文件[Pay.php](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/mcy-shop/Pay.php)
|
||||
下载下来,替换到你的网站路径`/app/Plugin/Epay/Config`下的同名文件。
|
||||
|
||||

|
||||

|
||||
|
||||
### 4.增加支付接口
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
> 支付通道:自行选择
|
||||
> 支付配置:选择第二步添加的配置
|
||||
>
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
其它参数根据自己的需求填写即可,填好之后即可开始测试是否对接成功!
|
||||
@@ -0,0 +1,23 @@
|
||||
# 第三方程序对接指南
|
||||
|
||||
## 兼容性说明
|
||||
|
||||
关于第三方程序的适配对接问题,建议您优先向您的程序开发者反馈,或在相关技术社区寻求支持,具体的适配进度和时效性无法保证。
|
||||
|
||||
### 兼容性特性
|
||||
|
||||
1. **Epusdt 兼容**:BEpusdt 与 Epusdt 插件保持高度兼容,理论上所有已适配 `Epusdt` 的程序均可无缝迁移至 `BEpusdt`
|
||||
。建议在正式环境部署前,先在测试环境中进行充分验证。
|
||||
|
||||
2. **彩虹易支付兼容**:原生支持`彩虹易支付`的 `submit.php` 提交接口标准,因此大多数已适配`彩虹易支付`的程序可直接集成使用。
|
||||
|
||||
## 对接教程
|
||||
|
||||
以下是常见程序的对接文档,请根据您的实际需求选择相应教程进行配置。如遇问题,请仔细核对操作步骤,或在相关技术社区寻求协助。
|
||||
|
||||
- [独角数卡](./dujiaoka/dujiaoka.md)
|
||||
- [彩虹易支付](https://github.com/v03413/Epay-BEpusdt)
|
||||
- [WHMCS](https://github.com/v03413/whmcs-gateway-epusdt)
|
||||
- [异次元发卡](acg-faka/README.md)
|
||||
- [萌次元商城](./mcy-faka/mcy-shop.md)
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
[Unit]
|
||||
Description=Bepusdt Service
|
||||
Description=BEpusdt Service
|
||||
Documentation=https://github.com/v03413/bepusdt
|
||||
After=network.target nss-lookup.target
|
||||
|
||||
[Service]
|
||||
Type = simple
|
||||
LimitAS=infinity
|
||||
LimitRSS=infinity
|
||||
LimitCORE=infinity
|
||||
LimitNOFILE=999999
|
||||
WorkingDirectory=/var/lib/bepusdt
|
||||
ExecStart=/usr/local/bin/bepusdt start
|
||||
Restart=on-failure
|
||||
|
||||
|
||||
@@ -1,37 +1,146 @@
|
||||
# Docker 部署
|
||||
# Docker 部署指南
|
||||
|
||||
## 准备工作
|
||||
## 环境准备
|
||||
|
||||
1. **安装 Docker:** 确保服务器已经安装 Docker,这里不阐述安装细节。
|
||||
2. **推荐服务器:** 推荐使用新加坡服务器(Debian12+),性能无硬性要求,主要确保网络通畅;
|
||||
推荐尽量知名厂商(例如:Aws Gcp DigitalOcean 等),一方面安全更有保障,其次一些私人VPS总是出现一些奇奇怪怪的问题!
|
||||
### 前置要求
|
||||
|
||||
## 部署命令
|
||||
1. **Docker 环境:** 确保服务器已安装 Docker(建议使用最新稳定版本)
|
||||
2. **服务器推荐配置:**
|
||||
- **操作系统:** Debian 12+ 或其他主流 Linux 发行版
|
||||
- **性能要求:** 无特殊硬性要求,建议至少 1GB 内存
|
||||
- **网络要求:** 确保服务器网络通畅,能够稳定访问区块链网络
|
||||
- **云服务商:** 推荐使用知名云服务提供商(如 AWS、GCP、DigitalOcean 等),以确保服务稳定性和安全性
|
||||
|
||||
## 快速部署
|
||||
|
||||
### 基础部署命令
|
||||
|
||||
```bash
|
||||
docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
|
||||
```
|
||||
|
||||
### 参数说明:
|
||||
### 参数说明
|
||||
|
||||
- `-p 8080:8080` 表示将宿主机的 8080 端口映射到容器的 8080 端口,使得应用可以通过宿主机的端口访问。
|
||||
- `--restart=unless-stopped` 确保你的容器在遇到问题时可以自动重启。
|
||||
- 版本说明:`v03413/bepusdt:latest` 为最新发行版镜像,`v03413/bepusdt:nightly`为每日构建的滚动开发版。
|
||||
- **端口映射 `-p 8080:8080`:** 将容器内部的 8080 端口映射到宿主机的 8080 端口,支持通过宿主机 IP 地址访问服务
|
||||
- **自动重启 `--restart=unless-stopped`:** 确保容器在异常退出或系统重启后自动恢复运行
|
||||
- **镜像版本:**
|
||||
- `v03413/bepusdt:latest` - 稳定发行版(推荐生产环境使用)
|
||||
- `v03413/bepusdt:nightly` - 每日构建开发版(包含最新特性,适合测试环境)
|
||||
|
||||
## 数据持久化
|
||||
|
||||
### SQLite 数据库(默认)
|
||||
|
||||
默认情况下,系统使用 SQLite 数据库存储所有数据,数据保存在容器内部路径 `/var/lib/bepusdt`。
|
||||
|
||||
**重要提示:** 为避免容器删除导致数据丢失,强烈建议将数据目录挂载到宿主机:
|
||||
|
||||
```bash
|
||||
docker run -d --restart=unless-stopped -p 8080:8080 -v [挂载路径]:/var/lib/bepusdt v03413/bepusdt:latest
|
||||
```
|
||||
|
||||
**配置示例:**
|
||||
|
||||
将 `[挂载路径]` 替换为宿主机实际路径,例如:
|
||||
|
||||
```bash
|
||||
docker run -d --restart=unless-stopped -p 8080:8080 -v /opt/bepusdt:/var/lib/bepusdt v03413/bepusdt:latest
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><strong>PostgreSQL 数据库(推荐)</strong></summary>
|
||||
|
||||
系统支持使用 PostgreSQL 作为数据存储方案,适用于生产环境。这是目前推荐的数据库方案。
|
||||
|
||||
**前置准备:**
|
||||
|
||||
- PostgreSQL 版本:18 或更高版本
|
||||
- 需提前完成 PostgreSQL 安装及安全配置
|
||||
- 已创建专用数据库(如 `bepusdt`)
|
||||
|
||||
**部署命令:**
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--restart unless-stopped \
|
||||
-p 8080:8080 \
|
||||
-e POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3 \
|
||||
v03413/bepusdt:latest
|
||||
```
|
||||
|
||||
**配置说明:**
|
||||
|
||||
- 将 `user` 替换为 PostgreSQL 用户名
|
||||
- 将 `password` 替换为 PostgreSQL 密码
|
||||
- 将 `localhost:5432` 替换为 PostgreSQL 服务器地址和端口
|
||||
- 将 `bepusdt` 替换为实际数据库名称
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>MySQL 数据库(已弃用)</strong></summary>
|
||||
|
||||
> **注意:** MySQL 支持将逐步弃用,建议使用 PostgreSQL 替代。
|
||||
|
||||
系统仍支持使用 MySQL 作为数据存储方案,但不再推荐用于新部署。
|
||||
|
||||
**部署命令:**
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--restart unless-stopped \
|
||||
-p 8080:8080 \
|
||||
-e MYSQL_DSN=user:password@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s&readTimeout=10s&writeTimeout=10s \
|
||||
v03413/bepusdt:latest
|
||||
```
|
||||
|
||||
**配置说明:**
|
||||
|
||||
- 将 `user` 替换为 MySQL 用户名
|
||||
- 将 `password` 替换为 MySQL 密码
|
||||
- 将 `127.0.0.1:3306` 替换为 MySQL 服务器地址和端口
|
||||
- 将 `bepusdt` 替换为实际数据库名称(如需要)
|
||||
|
||||
</details>
|
||||
|
||||
## 部署验证
|
||||
|
||||
确保命令执行无误后,控制台会返回一个容器 ID,执行命令 `docker logs -f [容器ID]` 如果一切正常则能看到启动成功信息;
|
||||
此时可以通过访问`http://[你的IP]:8080/[安全入口]`便可以看到安装完成,保存相关信息之后登录即可;如图:
|
||||
### 查看容器日志
|
||||
|
||||
执行部署命令后,系统将返回容器 ID。使用以下命令查看启动日志:
|
||||
|
||||
```bash
|
||||
docker logs -f [容器ID]
|
||||
```
|
||||
|
||||
如果启动成功,日志将显示相应的成功信息。
|
||||
|
||||
### 访问管理界面
|
||||
|
||||
通过浏览器访问以下地址进入初始化页面:
|
||||
|
||||
```
|
||||
http://[服务器IP]:8080/[安全入口]
|
||||
```
|
||||
|
||||
首次访问时,系统将显示安装向导。请按照提示完成初始化配置,并妥善保存管理员账号信息。
|
||||
|
||||

|
||||
|
||||
## 忘记密码
|
||||
## 运维管理
|
||||
|
||||
执行命令重置:
|
||||
### 重置管理员密码
|
||||
|
||||
如忘记管理员密码,可使用以下命令重置:
|
||||
|
||||
```bash
|
||||
docker exec -it [容器ID] bepusdt reset
|
||||
docker exec -it [容器ID] bepusdt reset
|
||||
```
|
||||
|
||||
[‼️强烈推荐配置 TronGrid Api Key 提高 Tron 扫块稳定性](../tron-grid/readme.md)
|
||||
### 重要提示
|
||||
|
||||
**强烈推荐配置 TronGrid API Key:** 配置后可显著提升 TRON 网络扫块的稳定性和可靠性。
|
||||
|
||||
详细配置步骤请参考:[TronGrid 配置指南](../tron-grid/readme.md)
|
||||
|
||||
---
|
||||
@@ -0,0 +1,58 @@
|
||||
# 后台登录信息重置
|
||||
|
||||
当忘记登录密码时,可通过 `reset` 命令重置后台管理入口及账号信息。
|
||||
|
||||
## 重置方法
|
||||
|
||||
### Docker 容器部署
|
||||
|
||||
1. 查询容器 ID:
|
||||
|
||||
```bash
|
||||
docker ps -a
|
||||
```
|
||||
|
||||
2. 执行重置命令:
|
||||
|
||||
```bash
|
||||
docker exec -it <容器ID> bepusdt reset
|
||||
```
|
||||
|
||||
3. 命令执行成功后,将输出新的登录凭证:
|
||||
|
||||
```
|
||||
重置成功,对应信息如下:
|
||||
管理员账号: 4bd57acf
|
||||
管理员密码: 40f7db37
|
||||
后台管理入口: /d57acf0610
|
||||
请妥善保存以上信息!
|
||||
```
|
||||
|
||||
### Linux 二进制部署
|
||||
|
||||
1. 定位二进制文件路径:
|
||||
|
||||
```bash
|
||||
which bepusdt
|
||||
```
|
||||
|
||||
2. 执行重置命令(假设二进制文件位于 `/usr/local/bin/bepusdt`):
|
||||
|
||||
```bash
|
||||
/usr/local/bin/bepusdt reset
|
||||
```
|
||||
|
||||
3. 命令执行成功后,将输出新的登录凭证:
|
||||
|
||||
```
|
||||
重置成功,对应信息如下:
|
||||
管理员账号: 4bd57acf
|
||||
管理员密码: 40f7db37
|
||||
后台管理入口: /d57acf0610
|
||||
请妥善保存以上信息!
|
||||
```
|
||||
|
||||
## 安全提示
|
||||
|
||||
⚠️ 请在重置后立即修改默认密码,并妥善保管新的登录信息。
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# 服务器选项
|
||||
|
||||
## 配置要求
|
||||
|
||||
**内存**:单网络扫块内存占用通常不超过 100MB,开启多网络扫块时内存会线性增加。推荐:1GB 内存。
|
||||
|
||||
**磁盘**:空间需求较小,但强烈建议使用 SSD 或 NVMe 高速磁盘。使用 HDD 机械硬盘可能会触发 Slow SQL 告警。
|
||||
|
||||
**网络**:
|
||||
|
||||
- 必须保证网络畅通稳定,避免使用网络受限地区的服务器
|
||||
- 扫块会持续下载区块数据,日流量消耗可达数 GB 以上
|
||||
|
||||
**时间同步**:务必配置 NTP 服务自动同步时间,系统多处逻辑依赖时间准确性。
|
||||
|
||||
**地区**:优先选择新加坡或美国机房。
|
||||
|
||||
## 推荐配置
|
||||
|
||||
最低配置:1 核 CPU / 1GB 内存 / 10GB 磁盘
|
||||
|
||||
推荐服务商:AWS、Google Cloud、Azure、DigitalOcean 等大厂商,可提供更好的稳定性和网络质量。
|
||||
|
||||
## 开发者推荐
|
||||
|
||||
[](https://www.digitalocean.com/?refcode=7204f1398099&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
|
||||
|
||||
本项目基于 [DigitalOcean](https://m.do.co/c/7204f1398099) 环境开发测试,兼容性最佳;月费用低于 $10,适合个人和小型项目。
|
||||
@@ -1,68 +1,71 @@
|
||||
# Linux 手动安装
|
||||
# Linux 手动安装指南
|
||||
|
||||
> ⚠️ **前置说明**:本教程假定您已掌握 Linux 基本操作,包括命令行使用、文件管理等常识。
|
||||
> ⚠️ **前置条件**:本指南假设您具备 Linux 基本操作能力,包括命令行使用、文件系统管理等基础知识。
|
||||
|
||||
## 系统要求
|
||||
## 系统需求
|
||||
|
||||
| 项目 | 要求 |
|
||||
|-----------|------------------|
|
||||
| **操作系统** | Debian 12 或更高版本 |
|
||||
| **处理器架构** | amd64(其他架构请自行测试) |
|
||||
| 项目 | 要求 |
|
||||
|------------|------------------|
|
||||
| **操作系统** | Debian 11 或更高版本 |
|
||||
| **CPU 架构** | amd64(其他架构请自行验证) |
|
||||
|
||||
## 安装步骤
|
||||
|
||||
执行以下命令依次完成安装:
|
||||
### 1. 获取安装包
|
||||
|
||||
### 1. 下载安装包
|
||||
从 [GitHub Releases](https://github.com/v03413/bepusdt/releases/latest/) 页面下载与系统架构对应的安装包。
|
||||
|
||||
```bash
|
||||
# 下载对应架构版本
|
||||
wget -O ./bepusdt.zip https://github.com/v03413/bepusdt/releases/latest/download/bepusdt-linux-amd64.zip
|
||||
wget -O ./linux-amd64-BEpusdt.tar.gz https://github.com/v03413/BEpusdt/releases/latest/download/linux-amd64-BEpusdt.tar.gz
|
||||
```
|
||||
|
||||
### 2. 解压文件
|
||||
### 2. 解压安装包
|
||||
|
||||
```bash
|
||||
unzip ./bepusdt.zip
|
||||
tar -zxvf ./linux-amd64-BEpusdt.tar.gz
|
||||
```
|
||||
|
||||
解压后的目录结构如下:
|
||||
解压后的目录结构:
|
||||
|
||||
```
|
||||
./bepusdt
|
||||
├── bepusdt # 可执行文件
|
||||
├── bepusdt # 可执行程序文件
|
||||
└── bepusdt.service # systemd 服务配置文件
|
||||
```
|
||||
|
||||
### 3. 配置系统自启
|
||||
### 3. 系统集成与自启配置
|
||||
|
||||
```bash
|
||||
# 将 service 文件移动到 systemd 目录
|
||||
mv ./bepusdt/bepusdt.service /etc/systemd/system
|
||||
# 复制可执行文件至系统路径
|
||||
mv ./bepusdt/bepusdt /usr/local/bin/
|
||||
|
||||
# 启用服务自启
|
||||
# 设置可执行权限
|
||||
chmod +x /usr/local/bin/bepusdt
|
||||
|
||||
# 复制服务配置文件
|
||||
mv ./bepusdt/bepusdt.service /etc/systemd/system/
|
||||
|
||||
# 启用开机自启
|
||||
systemctl enable bepusdt.service
|
||||
```
|
||||
|
||||
### 4. 启动服务
|
||||
|
||||
```bash
|
||||
# 启动 BEpusdt 服务
|
||||
systemctl start bepusdt.service
|
||||
```
|
||||
|
||||
### 5. 验证启动状态
|
||||
### 5. 验证服务状态
|
||||
|
||||
```bash
|
||||
# 查看服务状态
|
||||
systemctl status bepusdt.service
|
||||
```
|
||||
|
||||
✅ **成功标志**:看到 `Active: active (running)` 表示服务已成功启动
|
||||
✅ **成功指标**:状态显示 `Active: active (running)` 表示服务已正常启动
|
||||
|
||||
---
|
||||
|
||||
## 常用命令
|
||||
## 常用操作命令
|
||||
|
||||
| 操作 | 命令 |
|
||||
|----------|-------------------------------------|
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
# 交易匹配模式
|
||||
|
||||
订单过滤金额匹配时的不同对比算法,系统支持三种匹配模式,可根据实际业务场景选择合适的匹配策略。
|
||||
|
||||
---
|
||||
|
||||
## 传统模式(精确匹配)
|
||||
|
||||
最传统、最严格的金额匹配模式,实际交易金额和订单金额必须完全一致,才会被认为是匹配成功。
|
||||
|
||||
**适用场景:**
|
||||
|
||||
- 对金额准确性要求极高的场景
|
||||
|
||||
**举例:**
|
||||
|
||||
| 订单金额 | 实际交易金额 | 匹配结果 |
|
||||
|--------|--------|--------|
|
||||
| 100.00 | 100.00 | ✅ 匹配成功 |
|
||||
| 100.00 | 100.01 | ❌ 匹配失败 |
|
||||
| 99.99 | 99.99 | ✅ 匹配成功 |
|
||||
| 99.99 | 99.98 | ❌ 匹配失败 |
|
||||
|
||||
---
|
||||
|
||||
## 前缀匹配
|
||||
|
||||
如同名字一般,前缀匹配模式会将两个交易金额转换成字符串,然后从左到右逐位进行对比。
|
||||
如果订单金额字符串是实际交易金额字符串的前缀,则认为是匹配成功。
|
||||
|
||||
**适用场景:**
|
||||
|
||||
- 某些支付渠道可能会在金额末尾添加额外的小数位
|
||||
- 用户可能因为汇率波动或手续费问题支付了稍多的金额
|
||||
- 需要更灵活的金额匹配策略
|
||||
|
||||
**举例:**
|
||||
|
||||
| 订单金额 | 实际交易金额 | 匹配结果 | 说明 |
|
||||
|--------|------------|--------|-----------------------------|
|
||||
| 100 | 100.5 | ✅ 匹配成功 | "100" 是 "100.5" 的前缀 |
|
||||
| 100.5 | 100.56 | ✅ 匹配成功 | "100.5" 是 "100.56" 的前缀 |
|
||||
| 99.9 | 99.99 | ✅ 匹配成功 | "99.9" 是 "99.99" 的前缀 |
|
||||
| 100 | 99.99 | ❌ 匹配失败 | "100" 不是 "99.99" 的前缀 |
|
||||
| 100.5 | 100.4 | ❌ 匹配失败 | "100.5" 不是 "100.4" 的前缀 |
|
||||
| 123.45 | 123.456789 | ✅ 匹配成功 | "123.45" 是 "123.456789" 的前缀 |
|
||||
|
||||
---
|
||||
|
||||
## 修约匹配(四舍五入)
|
||||
|
||||
采用数值修约中的四舍五入规则,对实际交易金额进行修约处理后,再与订单金额进行对比。如果修约后的金额与订单金额一致,则认为是匹配成功。
|
||||
|
||||
**适用场景:**
|
||||
|
||||
- 加密货币交易,链上实际到账金额可能因为网络费用而略有差异
|
||||
- 汇率换算导致的小数位精度问题
|
||||
- 需要容忍一定误差范围的支付场景
|
||||
|
||||
**修约规则:**
|
||||
|
||||
- 根据订单金额的小数位数确定修约精度
|
||||
- 对实际交易金额按该精度进行四舍五入
|
||||
- 比较修约后的金额与订单金额是否相等
|
||||
|
||||
**举例:**
|
||||
|
||||
| 订单金额 | 实际交易金额 | 修约后金额 | 匹配结果 | 说明 |
|
||||
|---------|----------|---------|--------|-------------------------|
|
||||
| 100.00 | 100.004 | 100.00 | ✅ 匹配成功 | 保留2位小数,0.004四舍五入为0.00 |
|
||||
| 100.00 | 100.005 | 100.01 | ❌ 匹配失败 | 保留2位小数,0.005四舍五入为0.01 |
|
||||
| 99.50 | 99.498 | 99.50 | ✅ 匹配成功 | 保留2位小数,0.498四舍五入为0.50 |
|
||||
| 99.50 | 99.494 | 99.49 | ❌ 匹配失败 | 保留2位小数,0.494四舍五入为0.49 |
|
||||
| 88.5 | 88.51 | 88.5 | ✅ 匹配成功 | 保留1位小数,0.51四舍五入为0.5 |
|
||||
| 88.5 | 88.49 | 88.5 | ✅ 匹配成功 | 保留1位小数,0.49四舍五入为0.5 |
|
||||
| 88.5 | 88.45 | 88.5 | ✅ 匹配成功 | 保留1位小数,0.45四舍五入为0.5 |
|
||||
| 123.456 | 123.4564 | 123.456 | ✅ 匹配成功 | 保留3位小数,0.0004四舍五入为0.000 |
|
||||
|
||||
---
|
||||
|
||||
## 选择建议
|
||||
|
||||
- **传统模式**:适合金额固定、对准确性要求高的场景
|
||||
- **前缀匹配**:适合仅允许用户多付、可能添加额外精度的场景
|
||||
- **修约匹配**:适合允许用户多付或者少付,容忍度更高的场景
|
||||
|
||||
根据实际业务需求选择合适的匹配模式,可以在保证安全性的同时提升用户体验。
|
||||
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 59 KiB |
@@ -0,0 +1,96 @@
|
||||
# 收银台自定义修改指南
|
||||
|
||||
## 概述
|
||||
|
||||
本文档介绍如何自定义修改 BEpusdt 收银台的网页模板。本指南假设您已具备基本的 Linux/Docker 和前端开发知识。
|
||||
|
||||
## 获取默认资源文件
|
||||
|
||||
收银台的网页资源文件位于官方仓库:
|
||||
|
||||
https://github.com/v03413/BEpusdt/tree/main/static/payment
|
||||
|
||||
## 目录结构
|
||||
|
||||
```bash
|
||||
./payment
|
||||
├── assets
|
||||
│ ├── css # 样式文件
|
||||
│ ├── i18n # 国际化配置
|
||||
│ ├── img # 图片资源
|
||||
│ ├── js # JavaScript 文件
|
||||
│ └── locales # 多语言文件
|
||||
└── views
|
||||
├── bsc.bnb.html
|
||||
├── ethereum.eth.html
|
||||
├── index.html
|
||||
├── installed.html
|
||||
├── tron.trx.html
|
||||
├── usdc.aptos.html
|
||||
├── usdc.arbitrum.html
|
||||
├── usdc.base.html
|
||||
└── ...
|
||||
```
|
||||
|
||||
**目录说明:**
|
||||
|
||||
- **assets** - 静态资源文件(CSS、JavaScript、图片、国际化文件)
|
||||
- **views** - 各币种对应的收银台 HTML 模板文件,每个 HTML 文件对应一个币种的收银台页面
|
||||
|
||||
## 修改步骤
|
||||
|
||||
### 1. 修改网页模板
|
||||
|
||||
在 `views` 目录下编辑相应的 HTML 文件进行自定义修改。
|
||||
|
||||
### 2. 上传资源文件到服务器
|
||||
|
||||
#### Linux 直接部署
|
||||
|
||||
将修改后的整个 `payment` 目录上传到服务器指定路径:
|
||||
|
||||
```bash
|
||||
# 示例:上传到 /root/test/payment/
|
||||
scp -r ./payment user@server:/root/test/
|
||||
```
|
||||
|
||||
#### Docker 部署
|
||||
|
||||
**选项 A:使用 Volume 挂载(推荐)**
|
||||
|
||||
在启动容器时挂载本地目录,避免每次都复制文件:
|
||||
|
||||
```bash
|
||||
docker run -v /root/test/payment:/app/static/payment <image_id>
|
||||
```
|
||||
|
||||
**选项 B:复制到运行中的容器**
|
||||
|
||||
```bash
|
||||
docker cp payment/ <container_id>:/app/static/
|
||||
```
|
||||
|
||||
### 3. 配置静态资源路径
|
||||
|
||||

|
||||
|
||||
1. 登录 BEpusdt 后台管理系统
|
||||
2. 进入 **系统管理** → **基本设置** → **API 设置**
|
||||
3. 在**静态资源路径**字段中填入完整目录路径
|
||||
4. 点击保存
|
||||
|
||||
### 4. 重启服务并验证
|
||||
|
||||
重启 BEpusdt 服务:
|
||||
|
||||
```bash
|
||||
# Linux 直接部署
|
||||
systemctl restart bepusdt
|
||||
|
||||
# Docker 部署
|
||||
docker restart <container_id>
|
||||
```
|
||||
|
||||
查看服务日志,确认出现资源注册成功提示(如下图所示),则表示配置正确。之后访问当请求到对应的交易类型收银台时便能看到修改效果。
|
||||
|
||||

|
||||
@@ -1,58 +0,0 @@
|
||||
# 修改默认模板
|
||||
|
||||
BEpusdt 所有的静态文件都存放在 `static` 目录,而模板文件则存放在 `views` 目录下。
|
||||
|
||||
当前目录结构:
|
||||
|
||||
```
|
||||
➜ bepusdt git:(main) ✗ tree ./static
|
||||
./static
|
||||
├── css
|
||||
│ ├── layer.css
|
||||
│ ├── main.min.css
|
||||
│ └── usdt.min.css
|
||||
├── embep.go
|
||||
├── font
|
||||
├── img
|
||||
│ ├── cloud.png
|
||||
│ ├── Detector.js
|
||||
│ ├── favicon.ico
|
||||
│ ├── icon-1.png
|
||||
│ ├── icon-2.png
|
||||
│ ├── icon-3.png
|
||||
│ ├── icon-4.png
|
||||
│ ├── key.png
|
||||
│ ├── lock_icon_copy.png
|
||||
│ ├── logo.png
|
||||
│ ├── puff.svg
|
||||
│ ├── RequestAnimationFrame.js
|
||||
│ ├── tether.svg
|
||||
│ ├── ThreeExtras.js
|
||||
│ ├── ThreeWebGL.js
|
||||
│ ├── tick.png
|
||||
│ ├── tron_trx.svg
|
||||
│ ├── trx.png
|
||||
│ └── user_icon_copy.png
|
||||
├── js
|
||||
│ ├── clipboard.min.js
|
||||
│ ├── jquery.min.js
|
||||
│ ├── jquery.qrcode_1.0.min.js
|
||||
│ ├── layer.min.js
|
||||
│ └── usdt.min.js
|
||||
└── views
|
||||
├── index.html
|
||||
├── tron.trx.html
|
||||
├── usdt.aptos.html
|
||||
├── usdt.bep20.html
|
||||
├── usdt.erc20.html
|
||||
├── usdt.polygon.html
|
||||
├── usdt.solana.html
|
||||
├── usdt.trc20.html
|
||||
└── usdt.xlayer.html
|
||||
|
||||
```
|
||||
|
||||
能够看到,`static/views` 对应了不同支付交易类型的页面模板,模板内容可以自定义,但是模板文件名不能修改,
|
||||
必须和交易类型保持一致,否则系统无法识别。
|
||||
|
||||
当你修改之后,通过配置文件里面的`static_path`参数指定静态文件目录即可,最好是绝对路径;至于其它 css js img 等文件,自行调整。
|
||||
@@ -9,6 +9,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.10.1
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/go-telegram/bot v1.17.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/matoous/go-nanoid/v2 v2.1.0
|
||||
github.com/panjf2000/ants/v2 v2.11.3
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
@@ -21,10 +22,12 @@ require (
|
||||
github.com/v03413/tronprotocol v0.0.0-20240824084238-bbd62f5e0158
|
||||
golang.org/x/crypto v0.39.0
|
||||
google.golang.org/grpc v1.73.0
|
||||
gorm.io/gorm v1.30.0
|
||||
gorm.io/driver/mysql v1.6.0
|
||||
gorm.io/gorm v1.31.1
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.13.3 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
@@ -35,11 +38,16 @@ require (
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.26.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.9.3 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/context v1.1.2 // indirect
|
||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||
github.com/gorilla/sessions v1.4.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
@@ -48,6 +56,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
@@ -60,14 +69,15 @@ require (
|
||||
golang.org/x/arch v0.18.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/sync v0.15.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
golang.org/x/text v0.33.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/postgres v1.6.0 // indirect
|
||||
modernc.org/libc v1.65.10 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
||||
@@ -68,6 +70,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
|
||||
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/go-telegram/bot v1.17.0 h1:Hs0kGxSj97QFqOQP0zxduY/4tSx8QDzvNI9uVRS+zmY=
|
||||
github.com/go-telegram/bot v1.17.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
@@ -102,12 +106,22 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
|
||||
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
@@ -116,8 +130,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
@@ -131,6 +148,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
@@ -216,8 +235,8 @@ golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 h1:bsqhLWFR6G6xiQcb+JoGqdKdRU6WzPWmK8E0jxTjzo4=
|
||||
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
|
||||
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
|
||||
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -226,8 +245,8 @@ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81R
|
||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -244,11 +263,11 @@ golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
|
||||
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
|
||||
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
|
||||
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM=
|
||||
@@ -268,6 +287,7 @@ google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -276,8 +296,12 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
|
||||
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
||||
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
|
||||
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
|
||||
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
|
||||
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
|
||||
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
|
||||
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
|
||||
modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s=
|
||||
modernc.org/cc/v4 v4.26.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=
|
||||
|
||||
@@ -4,11 +4,17 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/v03413/bepusdt/app/cmd"
|
||||
"github.com/v03413/bepusdt/app/conf"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 不推荐引导小白参与修改各种配置文件
|
||||
_ = godotenv.Load()
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := &cli.Command{
|
||||
Name: "BEpusdt",
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
.selector-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: white !important;
|
||||
padding: 32px !important;
|
||||
gap: 32px;
|
||||
margin-bottom: 32px !important;
|
||||
border-radius: 7px !important;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
||||
}
|
||||
|
||||
.selector-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.selector-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.coin-select {
|
||||
outline: 1px solid #e8e8e8;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 18px 22px 18px 16px;
|
||||
}
|
||||
|
||||
.coin-select span {
|
||||
margin: 0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.pay-button {
|
||||
cursor: pointer;
|
||||
font-family: Golos, sans-serif;
|
||||
padding: 18px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
background: #667eea;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.pay-button:hover {
|
||||
background-color: #5a67d8;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.pay-button p {
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
height: 20px;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
letter-spacing: -.12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
column-gap: 10px;
|
||||
}
|
||||
|
||||
/* Dropdown Styles */
|
||||
.selector-container {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.coin-select {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
background: var(--bg-card-light, #f8f9fa);
|
||||
/* Fallback or use variable if exists */
|
||||
border: 1px solid var(--border-color, #e9ecef);
|
||||
border-radius: 12px;
|
||||
padding: 12px 16px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.coin-select:hover {
|
||||
border-color: var(--primary-color, #2d60e0);
|
||||
background: #fff;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.coin-select.active {
|
||||
border-color: var(--primary-color, #2d60e0);
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 3px rgba(45, 96, 224, 0.1);
|
||||
}
|
||||
|
||||
.coin-select span {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
color: #4a5568;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.coin-select svg {
|
||||
color: var(--text-secondary, #8590a6);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.coin-select.active svg {
|
||||
transform: rotate(180deg);
|
||||
color: var(--primary-color, #2d60e0);
|
||||
}
|
||||
|
||||
/* Options Dropdown */
|
||||
.options-list {
|
||||
position: absolute;
|
||||
top: calc(100% + 8px);
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
border: 1px solid var(--border-color, #e9ecef);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
||||
z-index: 100;
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transform: translateY(-10px);
|
||||
transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.coin-select.active .options-list {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.option-item {
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.option-item:hover {
|
||||
background: var(--bg-hover, #f5f7fa);
|
||||
}
|
||||
|
||||
.option-item.selected {
|
||||
background: rgba(45, 96, 224, 0.08);
|
||||
color: var(--primary-color, #2d60e0);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.option-item .option-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.option-item .option-badge {
|
||||
font-size: 12px;
|
||||
padding: 2px 6px;
|
||||
background: #edf2f7;
|
||||
border-radius: 4px;
|
||||
color: #718096;
|
||||
}
|
||||
|
||||
/* Scrollbar styling */
|
||||
.options-list::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.options-list::-webkit-scrollbar-thumb {
|
||||
background-color: #cbd5e0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.options-list::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.pay-button:disabled {
|
||||
background: #bdbdbd; /* 灰色背景 */
|
||||
color: #f5f5f5;
|
||||
cursor: not-allowed;
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
transform: none;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 392 B After Width: | Height: | Size: 392 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |