This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package pay
import (
"errors"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/TeaOSLab/EdgeUser/internal/ttlcache"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
stringutil "github.com/iwind/TeaGo/utils/string"
"github.com/skip2/go-qrcode"
"time"
)
var qrcodeKeySalt = rands.HexString(32)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
Code string
From string
ReturnURL string
}) {
this.Data["fromURL"] = params.From
this.Data["returnURL"] = params.ReturnURL
orderResp, err := this.RPC().UserOrderRPC().FindEnabledUserOrder(this.UserContext(), &pb.FindEnabledUserOrderRequest{Code: params.Code})
if err != nil {
this.ErrorPage(err)
return
}
var order = orderResp.UserOrder
if order == nil {
this.ErrorPage(errors.New("can not find order with code '" + params.Code + "'"))
return
}
var methodMap = maps.Map{
"name": "",
}
var qrcodeKey = ""
var qrcodeTitle = ""
if order.OrderMethod != nil {
methodMap = maps.Map{
"name": order.OrderMethod.Name,
}
qrcodeTitle = order.OrderMethod.QrcodeTitle
if len(qrcodeTitle) == 0 && len(order.OrderMethod.ParentCode) > 0 {
var parentDef = userconfigs.FindPresetPayMethodWithCode(order.OrderMethod.ParentCode)
if parentDef != nil {
qrcodeTitle = parentDef.QRCodeTitle
}
}
if order.OrderMethod.ClientType == userconfigs.PayClientTypeMobile {
data, err := qrcode.Encode(order.PayURL, qrcode.Medium, 256)
if err != nil {
this.ErrorPage(errors.New("二维码生成失败:" + err.Error()))
return
}
qrcodeKey = stringutil.Md5(qrcodeKeySalt + ":order:" + order.Code)
ttlcache.DefaultCache.Write(qrcodeKey, data, time.Now().Unix()+600 /** 只保留10分钟防止内存占用过高 **/)
}
}
this.Data["order"] = maps.Map{
"code": order.Code,
"amount": order.Amount,
"canPay": order.CanPay,
"payURL": order.PayURL,
"typeName": userconfigs.FindOrderTypeName(order.Type),
"method": methodMap,
"isExpired": order.IsExpired,
"status": order.Status,
"statusName": userconfigs.FindOrderStatusName(order.Status),
"urlQRCodeKey": qrcodeKey,
"qrcodeTitle": qrcodeTitle,
}
this.Show()
}

View File

@@ -0,0 +1,18 @@
package pay
import (
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth("")).
Data("teaMenu", "finance").
Data("teaSubMenu", "orders").
Prefix("/finance/pay").
Get("", new(IndexAction)).
EndAll()
})
}