Files
admin a950fd2ead
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 47s
rebrand: BEpusdt → VUPAY
展示层与标识符全量改名:
- module github.com/v03413/bepusdt → git.viaeon.com/admin/vupay(含全部 import)
- 二进制/镜像/容器/DB 名 bepusdt → vupay(Dockerfile、workflow IMAGE、compose、docs)
- 显示名 BEpusdt → VUPAY(前端 title、后端 banner、version 命令、通知文案)
- 默认路径 /var/lib/bepusdt → /var/lib/vupay,/var/log/bepusdt → /var/log/vupay
- Telegram 通知的频道按钮原来指向上游 t.me 群,改成站点链接(否则改名后是死链)

刻意保留(运行语义,改了会坏):
- api_type 取值 "epusdt" / "epusdt_order"(库里存量数据按此匹配)
- 表前缀 bep_(bep_order / bep_conf / …,改需 RENAME TABLE 迁移)
- 签名函数 EpusdtSign 与 handler 包名 epusdt(对外协议语义,非品牌)
- 所有加密/会话派生的字面量原样不动

验证:gofmt 通过、go build ./... 通过、全仓 grep -i bepusdt 归零
2026-11-25 09:06:06 +08:00

246 lines
6.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package notifier
import (
"context"
"fmt"
"strings"
"time"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/tronprotocol/core"
)
type Telegram struct {
api *bot.Bot
token string
chatID int64
topicID int
}
func (t *Telegram) Initialize(params string) error {
info := gjson.Parse(params)
t.token = info.Get("bot_token").String()
t.chatID = info.Get("chat_id").Int()
t.topicID = cast.ToInt(info.Get("topic_id").Int())
b, err := bot.New(t.token)
if err != nil {
return err
}
t.api = b
return nil
}
func (t *Telegram) Success(o model.Order) {
if o.Status != model.OrderStatusSuccess {
return
}
tradeType := string(o.TradeType)
tokenType, err := model.GetCrypto(o.TradeType)
if err != nil {
t.sendMessage(&bot.SendMessageParams{Text: "❌交易类型不支持:" + tradeType})
return
}
token := string(tokenType)
text := `
\#收款成功 \#订单交易 \#` + token + `
\-\-\-
` + "```" + `
🚦商户订单:%v
💰请求金额:%v ` + string(o.Fiat) + `(%v)
💲支付数额:%v ` + tradeType + `
💎交易哈希:%s
✅收款地址:%s
⏱️创建时间:%s
️🎯️支付时间:%s
` + "```" + `
`
text = fmt.Sprintf(text,
o.OrderId,
o.Money,
o.Rate,
o.Amount,
utils.MaskHash(o.RefHash),
utils.MaskAddress(o.Address),
o.CreatedAt.Format(time.DateTime),
o.UpdatedAt.Format(time.DateTime),
)
t.sendMessage(&bot.SendMessageParams{
Text: text,
ParseMode: models.ParseModeMarkdown,
ReplyMarkup: &models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
models.InlineKeyboardButton{Text: "📝查看交易明细", URL: o.GetTxUrl()},
},
},
},
})
}
func (t *Telegram) NotifyFail(o model.Order, reason string) {
tradeType := string(o.TradeType)
tokenT, err := model.GetCrypto(o.TradeType)
if err != nil {
t.sendMessage(&bot.SendMessageParams{Text: "❌交易类型不支持:" + tradeType})
return
}
token := string(tokenT)
text := fmt.Sprintf(`
\#回调失败 \#订单交易 \#`+token+`
\-\-\-
`+"```"+`
🚦商户订单:%v
💲支付数额:%v
💰请求金额:%v `+string(o.Fiat)+`(%v)
💍交易类别:%s
⚖️️确认时间:%s
⏰下次回调:%s
🗒️失败原因:%s
`+"```"+`
`,
utils.Ec(o.OrderId),
o.Amount,
o.Money, o.Rate,
strings.ToUpper(tradeType),
o.ConfirmedAt.Format(time.DateTime),
utils.CalcNextNotifyTime(*o.ConfirmedAt, o.NotifyNum+1).Format(time.DateTime),
reason,
)
t.sendMessage(&bot.SendMessageParams{
Text: text,
ParseMode: models.ParseModeMarkdown,
ReplyMarkup: &models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
models.InlineKeyboardButton{Text: "📝查看收款详情", CallbackData: o.GetTxUrl()},
},
},
},
})
}
func (t *Telegram) NonOrderTransfer(trans model.TronTransfer, wa model.Wallet) {
title := nonOrderTransferTitle(trans, wa)
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(),
trans.Timestamp.Format(time.DateTime),
utils.MaskAddress(trans.RecvAddress),
utils.MaskAddress(trans.FromAddress),
)
t.sendMessage(&bot.SendMessageParams{
Text: text,
ParseMode: models.ParseModeMarkdown,
ReplyMarkup: models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
models.InlineKeyboardButton{Text: "📝查看交易明细", URL: model.GetTxUrl(trans.TradeType, trans.TxHash)},
},
},
},
})
}
func nonOrderTransferTitle(trans model.TronTransfer, wa model.Wallet) string {
if trans.RecvAddress == wa.MatchAddr {
return "收入"
}
return "支出"
}
func (t *Telegram) TronResourceChange(res model.TronResource) {
title := "代理"
if res.Type == core.Transaction_Contract_UnDelegateResourceContract {
title = "回收"
}
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),
utils.MaskAddress(res.FromAddress),
)
t.sendMessage(&bot.SendMessageParams{
Text: text,
ParseMode: models.ParseModeMarkdown,
ReplyMarkup: models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
models.InlineKeyboardButton{Text: "📝查看交易明细", URL: "https://tronscan.org/#/transaction/" + res.ID},
},
},
},
})
}
func (t *Telegram) Welcome() {
text := `
👋 欢迎使用 VUPAY,` + conf.Desc + `,如果您看到此消息,说明系统已启动成功!
📌当前版本:` + app.Version + `
🎉开源地址:` + conf.Github + `
---
`
t.sendMessage(&bot.SendMessageParams{
Text: text,
ReplyMarkup: models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "🌐 访问站点", URL: "https://u.viaeon.com"},
},
},
},
})
}
func (t *Telegram) Test() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
_, err := t.api.SendMessage(ctx, &bot.SendMessageParams{
ChatID: t.chatID,
MessageThreadID: t.topicID,
Text: "✅ 这是一条测试消息,Telegram 通知配置成功!\n当前系统时间:" + time.Now().Format("2006-01-02 15:04:05"),
})
return err
}
func (t *Telegram) sendMessage(p *bot.SendMessageParams) {
p.ChatID = t.chatID
p.MessageThreadID = t.topicID
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())
}
}