kgen 平台接口

This commit is contained in:
lianghuanjie
2025-01-13 19:48:14 +08:00
parent 2b9a1acce2
commit d592615908
9 changed files with 322 additions and 0 deletions

33
doc/api/kgen.api Normal file
View File

@@ -0,0 +1,33 @@
syntax = "v1"
@server (
prefix: /gapi/kgen
middleware: KGeNApiKeyCheck
group: kgen
)
service novatask {
@doc "KGeN任务完成检查"
@handler KGeNTaskCheck
get /task (KGeNTaskCheckReq) returns (KGeNResult)
}
type KGeNTaskCheckReq {
ApiKey string `header:"x-api-key"` // api key
Email string `form:"email"` // 邮箱
Type int8 `form:"type"` // 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)
}
type KGeNStatus {
Code int `json:"code"` // 状态码
Msg string `json:"msg"` // 状态信息
}
type KGeNResultData {
IsValid bool `json:"isValid"` // true:是false:否
}
type KGeNResult {
Status KGeNStatus `json:"status"` // 状态
Data KGeNResultData `json:"data"` // 数据
}

View File

@@ -4,6 +4,7 @@ import "task.api"
import "carv.api" import "carv.api"
import "admin.api" import "admin.api"
import "game7.api" import "game7.api"
import "kgen.api"
info ( info (
desc: "nova api" desc: "nova api"

View File

@@ -393,6 +393,50 @@
] ]
} }
}, },
"/gapi/kgen/task": {
"get": {
"summary": "KGeN任务完成检查",
"operationId": "KGeNTaskCheck",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/KGeNResult"
}
}
},
"parameters": [
{
"name": "x-api-key",
"description": " api key",
"in": "header",
"required": true,
"type": "string"
},
{
"name": "email",
"description": " 邮箱",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "type",
"description": " 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)",
"in": "query",
"required": true,
"type": "integer",
"format": "int8"
}
],
"tags": [
"kgen"
],
"consumes": [
"multipart/form-data"
]
}
},
"/gapi/task/v1/community": { "/gapi/task/v1/community": {
"get": { "get": {
"summary": "获取社区列表", "summary": "获取社区列表",
@@ -900,6 +944,76 @@
"points" "points"
] ]
}, },
"KGeNResult": {
"type": "object",
"properties": {
"status": {
"$ref": "#/definitions/KGeNStatus",
"description": " 状态"
},
"data": {
"$ref": "#/definitions/KGeNResultData",
"description": " 数据"
}
},
"title": "KGeNResult",
"required": [
"status",
"data"
]
},
"KGeNResultData": {
"type": "object",
"properties": {
"isValid": {
"type": "boolean",
"format": "boolean",
"description": " true:是false:否"
}
},
"title": "KGeNResultData",
"required": [
"isValid"
]
},
"KGeNStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"description": " 状态码"
},
"msg": {
"type": "string",
"description": " 状态信息"
}
},
"title": "KGeNStatus",
"required": [
"code",
"msg"
]
},
"KGeNTaskCheckReq": {
"type": "object",
"properties": {
"email": {
"type": "string",
"description": " 邮箱"
},
"type": {
"type": "integer",
"format": "int8",
"description": " 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)"
}
},
"title": "KGeNTaskCheckReq",
"required": [
"email",
"type"
]
},
"Result": { "Result": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@@ -0,0 +1,29 @@
package kgen
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"nova_task/internal/logic/kgen"
"nova_task/internal/svc"
"nova_task/internal/types"
)
// KGeN任务完成检查
func KGeNTaskCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.KGeNTaskCheckReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := kgen.NewKGeNTaskCheckLogic(r.Context(), svcCtx)
resp, err := l.KGeNTaskCheck(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -9,6 +9,7 @@ import (
admin "nova_task/internal/handler/admin" admin "nova_task/internal/handler/admin"
carv "nova_task/internal/handler/carv" carv "nova_task/internal/handler/carv"
game7 "nova_task/internal/handler/game7" game7 "nova_task/internal/handler/game7"
kgen "nova_task/internal/handler/kgen"
task "nova_task/internal/handler/task" task "nova_task/internal/handler/task"
"nova_task/internal/svc" "nova_task/internal/svc"
@@ -109,6 +110,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/gapi/game7"), rest.WithPrefix("/gapi/game7"),
) )
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.KGeNApiKeyCheck},
[]rest.Route{
{
// KGeN任务完成检查
Method: http.MethodGet,
Path: "/task",
Handler: kgen.KGeNTaskCheckHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/gapi/kgen"),
)
server.AddRoutes( server.AddRoutes(
[]rest.Route{ []rest.Route{
{ {

View File

@@ -0,0 +1,71 @@
package kgen
import (
"context"
"errors"
"nova_task/internal/consts"
"nova_task/internal/model"
"nova_task/internal/pkg/errs"
"nova_task/internal/svc"
"nova_task/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type KGeNTaskCheckLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewKGeNTaskCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KGeNTaskCheckLogic {
return &KGeNTaskCheckLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *KGeNTaskCheckLogic) KGeNTaskCheck(req *types.KGeNTaskCheckReq) (resp *types.KGeNResultData, err error) {
uid, resultErr := l.svcCtx.GetUidByEmail(l.ctx, req.Email)
if resultErr != nil {
if resultErr.Error.Code == int(errs.ErrUserNotFound) {
return &types.KGeNResultData{
IsValid: false,
}, nil
}
return nil, errs.New(errs.Reason(resultErr.Error.Code), resultErr.Error.Message)
}
pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
return nil, errs.New(errs.ErrDatabaseOperate, err)
}
return &types.KGeNResultData{
IsValid: false,
}, nil
}
shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.KgenIoInviterId)
if pb.ShareUid != shareId {
return &types.KGeNResultData{
IsValid: false,
}, nil
}
var isValid bool
// 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)
switch req.Type {
case 1:
isValid = true
case 2:
isValid = pb.IsBindWallet == 1
case 3:
isValid = pb.IsCreateRole == 1
}
return &types.KGeNResultData{IsValid: isValid}, nil
}

View File

@@ -0,0 +1,36 @@
package middleware
import (
"net/http"
"nova_task/internal/consts"
"nova_task/internal/model"
"nova_task/internal/pkg/errs"
)
type KGeNApiKeyCheckMiddleware struct {
conf model.NhSystemConfigModel
}
func NewKGeNApiKeyCheckMiddleware(conf model.NhSystemConfigModel) *KGeNApiKeyCheckMiddleware {
return &KGeNApiKeyCheckMiddleware{conf: conf}
}
func (m *KGeNApiKeyCheckMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
key, err := m.conf.GetApiKey(ctx, consts.KgenApiKey)
if err != nil {
_, result := errs.ErrorHandle(errs.New(errs.ErrDatabaseOperate, "api key config not exist"))
errs.WriteHttpResponse(ctx, w, result)
return
}
apiKey := r.Header.Get("x-api-key")
if apiKey == "" || apiKey != key {
_, result := errs.ErrorHandle(errs.New(errs.ErrUnauthorized, "invalid api key"))
errs.WriteHttpResponse(ctx, w, result)
return
}
next(w, r)
}
}

View File

@@ -48,6 +48,7 @@ type ServiceContext struct {
ApiKeyCheck rest.Middleware ApiKeyCheck rest.Middleware
AdminSecretCheck rest.Middleware AdminSecretCheck rest.Middleware
Game7ApiKeyCheck rest.Middleware Game7ApiKeyCheck rest.Middleware
KGeNApiKeyCheck rest.Middleware
Earn *ea.Client Earn *ea.Client
DBConn sqlx.SqlConn DBConn sqlx.SqlConn
@@ -85,6 +86,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
ApiKeyCheck: middleware.NewApiKeyCheckMiddleware(configModel).Handle, ApiKeyCheck: middleware.NewApiKeyCheckMiddleware(configModel).Handle,
AdminSecretCheck: middleware.NewAdminSecretCheckMiddleware(configModel).Handle, AdminSecretCheck: middleware.NewAdminSecretCheckMiddleware(configModel).Handle,
Game7ApiKeyCheck: middleware.NewGame7ApiKeyCheckMiddleware(configModel).Handle, Game7ApiKeyCheck: middleware.NewGame7ApiKeyCheckMiddleware(configModel).Handle,
KGeNApiKeyCheck: middleware.NewKGeNApiKeyCheckMiddleware(configModel).Handle,
Earn: c.Earn.BuildEarnClient(), Earn: c.Earn.BuildEarnClient(),
DBConn: dbConn, DBConn: dbConn,

View File

@@ -71,6 +71,26 @@ type GetTaskRewardResp struct {
Points int `json:"points"` // 积分 Points int `json:"points"` // 积分
} }
type KGeNResult struct {
Status KGeNStatus `json:"status"` // 状态
Data KGeNResultData `json:"data"` // 数据
}
type KGeNResultData struct {
IsValid bool `json:"isValid"` // true:是false:否
}
type KGeNStatus struct {
Code int `json:"code"` // 状态码
Msg string `json:"msg"` // 状态信息
}
type KGeNTaskCheckReq struct {
ApiKey string `header:"x-api-key"` // api key
Email string `form:"email"` // 邮箱
Type int8 `form:"type"` // 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)
}
type Result struct { type Result struct {
IsValid bool `json:"isValid"` IsValid bool `json:"isValid"`
} }