new
This commit is contained in:
parent
8f903b457f
commit
c76451788c
@ -118,6 +118,9 @@ service api-api {
|
||||
|
||||
@handler YYSY4B37
|
||||
post /YYSY4B37 (request) returns (string)
|
||||
|
||||
@handler YYSY4B21
|
||||
post /YYSY4B21 (request) returns (string)
|
||||
}
|
||||
|
||||
@server (
|
||||
|
@ -22,6 +22,12 @@ func EncryptStructFields(inputStruct interface{}, key string) (map[string]interf
|
||||
field := v.Type().Field(i)
|
||||
fieldValue := v.Field(i)
|
||||
|
||||
// 检查字段的 encrypt 标签是否为 "false"
|
||||
encryptTag := field.Tag.Get("encrypt")
|
||||
if encryptTag == "false" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果字段为空值,跳过
|
||||
if fieldValue.IsZero() {
|
||||
continue
|
||||
|
31
apps/api/internal/handler/YYSY/yysy4b21handler.go
Normal file
31
apps/api/internal/handler/YYSY/yysy4b21handler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package YYSY
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"tianyuan-api/pkg/response"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tianyuan-api/apps/api/internal/logic/YYSY"
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
"tianyuan-api/apps/api/internal/types"
|
||||
|
||||
xhttp "github.com/zeromicro/x/http"
|
||||
)
|
||||
|
||||
func YYSY4B21Handler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := YYSY.NewYYSY4B21Logic(r.Context(), svcCtx)
|
||||
resp, err := l.YYSY4B21(&req)
|
||||
if err != nil {
|
||||
response.Fail(r.Context(), w, err)
|
||||
} else {
|
||||
response.Success(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@ -187,6 +187,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/YYSY09CD",
|
||||
Handler: YYSY.YYSY09CDHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/YYSY4B21",
|
||||
Handler: YYSY.YYSY4B21Handler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/YYSY4B37",
|
||||
|
@ -88,7 +88,7 @@ func (l *FLXG970FLogic) FLXG970F(req *types.Request) (resp string, err *errs.App
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG970FFieldMapping, "")
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG970FFieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00028", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
|
@ -88,7 +88,7 @@ func (l *QYGL2ACDLogic) QYGL2ACD(req *types.Request) (resp string, err *errs.App
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL2ACDFieldMapping, "")
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL2ACDFieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00022", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
|
@ -88,7 +88,7 @@ func (l *QYGL45BDLogic) QYGL45BD(req *types.Request) (resp string, err *errs.App
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL45BDFieldMapping, "")
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL45BDFieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00021", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
|
@ -88,7 +88,7 @@ func (l *QYGLB4C0Logic) QYGLB4C0(req *types.Request) (resp string, err *errs.App
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGLB4C0FieldMapping, "")
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGLB4C0FieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G05HZ01", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
|
103
apps/api/internal/logic/YYSY/yysy4b21logic.go
Normal file
103
apps/api/internal/logic/YYSY/yysy4b21logic.go
Normal file
@ -0,0 +1,103 @@
|
||||
package YYSY
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"tianyuan-api/apps/api/internal/common"
|
||||
"tianyuan-api/apps/api/internal/validator"
|
||||
"tianyuan-api/apps/api/internal/westmodel"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
"tianyuan-api/pkg/errs"
|
||||
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
"tianyuan-api/apps/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type YYSY4B21Logic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewYYSY4B21Logic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSY4B21Logic {
|
||||
return &YYSY4B21Logic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *YYSY4B21Logic) YYSY4B21(req *types.Request) (resp string, err *errs.AppError) {
|
||||
var status string
|
||||
var charges bool
|
||||
var remark = ""
|
||||
secretKey, ok := l.ctx.Value("secretKey").(string)
|
||||
if !ok {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
transactionID, ok := l.ctx.Value("transactionID").(string)
|
||||
if !ok {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
userId, userIdOk := l.ctx.Value("userId").(int64)
|
||||
if !userIdOk {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
productCode, productCodeOk := l.ctx.Value("productCode").(string)
|
||||
if !productCodeOk || productCode == "" {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
status = "failed"
|
||||
charges = false
|
||||
} else {
|
||||
status = "success"
|
||||
charges = true
|
||||
}
|
||||
sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark)
|
||||
if sendApiRequestMessageErr != nil {
|
||||
logx.Errorf("发送 API 请求消息失败: %v", err)
|
||||
}
|
||||
}()
|
||||
// 1、解密
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return "", errs.ErrParamDecryption
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data validator.YYSY4B21Request
|
||||
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
return "", errs.ErrParamValidation
|
||||
}
|
||||
|
||||
// 3、西部加密
|
||||
westConfig := l.svcCtx.Config.WestConfig
|
||||
encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
|
||||
if encryptStructFieldsErr != nil {
|
||||
logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSY4B21FieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G25BJ02", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
|
||||
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||
if aesEncrypt != nil {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
return encryptData, nil
|
||||
}
|
@ -117,6 +117,9 @@ type QYGLB4C0Request struct {
|
||||
type YYSY4B37Request struct {
|
||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||
}
|
||||
type YYSY4B21Request struct {
|
||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||
}
|
||||
type YYSY6F2ERequest struct {
|
||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||
MobileType string `json:"mobile_type" validate:"omitempty,validMobileType"`
|
||||
@ -139,5 +142,5 @@ type YYSYD50FRequest struct {
|
||||
}
|
||||
type YYSYF7DBRequest struct {
|
||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||
StartDate string `json:"start_date" validate:"required,validDate"`
|
||||
StartDate string `json:"start_date" validate:"required,validDate" encrypt:"false"`
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func validDate(fl validator.FieldLevel) bool {
|
||||
// 自定义身份证校验
|
||||
func validIDCard(fl validator.FieldLevel) bool {
|
||||
id := fl.Field().String()
|
||||
validIDPattern := `^\d{15}$|^\d{18}$|^\d{17}(\d|X|x)$` // 匹配15位或18位身份证
|
||||
validIDPattern := `^\d{17}(\d|X|x)$` // 匹配18位身份证号码
|
||||
matched, _ := regexp.MatchString(validIDPattern, id)
|
||||
return matched
|
||||
}
|
||||
|
@ -101,6 +101,9 @@ var QYGLB4C0FieldMapping = map[string]string{
|
||||
var YYSY4B37FieldMapping = map[string]string{
|
||||
"MobileNo": "phone",
|
||||
}
|
||||
var YYSY4B21FieldMapping = map[string]string{
|
||||
"MobileNo": "phone",
|
||||
}
|
||||
var YYSY6F2EFieldMapping = map[string]string{
|
||||
"IDCard": "idNo",
|
||||
"Name": "name",
|
||||
|
@ -258,17 +258,44 @@ type (
|
||||
AliTopUpResponse {
|
||||
payUrl string `json:"payUrl"`
|
||||
}
|
||||
GetTopUpListReq {
|
||||
Page int64 `form:"page"`
|
||||
PageSize int64 `form:"pageSize"`
|
||||
}
|
||||
GetTopUpListResp {
|
||||
Total int64 `json:"total"`
|
||||
List []TopUpItem `json:"list"`
|
||||
}
|
||||
TopUpItem {
|
||||
Id int64 `json:"id"` // 主键ID
|
||||
UserId int64 `json:"user_id"` // 用户ID
|
||||
TransactionId string `json:"transaction_id"` // 交易ID
|
||||
OutTradeNo string `json:"out_trade_no"` // 外部订单号
|
||||
Amount float64 `json:"amount"` // 充值金额
|
||||
PaymentMethod int64 `json:"payment_method"` // 支付方式
|
||||
CreatedAt string `json:"created_at"` // 创建时间
|
||||
UpdatedAt string `json:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: topup
|
||||
prefix: /api/console/topupfmghnjx
|
||||
prefix: /api/console/topup
|
||||
middleware: AuthInterceptor,EntAuthInterceptor
|
||||
)
|
||||
service gateway-api {
|
||||
@handler aliTopUp
|
||||
post /aliTopUp (AliTopUpRequest) returns (AliTopUpResponse)
|
||||
|
||||
@handler topList
|
||||
get /topUpList (GetTopUpListReq) returns (GetTopUpListResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: topup
|
||||
prefix: /api/console/topup
|
||||
)
|
||||
service gateway-api {
|
||||
@handler aliTopUpCallback
|
||||
post /aliTopUpCallback
|
||||
}
|
||||
|
@ -90,13 +90,24 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Handler: topup.AliTopUpHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/aliTopUpCallback",
|
||||
Handler: topup.AliTopUpCallbackHandler(serverCtx),
|
||||
Method: http.MethodGet,
|
||||
Path: "/topUpList",
|
||||
Handler: topup.TopListHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/console/topupfmghnjx"),
|
||||
rest.WithPrefix("/api/console/topup"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/aliTopUpCallback",
|
||||
Handler: topup.AliTopUpCallbackHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/console/topup"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
|
30
apps/gateway/internal/handler/topup/toplisthandler.go
Normal file
30
apps/gateway/internal/handler/topup/toplisthandler.go
Normal file
@ -0,0 +1,30 @@
|
||||
package topup
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tianyuan-api/apps/gateway/internal/logic/topup"
|
||||
"tianyuan-api/apps/gateway/internal/svc"
|
||||
"tianyuan-api/apps/gateway/internal/types"
|
||||
|
||||
xhttp "github.com/zeromicro/x/http"
|
||||
)
|
||||
|
||||
func TopListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetTopUpListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := topup.NewTopListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.TopList(&req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,11 @@ func NewAliTopUpCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
|
||||
func (l *AliTopUpCallbackLogic) AliTopUpCallback(r *http.Request) error {
|
||||
_, err := l.svcCtx.TopUpRpc.AliTopUpNotify(l.ctx, &sentinel.AliTopUpNotifyRequest{
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = l.svcCtx.TopUpRpc.AliTopUpNotify(l.ctx, &sentinel.AliTopUpNotifyRequest{
|
||||
RawForm: r.Form.Encode(),
|
||||
})
|
||||
if err != nil {
|
||||
|
59
apps/gateway/internal/logic/topup/toplistlogic.go
Normal file
59
apps/gateway/internal/logic/topup/toplistlogic.go
Normal file
@ -0,0 +1,59 @@
|
||||
package topup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"tianyuan-api/apps/gateway/internal/svc"
|
||||
"tianyuan-api/apps/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type TopListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewTopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopListLogic {
|
||||
return &TopListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *TopListLogic) TopList(req *types.GetTopUpListReq) (resp *types.GetTopUpListResp, err error) {
|
||||
userId, ok := l.ctx.Value("userId").(int64)
|
||||
if !ok {
|
||||
return nil, errors.New("无法获取 userId")
|
||||
}
|
||||
list, err := l.svcCtx.Wallets.GetRechargeList(l.ctx, &user.RechargeRequest{
|
||||
UserId: userId,
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var topUpItemList []types.TopUpItem
|
||||
|
||||
for _, p := range list.List {
|
||||
topUpItemList = append(topUpItemList, types.TopUpItem{
|
||||
Id: p.Id,
|
||||
UserId: p.UserId,
|
||||
TransactionId: p.TransactionId,
|
||||
OutTradeNo: p.OutTradeNo,
|
||||
Amount: float64(p.Amount),
|
||||
PaymentMethod: p.PaymentMethod,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
return &types.GetTopUpListResp{
|
||||
Total: list.Total,
|
||||
List: topUpItemList,
|
||||
}, nil
|
||||
}
|
@ -18,6 +18,7 @@ type ServiceContext struct {
|
||||
AuthRpc user.AuthClient
|
||||
EntRpc user.EnterpriseClient
|
||||
UserRpc user.UserClient
|
||||
Wallets user.WalletServiceClient
|
||||
ProductRpc sentinel.ProductClient
|
||||
UserProductRpc sentinel.UserProductClient
|
||||
WhitelistRpc sentinel.WhitelistClient
|
||||
@ -37,11 +38,13 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
authRpc := user.NewAuthClient(zrpc.MustNewClient(c.UserRpc).Conn())
|
||||
entRpc := user.NewEnterpriseClient(zrpc.MustNewClient(c.UserRpc).Conn())
|
||||
userRpc := user.NewUserClient(zrpc.MustNewClient(c.UserRpc).Conn())
|
||||
wallets := user.NewWalletServiceClient(zrpc.MustNewClient(c.UserRpc).Conn())
|
||||
productRpc := sentinel.NewProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
|
||||
userProductRpc := sentinel.NewUserProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
|
||||
whitelistRpc := sentinel.NewWhitelistClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
|
||||
secretRpc := sentinel.NewSecretClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
|
||||
topUpRpc := sentinel.NewTopUpClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
AuthInterceptor: middleware.NewAuthInterceptorMiddleware(c).Handle,
|
||||
@ -55,5 +58,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
WhitelistRpc: whitelistRpc,
|
||||
SecretRpc: secretRpc,
|
||||
TopUpRpc: topUpRpc,
|
||||
Wallets: wallets,
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,16 @@ type GetProductListResp struct {
|
||||
List []ProductItem `json:"list"`
|
||||
}
|
||||
|
||||
type GetTopUpListReq struct {
|
||||
Page int64 `form:"page"`
|
||||
PageSize int64 `form:"pageSize"`
|
||||
}
|
||||
|
||||
type GetTopUpListResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List []TopUpItem `json:"list"`
|
||||
}
|
||||
|
||||
type GetUserProductListReq struct {
|
||||
Page int64 `form:"page"`
|
||||
PageSize int64 `form:"pageSize"`
|
||||
@ -95,6 +105,17 @@ type RegisterReq struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type TopUpItem struct {
|
||||
Id int64 `json:"id"` // 主键ID
|
||||
UserId int64 `json:"user_id"` // 用户ID
|
||||
TransactionId string `json:"transaction_id"` // 交易ID
|
||||
OutTradeNo string `json:"out_trade_no"` // 外部订单号
|
||||
Amount float64 `json:"amount"` // 充值金额
|
||||
PaymentMethod int64 `json:"payment_method"` // 支付方式
|
||||
CreatedAt string `json:"created_at"` // 创建时间
|
||||
UpdatedAt string `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
type UploadBusinessLicenseResp struct {
|
||||
Url string `json:"url"`
|
||||
EnterpriseName string `json:"enterpriseName"`
|
||||
|
@ -13,11 +13,14 @@ Alipay:
|
||||
AppID: "2021004181633376"
|
||||
PrivateKey: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCC2GNEWrQUg6FVHBdlDcgL1SA1KmRI8IHgSJGvXEsgfo3g62aa5usFXHVz5bMzpIcDu0N+jGtZQIBuuq7TxGwhDvWBygEDXN17p00uwqik/3TsyFvJ4FfbkaS7pRIGfeO/cBTzjqznanPUdHJZ9L39QmTqTefIQQvGOCvgntKxPa/LdS24+ZLA2RNh3TsRzbSxOOJPmUrwvCX8U13F9jH250hvf+Tewz4hyG8CkiMM4d1UpGMndQNr8oTY0vwFbWAG0ZDGgkxjg0iRJ02fgxwShQS1TgY5NxPhpKBiN5C/WG15qCqEw0F3GlpfWZwzUhv1uMiy+xbZ2bGLo1YCtwUtAgMBAAECggEAQ8uk25T3u61cWYH9qTGT1nWug32ciqJ7WN+hBLCYiJSqJMEz380INzXp8Ywx5u83ubo8xYQyVwNxyG3YCge7UwGyOXaWQczLQbe06SaZRSzLw6gozxf7zdvP9B4akdyGtfl4EZ56fkmNDKbtXSjPjDrrmO+Wyg7R7/nI2lDQsF6dXTKD0YiHtTKz40amKgbIYX+qc3yVS0slkVjcfnRczr+PKM5RMsV3Jk2pr6IYeq3E24LnbuVtV76priTqJN3hVSy2Y6JqmAYkI0HCoCuaFGE8ud3J859jjMcUXTRFJyDsKKooa+FZCoEx2ToVMqnb4vjfr1gZifUrw4ZNd5cPoQKBgQC4v/fNTXuA21pb+l4fnqK0o3wFhiNJh920yIlF4Vd0Nsi2/TwqFK6cVhrUFAmKr88hTzY1vkOhd/HLlkWjNDR5OGx1K1BKUAZjWIfProv8lDSckADEI29lro9WzFGy0o4szlEJ2uuUfO/j9Qn2lmx5oFPsz0TI+HoSNFE0q/SlxQKBgQC1ToMLuh0OkucZm1SL6xcjudBX7U0ElZ/TIxRzfxQ/sN911/BRlxrSdCcDMXNuuFpV2ACjDNWWLJM1sRVsOWNA/oXzZf6VTvUDIAv8XrNUt/B87genBVuMTZ2RYmMWCrgW0PE1OrpKGuQCKVsn242B2Xpmee9OnHhBF2uTASDASQKBgBALvD38iMl8Q7DRYfNlF8SQnmjsaYwtXLgi4qlLFQlm6K/b9qnA+hlh8RqSUvHUqyy9cHvidoVDoaCJAKtYEWal2+WhSWvq32MpgUIsasQZKyid6TMf0MEIFDL5s+7QEsEZejhc5zESWNN3qNHd5rX5ktBygArkadXC7XqhpLHxAoGBAJ0dJEKNTZDLjKiMCoAVgT/cTcdkRFGst4tn4tkTTqDCzWJ5di++Geg173i86aMQ7ndlb2fcP1qb1hW5Fy9pq7Eu3zVFNZB9k6TZqIlSJ2VK4IPiYY9C/UpgGCNcdzEqqMxc1Cmkcrq1AtE8tVmc0Mutgnw7Pj2JKkx91yLU32TBAoGAKxssUdTLuf5Z5oFgzpoSES9qwc1h6jlMfsouDzHcZf0aYintD6Vby7SVul5540qYkDkNs0YZ3uZu74LHfoBaWJjYIIVAMSMX+3AtBpQUyYluex64V/g60t+0sFuDWqMvSPU7mZcv6+KIP6vW56GeYdhHf4JqttdIHm9SgkoJjjY="
|
||||
AlipayPublicKey: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2CqoCp95w/JV3RT/gzF4/8QmVT1HQNaeW7yUp+mA7x9AbjvlTW/+eRn6oGAL/XhZLjvHD0XjKLVKX0MJVS1aUQHEHEbOJN4Eu8II45OavD4iZISa7Kp9V6AM+i4qTyaeV2wNDnGxHQBaLVUGCfMR+56EK2YpORdE1H9uy72SSQseVb3bmpsV9EW/IJNmcVL/ut3uA1JWAoRmzlQ7ekxg7p8AYXzYPEHQr1tl7W+M4zv9wO9GKZCxIqMA8U3RP5npPfRaCfIRGzXzCqFEEUvWuidOB7frsvN4jiPD07qpL2Bi9LM1X/ee2kC/oM8Uhd7ERZhG8MbZfijZKxgrsDKBcwIDAQAB"
|
||||
IsProduction: false # 是否是生产环境,true为生产环境,false为沙箱环境
|
||||
IsProduction: true # 是否是生产环境,true为生产环境,false为沙箱环境
|
||||
TopUp:
|
||||
MaxTopUpAmount: 100000
|
||||
Domain:
|
||||
Front: "https://console.tianyuanapi.com"
|
||||
Backend: "https://console.tianyuanapi.com"
|
||||
NotifyURL: "https://6m4685017o.goho.co/api/console/"
|
||||
ReturnURL: "http://127.0.0.1:5173"
|
||||
Subject: "天远数据API使用额度"
|
||||
NotifyURL: "https://6m4685017o.goho.co/api/console/topup/aliTopUpCallback"
|
||||
ReturnURL: "http://127.0.0.1:5173/charge/recharge"
|
||||
UserRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: user.rpc
|
@ -16,8 +16,11 @@ Alipay:
|
||||
IsProduction: true # 是否是生产环境,true为生产环境,false为沙箱环境
|
||||
TopUp:
|
||||
MaxTopUpAmount: 100000
|
||||
Domain:
|
||||
Front: "https://console.tianyuanapi.com"
|
||||
Backend: "https://console.tianyuanapi.com"
|
||||
NotifyURL: "http://console.tianyuanapi.com/api/console/"
|
||||
ReturnURL: "https://console.tianyuanapi.com/charge/recharge"
|
||||
Subject: "天远数据API使用额度"
|
||||
NotifyURL: "http://console.tianyuanapi.com/api/console/topup/aliTopUpCallback"
|
||||
ReturnURL: "https://console.tianyuanapi.com/charge/recharge"
|
||||
UserRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- tyapi_etcd:2379
|
||||
Key: user.rpc
|
@ -11,6 +11,7 @@ type Config struct {
|
||||
CacheRedis cache.CacheConf // 缓存配置,使用 go-zero 自带的缓存配置结构体
|
||||
Alipay AlipayConfig
|
||||
TopUp TopUpConfig
|
||||
UserRpc zrpc.RpcClientConf
|
||||
}
|
||||
type AlipayConfig struct {
|
||||
AppID string
|
||||
@ -20,4 +21,7 @@ type AlipayConfig struct {
|
||||
}
|
||||
type TopUpConfig struct {
|
||||
MaxTopUpAmount int64
|
||||
Subject string
|
||||
NotifyURL string
|
||||
ReturnURL string
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ func (l *AliTopUpLogic) AliTopUp(in *sentinel.AliTopUpRequest) (*sentinel.AliTop
|
||||
// 构造支付请求
|
||||
var p = alipay.TradePagePay{
|
||||
Trade: alipay.Trade{
|
||||
Subject: "天远数据API使用额度",
|
||||
Subject: l.svcCtx.Config.TopUp.Subject,
|
||||
OutTradeNo: outTradeNo,
|
||||
TotalAmount: totalAmount,
|
||||
ProductCode: "FAST_INSTANT_TRADE_PAY",
|
||||
NotifyURL: "https://console.tianyuanapi.com/api/console/", // 异步回调通知地址
|
||||
ReturnURL: "https://console.tianyuanapi.com/charge/recharge", // 支付成功后的跳转地址
|
||||
NotifyURL: l.svcCtx.Config.TopUp.NotifyURL, // 异步回调通知地址
|
||||
ReturnURL: l.svcCtx.Config.TopUp.ReturnURL, // 支付成功后的跳转地址
|
||||
},
|
||||
}
|
||||
_, inserErr := l.svcCtx.PayOrderModel.Insert(l.ctx, &model.PayOrder{
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
@ -63,7 +64,20 @@ func (l *AliTopUpNotifyLogic) AliTopUpNotify(in *sentinel.AliTopUpNotifyRequest)
|
||||
logx.Infof("回调金额:%v,订单金额%v", notify.TotalAmount, payOrder.Amount)
|
||||
// 比较支付宝返回的金额与数据库存储的金额
|
||||
if math.Abs(notifyAmount-payOrder.Amount) < 1e-6 {
|
||||
// 金额匹配,继续处理
|
||||
payOrder.Status = 1
|
||||
updateErr := l.svcCtx.PayOrderModel.Update(l.ctx, payOrder)
|
||||
if updateErr != nil {
|
||||
return nil, globalErr
|
||||
}
|
||||
_, rechargeWallet := l.svcCtx.WalletRpc.RechargeWallet(l.ctx, &user.RechargeWalletRequest{
|
||||
UserId: payOrder.UserId,
|
||||
OutTradeNo: payOrder.OutTradeNo,
|
||||
Amount: int64(payOrder.Amount),
|
||||
PaymentMethod: 0,
|
||||
})
|
||||
if rechargeWallet != nil {
|
||||
return nil, globalErr
|
||||
}
|
||||
} else {
|
||||
return nil, globalErr
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ import (
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"tianyuan-api/apps/sentinel/internal/config"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/user/user"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
@ -18,6 +20,7 @@ type ServiceContext struct {
|
||||
ProductsModel model.ProductsModel
|
||||
UserProductsModel model.UserProductsModel
|
||||
PayOrderModel model.PayOrderModel
|
||||
WalletRpc user.WalletServiceClient
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
@ -41,6 +44,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("加载支付宝公钥失败: %v", err))
|
||||
}
|
||||
|
||||
walletRpc := user.NewWalletServiceClient(zrpc.MustNewClient(c.UserRpc).Conn())
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Redis: rds,
|
||||
@ -50,5 +55,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
ProductsModel: model.NewProductsModel(db, c.CacheRedis),
|
||||
UserProductsModel: model.NewUserProductsModel(rds, db, c.CacheRedis),
|
||||
PayOrderModel: model.NewPayOrderModel(db, c.CacheRedis),
|
||||
WalletRpc: walletRpc,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/config"
|
||||
TopUpServer "tianyuan-api/apps/sentinel/internal/server/TopUp"
|
||||
productServer "tianyuan-api/apps/sentinel/internal/server/product"
|
||||
secretServer "tianyuan-api/apps/sentinel/internal/server/secret"
|
||||
userproductServer "tianyuan-api/apps/sentinel/internal/server/userproduct"
|
||||
@ -48,6 +49,7 @@ func main() {
|
||||
sentinel.RegisterSecretServer(grpcServer, secretServer.NewSecretServer(ctx))
|
||||
sentinel.RegisterProductServer(grpcServer, productServer.NewProductServer(ctx))
|
||||
sentinel.RegisterUserProductServer(grpcServer, userproductServer.NewUserProductServer(ctx))
|
||||
sentinel.RegisterTopUpServer(grpcServer, TopUpServer.NewTopUpServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
|
@ -39,6 +39,11 @@ type (
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RechargeItem = user.RechargeItem
|
||||
RechargeRequest = user.RechargeRequest
|
||||
RechargeResponse = user.RechargeResponse
|
||||
RechargeWalletRequest = user.RechargeWalletRequest
|
||||
RechargeWalletResponse = user.RechargeWalletResponse
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
|
@ -39,6 +39,11 @@ type (
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RechargeItem = user.RechargeItem
|
||||
RechargeRequest = user.RechargeRequest
|
||||
RechargeResponse = user.RechargeResponse
|
||||
RechargeWalletRequest = user.RechargeWalletRequest
|
||||
RechargeWalletResponse = user.RechargeWalletResponse
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
|
@ -39,6 +39,11 @@ type (
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RechargeItem = user.RechargeItem
|
||||
RechargeRequest = user.RechargeRequest
|
||||
RechargeResponse = user.RechargeResponse
|
||||
RechargeWalletRequest = user.RechargeWalletRequest
|
||||
RechargeWalletResponse = user.RechargeWalletResponse
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
|
@ -39,6 +39,11 @@ type (
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RechargeItem = user.RechargeItem
|
||||
RechargeRequest = user.RechargeRequest
|
||||
RechargeResponse = user.RechargeResponse
|
||||
RechargeWalletRequest = user.RechargeWalletRequest
|
||||
RechargeWalletResponse = user.RechargeWalletResponse
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
|
@ -39,6 +39,11 @@ type (
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RechargeItem = user.RechargeItem
|
||||
RechargeRequest = user.RechargeRequest
|
||||
RechargeResponse = user.RechargeResponse
|
||||
RechargeWalletRequest = user.RechargeWalletRequest
|
||||
RechargeWalletResponse = user.RechargeWalletResponse
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
@ -54,6 +59,10 @@ type (
|
||||
// 查询扣款记录
|
||||
GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error)
|
||||
// 定义充值请求接口
|
||||
RechargeWallet(ctx context.Context, in *RechargeWalletRequest, opts ...grpc.CallOption) (*RechargeWalletResponse, error)
|
||||
// 充值记录列表篇
|
||||
GetRechargeList(ctx context.Context, in *RechargeRequest, opts ...grpc.CallOption) (*RechargeResponse, error)
|
||||
}
|
||||
|
||||
defaultWalletService struct {
|
||||
@ -89,3 +98,15 @@ func (m *defaultWalletService) GetDeductionByTransactionId(ctx context.Context,
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.GetDeductionByTransactionId(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 定义充值请求接口
|
||||
func (m *defaultWalletService) RechargeWallet(ctx context.Context, in *RechargeWalletRequest, opts ...grpc.CallOption) (*RechargeWalletResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.RechargeWallet(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 充值记录列表篇
|
||||
func (m *defaultWalletService) GetRechargeList(ctx context.Context, in *RechargeRequest, opts ...grpc.CallOption) (*RechargeResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.GetRechargeList(ctx, in, opts...)
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetRechargeListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetRechargeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRechargeListLogic {
|
||||
return &GetRechargeListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 充值记录列表篇
|
||||
func (l *GetRechargeListLogic) GetRechargeList(in *user.RechargeRequest) (*user.RechargeResponse, error) {
|
||||
list, total, err := l.svcCtx.RechargeModel.FindRechargeListByUserId(l.ctx, in.UserId, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var rechargeItemList []*user.RechargeItem
|
||||
for _, w := range list {
|
||||
rechargeItemList = append(rechargeItemList, &user.RechargeItem{
|
||||
Id: w.Id,
|
||||
UserId: w.UserId,
|
||||
TransactionId: w.TransactionId,
|
||||
OutTradeNo: w.OutTradeNo,
|
||||
Amount: float32(w.Amount),
|
||||
PaymentMethod: w.PaymentMethod,
|
||||
CreatedAt: w.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: w.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &user.RechargeResponse{
|
||||
List: rechargeItemList,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"tianyuan-api/pkg/generate"
|
||||
"time"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RechargeWalletLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewRechargeWalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeWalletLogic {
|
||||
return &RechargeWalletLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 定义充值请求接口
|
||||
func (l *RechargeWalletLogic) RechargeWallet(in *user.RechargeWalletRequest) (*user.RechargeWalletResponse, error) {
|
||||
if in.Amount <= 0 {
|
||||
return nil, errors.New("金额不能小于0")
|
||||
}
|
||||
// 启动事务
|
||||
err := l.svcCtx.WalletsModel.TransCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
var err error
|
||||
// 更新余额(充值金额是正数,增加余额)
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
err = l.svcCtx.WalletsModel.UpdateBalance(session, l.ctx, in.UserId, float64(in.Amount))
|
||||
if err == nil {
|
||||
// 成功,退出循环
|
||||
break
|
||||
}
|
||||
if errors.Is(err, model.ErrVersionMismatch) {
|
||||
// 版本号不匹配,重试
|
||||
time.Sleep(100 * time.Millisecond) // 重试前的延迟
|
||||
continue
|
||||
} else {
|
||||
// 其他错误,直接返回
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 生成交易单号
|
||||
TransactionId := generate.GenerateTransactionID()
|
||||
// 更新余额成功后,插入充值记录
|
||||
_, err = l.svcCtx.RechargeModel.InsertRechargeTrans(ctx, &model.Recharge{
|
||||
TransactionId: TransactionId,
|
||||
OutTradeNo: in.OutTradeNo,
|
||||
UserId: in.UserId,
|
||||
Amount: float64(in.Amount),
|
||||
}, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 返回成功的充值响应
|
||||
return &user.RechargeWalletResponse{}, nil
|
||||
}
|
74
apps/user/internal/model/rechargemodel.go
Normal file
74
apps/user/internal/model/rechargemodel.go
Normal file
@ -0,0 +1,74 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ RechargeModel = (*customRechargeModel)(nil)
|
||||
|
||||
type (
|
||||
// RechargeModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customRechargeModel.
|
||||
RechargeModel interface {
|
||||
rechargeModel
|
||||
InsertRechargeTrans(ctx context.Context, data *Recharge, session sqlx.Session) (sql.Result, error)
|
||||
FindRechargeListByUserId(ctx context.Context, userId, page, pageSize int64) ([]*Recharge, int64, error)
|
||||
}
|
||||
|
||||
customRechargeModel struct {
|
||||
*defaultRechargeModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewRechargeModel returns a model for the database table.
|
||||
func NewRechargeModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) RechargeModel {
|
||||
return &customRechargeModel{
|
||||
defaultRechargeModel: newRechargeModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
func (m *customRechargeModel) InsertRechargeTrans(ctx context.Context, data *Recharge, session sqlx.Session) (sql.Result, error) {
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, data.OutTradeNo)
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, data.TransactionId)
|
||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?)", m.table, rechargeRowsExpectAutoSet)
|
||||
ret, err := session.ExecCtx(ctx, query, data.UserId, data.TransactionId, data.OutTradeNo, data.Amount, data.PaymentMethod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 2. 更新缓存,保证所有缓存操作成功
|
||||
cacheKeys := []string{rechargeOutTradeNoKey, rechargeTransactionIdKey}
|
||||
cacheErrors := make([]error, len(cacheKeys))
|
||||
|
||||
cacheErrors[0] = m.DelCacheCtx(ctx, rechargeOutTradeNoKey)
|
||||
cacheErrors[1] = m.DelCacheCtx(ctx, rechargeTransactionIdKey)
|
||||
// 3. 检查缓存操作是否全部成功
|
||||
for _, cacheErr := range cacheErrors {
|
||||
if cacheErr != nil {
|
||||
return nil, cacheErr // 返回第一个缓存更新失败的错误
|
||||
}
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
func (m *customRechargeModel) FindRechargeListByUserId(ctx context.Context, userId, page, pageSize int64) ([]*Recharge, int64, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
query := fmt.Sprintf("SELECT * FROM recharge WHERE user_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?")
|
||||
|
||||
var recharges []*Recharge
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &recharges, query, userId, pageSize, offset)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 获取总记录数
|
||||
var total int64
|
||||
countQuery := "SELECT COUNT(1) FROM recharge WHERE user_id = ?"
|
||||
err = m.QueryRowNoCacheCtx(ctx, &total, countQuery, userId)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return recharges, total, nil
|
||||
}
|
177
apps/user/internal/model/rechargemodel_gen.go
Normal file
177
apps/user/internal/model/rechargemodel_gen.go
Normal file
@ -0,0 +1,177 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
rechargeFieldNames = builder.RawFieldNames(&Recharge{})
|
||||
rechargeRows = strings.Join(rechargeFieldNames, ",")
|
||||
rechargeRowsExpectAutoSet = strings.Join(stringx.Remove(rechargeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
rechargeRowsWithPlaceHolder = strings.Join(stringx.Remove(rechargeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheRechargeIdPrefix = "cache:recharge:id:"
|
||||
cacheRechargeOutTradeNoPrefix = "cache:recharge:outTradeNo:"
|
||||
cacheRechargeTransactionIdPrefix = "cache:recharge:transactionId:"
|
||||
)
|
||||
|
||||
type (
|
||||
rechargeModel interface {
|
||||
Insert(ctx context.Context, data *Recharge) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Recharge, error)
|
||||
FindOneByOutTradeNo(ctx context.Context, outTradeNo string) (*Recharge, error)
|
||||
FindOneByTransactionId(ctx context.Context, transactionId string) (*Recharge, error)
|
||||
Update(ctx context.Context, data *Recharge) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultRechargeModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Recharge struct {
|
||||
Id int64 `db:"id"` // 主键
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
TransactionId string `db:"transaction_id"` // 交易ID,唯一
|
||||
OutTradeNo string `db:"out_trade_no"` // 外部订单号,唯一
|
||||
Amount float64 `db:"amount"` // 充值金额
|
||||
PaymentMethod int64 `db:"payment_method"` // 充值方式 1-支付宝在线支付, 2-对公转账
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newRechargeModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultRechargeModel {
|
||||
return &defaultRechargeModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`recharge`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rechargeIdKey := fmt.Sprintf("%s%v", cacheRechargeIdPrefix, id)
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, data.OutTradeNo)
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, rechargeIdKey, rechargeOutTradeNoKey, rechargeTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) FindOne(ctx context.Context, id int64) (*Recharge, error) {
|
||||
rechargeIdKey := fmt.Sprintf("%s%v", cacheRechargeIdPrefix, id)
|
||||
var resp Recharge
|
||||
err := m.QueryRowCtx(ctx, &resp, rechargeIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", rechargeRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) FindOneByOutTradeNo(ctx context.Context, outTradeNo string) (*Recharge, error) {
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, outTradeNo)
|
||||
var resp Recharge
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, rechargeOutTradeNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `out_trade_no` = ? limit 1", rechargeRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, outTradeNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) FindOneByTransactionId(ctx context.Context, transactionId string) (*Recharge, error) {
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, transactionId)
|
||||
var resp Recharge
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, rechargeTransactionIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `transaction_id` = ? limit 1", rechargeRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, transactionId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) Insert(ctx context.Context, data *Recharge) (sql.Result, error) {
|
||||
rechargeIdKey := fmt.Sprintf("%s%v", cacheRechargeIdPrefix, data.Id)
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, data.OutTradeNo)
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, data.TransactionId)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, rechargeRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.TransactionId, data.OutTradeNo, data.Amount, data.PaymentMethod)
|
||||
}, rechargeIdKey, rechargeOutTradeNoKey, rechargeTransactionIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) Update(ctx context.Context, newData *Recharge) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rechargeIdKey := fmt.Sprintf("%s%v", cacheRechargeIdPrefix, data.Id)
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, data.OutTradeNo)
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, rechargeRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.TransactionId, newData.OutTradeNo, newData.Amount, newData.PaymentMethod, newData.Id)
|
||||
}, rechargeIdKey, rechargeOutTradeNoKey, rechargeTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheRechargeIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", rechargeRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultRechargeModel) tableName() string {
|
||||
return m.table
|
||||
}
|
@ -45,3 +45,15 @@ func (s *WalletServiceServer) GetDeductionByTransactionId(ctx context.Context, i
|
||||
l := walletservicelogic.NewGetDeductionByTransactionIdLogic(ctx, s.svcCtx)
|
||||
return l.GetDeductionByTransactionId(in)
|
||||
}
|
||||
|
||||
// 定义充值请求接口
|
||||
func (s *WalletServiceServer) RechargeWallet(ctx context.Context, in *user.RechargeWalletRequest) (*user.RechargeWalletResponse, error) {
|
||||
l := walletservicelogic.NewRechargeWalletLogic(ctx, s.svcCtx)
|
||||
return l.RechargeWallet(in)
|
||||
}
|
||||
|
||||
// 充值记录列表篇
|
||||
func (s *WalletServiceServer) GetRechargeList(ctx context.Context, in *user.RechargeRequest) (*user.RechargeResponse, error) {
|
||||
l := walletservicelogic.NewGetRechargeListLogic(ctx, s.svcCtx)
|
||||
return l.GetRechargeList(in)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ type ServiceContext struct {
|
||||
WalletsModel model.WalletsModel
|
||||
DeductionsModel model.DeductionsModel
|
||||
ApiRequestsModel model.ApiRequestsModel
|
||||
RechargeModel model.RechargeModel
|
||||
SecretRpc sentinel.SecretClient
|
||||
ProductRpc sentinel.ProductClient
|
||||
}
|
||||
@ -41,6 +42,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
WalletsModel: model.NewWalletsModel(db, c.CacheRedis),
|
||||
DeductionsModel: model.NewDeductionsModel(db, c.CacheRedis),
|
||||
ApiRequestsModel: model.NewApiRequestsModel(db, c.CacheRedis),
|
||||
RechargeModel: model.NewRechargeModel(db, c.CacheRedis),
|
||||
SecretRpc: sentinel.NewSecretClient(zrpc.MustNewClient(c.SentinelRpc).Conn()),
|
||||
ProductRpc: sentinel.NewProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn()),
|
||||
}
|
||||
|
@ -139,8 +139,6 @@ service User {
|
||||
|
||||
// 定义钱包服务
|
||||
service WalletService {
|
||||
|
||||
|
||||
// 修改钱包余额
|
||||
rpc UpdateWallet (UpdateWalletRequest) returns (UpdateWalletResponse);
|
||||
|
||||
@ -151,6 +149,12 @@ service WalletService {
|
||||
rpc GetDeductions (GetDeductionsRequest) returns (GetDeductionsResponse);
|
||||
|
||||
rpc GetDeductionByTransactionId (GetDeductionByTransactionIdRequest) returns (GetDeductionByTransactionIdResponse);
|
||||
|
||||
// 定义充值请求接口
|
||||
rpc RechargeWallet (RechargeWalletRequest) returns (RechargeWalletResponse);
|
||||
|
||||
// 充值记录列表篇
|
||||
rpc GetRechargeList(RechargeRequest) returns (RechargeResponse);
|
||||
}
|
||||
|
||||
// 更新钱包余额
|
||||
@ -206,6 +210,37 @@ message Deduction {
|
||||
string created_at = 5;
|
||||
}
|
||||
|
||||
message RechargeWalletRequest {
|
||||
int64 user_id = 1; // 用户ID
|
||||
string out_trade_no = 2; // 订单号
|
||||
int64 amount = 3; // 充值金额
|
||||
int64 payment_method = 4; // 充值方式(1-支付宝在线支付, 2-对公转账)
|
||||
}
|
||||
|
||||
message RechargeWalletResponse {
|
||||
|
||||
}
|
||||
message RechargeRequest {
|
||||
int64 user_id = 1; // 用户ID
|
||||
int64 page = 2; // 分页页码
|
||||
int64 page_size = 3; // 每页大小
|
||||
}
|
||||
|
||||
message RechargeResponse {
|
||||
repeated RechargeItem list = 1; // 充值记录列表
|
||||
int64 total = 2; // 总记录数
|
||||
}
|
||||
|
||||
message RechargeItem {
|
||||
int64 id = 1; // 主键ID
|
||||
int64 user_id = 2; // 用户ID
|
||||
string transaction_id = 3; // 交易ID
|
||||
string out_trade_no = 4; // 外部订单号
|
||||
float amount = 5; // 充值金额
|
||||
int64 payment_method = 6; // 支付方式
|
||||
string created_at = 7; // 创建时间
|
||||
string updated_at = 8; // 更新时间
|
||||
}
|
||||
|
||||
service ApiRequestService {
|
||||
// 添加API请求记录
|
||||
|
@ -70,3 +70,15 @@ CREATE TABLE api_requests (
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '请求时间',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='API请求记录表,存储API请求的相关信息';
|
||||
|
||||
CREATE TABLE `recharge` (
|
||||
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
user_id INT(11) NOT NULL COMMENT '用户ID',
|
||||
`transaction_id` VARCHAR(64) NOT NULL UNIQUE COMMENT '交易ID,唯一',
|
||||
`out_trade_no` VARCHAR(64) NOT NULL UNIQUE COMMENT '外部订单号,唯一',
|
||||
`amount` DECIMAL(10, 2) NOT NULL COMMENT '充值金额',
|
||||
`payment_method` TINYINT NOT NULL COMMENT '充值方式 1-支付宝在线支付, 2-对公转账',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='充值记录表';
|
File diff suppressed because it is too large
Load Diff
@ -546,6 +546,8 @@ const (
|
||||
WalletService_GetWallet_FullMethodName = "/WalletService/GetWallet"
|
||||
WalletService_GetDeductions_FullMethodName = "/WalletService/GetDeductions"
|
||||
WalletService_GetDeductionByTransactionId_FullMethodName = "/WalletService/GetDeductionByTransactionId"
|
||||
WalletService_RechargeWallet_FullMethodName = "/WalletService/RechargeWallet"
|
||||
WalletService_GetRechargeList_FullMethodName = "/WalletService/GetRechargeList"
|
||||
)
|
||||
|
||||
// WalletServiceClient is the client API for WalletService service.
|
||||
@ -561,6 +563,10 @@ type WalletServiceClient interface {
|
||||
// 查询扣款记录
|
||||
GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error)
|
||||
// 定义充值请求接口
|
||||
RechargeWallet(ctx context.Context, in *RechargeWalletRequest, opts ...grpc.CallOption) (*RechargeWalletResponse, error)
|
||||
// 充值记录列表篇
|
||||
GetRechargeList(ctx context.Context, in *RechargeRequest, opts ...grpc.CallOption) (*RechargeResponse, error)
|
||||
}
|
||||
|
||||
type walletServiceClient struct {
|
||||
@ -611,6 +617,26 @@ func (c *walletServiceClient) GetDeductionByTransactionId(ctx context.Context, i
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) RechargeWallet(ctx context.Context, in *RechargeWalletRequest, opts ...grpc.CallOption) (*RechargeWalletResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RechargeWalletResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_RechargeWallet_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) GetRechargeList(ctx context.Context, in *RechargeRequest, opts ...grpc.CallOption) (*RechargeResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RechargeResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_GetRechargeList_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// WalletServiceServer is the server API for WalletService service.
|
||||
// All implementations must embed UnimplementedWalletServiceServer
|
||||
// for forward compatibility
|
||||
@ -624,6 +650,10 @@ type WalletServiceServer interface {
|
||||
// 查询扣款记录
|
||||
GetDeductions(context.Context, *GetDeductionsRequest) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(context.Context, *GetDeductionByTransactionIdRequest) (*GetDeductionByTransactionIdResponse, error)
|
||||
// 定义充值请求接口
|
||||
RechargeWallet(context.Context, *RechargeWalletRequest) (*RechargeWalletResponse, error)
|
||||
// 充值记录列表篇
|
||||
GetRechargeList(context.Context, *RechargeRequest) (*RechargeResponse, error)
|
||||
mustEmbedUnimplementedWalletServiceServer()
|
||||
}
|
||||
|
||||
@ -643,6 +673,12 @@ func (UnimplementedWalletServiceServer) GetDeductions(context.Context, *GetDeduc
|
||||
func (UnimplementedWalletServiceServer) GetDeductionByTransactionId(context.Context, *GetDeductionByTransactionIdRequest) (*GetDeductionByTransactionIdResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetDeductionByTransactionId not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) RechargeWallet(context.Context, *RechargeWalletRequest) (*RechargeWalletResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RechargeWallet not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) GetRechargeList(context.Context, *RechargeRequest) (*RechargeResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetRechargeList not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) mustEmbedUnimplementedWalletServiceServer() {}
|
||||
|
||||
// UnsafeWalletServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
@ -728,6 +764,42 @@ func _WalletService_GetDeductionByTransactionId_Handler(srv interface{}, ctx con
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WalletService_RechargeWallet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RechargeWalletRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).RechargeWallet(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_RechargeWallet_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).RechargeWallet(ctx, req.(*RechargeWalletRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WalletService_GetRechargeList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RechargeRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).GetRechargeList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_GetRechargeList_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).GetRechargeList(ctx, req.(*RechargeRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// WalletService_ServiceDesc is the grpc.ServiceDesc for WalletService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@ -751,6 +823,14 @@ var WalletService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GetDeductionByTransactionId",
|
||||
Handler: _WalletService_GetDeductionByTransactionId_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "RechargeWallet",
|
||||
Handler: _WalletService_RechargeWallet_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetRechargeList",
|
||||
Handler: _WalletService_GetRechargeList_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user.proto",
|
||||
|
15
westDex/westDex.go
Normal file
15
westDex/westDex.go
Normal file
@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := "GBymoxlPVETbdHlL6lI20qG6i006C3WkVM/m4AVpD9G7YE3rvAELhTrgcP7XTF0kgJ8sr9PVmiX0AdLyceIzYHzeGRGQFr1k9YbcSCzhwEBnsybVGunurX7RnhPNpCzKI0k1FUWaIkH3UXl5DNPly+fH822K7IUGiYDpKKDb8Rl5xMmIuRuO7D5CvhNhT3wgIVzHcdpoSDQ9eTREyODC2Q=="
|
||||
decrypt, err := crypto.WestDexDecrypt(data, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(string(decrypt))
|
||||
}
|
Loading…
Reference in New Issue
Block a user