update:router

This commit is contained in:
xiabin 2025-01-20 18:20:25 +08:00
parent 22ec38db77
commit 38c3b17952
10 changed files with 72 additions and 14 deletions

View File

@ -2,7 +2,7 @@ syntax = "v1"
import "common.api"
type DouyinCode2UserIdRequest {
type DouyinCode2TokenRequest {
AppId string `form:"appId"`
Code string `form:"code,optional"`
AnonymousCode string `form:"anonymousCode,optional"`
@ -17,8 +17,8 @@ type DouyinCode2UserIdRequest {
service game_open_api-api {
@handler douyinCode2UserId
get /code2userId (DouyinCode2UserIdRequest) returns (Auth)
@handler douyinCode2token
get /code2token (DouyinCode2TokenRequest) returns (Auth)
}

View File

@ -11,7 +11,7 @@ import (
func DouyinCode2UserIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DouyinCode2UserIdRequest
var req types.DouyinCode2TokenRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return

View File

@ -0,0 +1,28 @@
package douyin
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"youtu_server/game_open_api/internal/logic/douyin"
"youtu_server/game_open_api/internal/svc"
"youtu_server/game_open_api/internal/types"
)
func DouyinCode2tokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DouyinCode2TokenRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := douyin.NewDouyinCode2tokenLogic(r.Context(), svcCtx)
resp, err := l.DouyinCode2token(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -35,8 +35,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/code2userId",
Handler: douyin.DouyinCode2UserIdHandler(serverCtx),
Path: "/code2token",
Handler: douyin.DouyinCode2tokenHandler(serverCtx),
},
},
rest.WithPrefix("/v1/douyin"),
@ -81,7 +81,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/code2userId",
Path: "/code2token",
Handler: wechat.WechatCode2UserIdHandler(serverCtx),
},
},

View File

@ -11,7 +11,7 @@ import (
func WechatCode2UserIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.WechatCode2UserIdRequest
var req types.WechatCode2TokenRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return

View File

@ -28,7 +28,7 @@ func NewDouyinCode2UserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *DouyinCode2UserIdLogic) DouyinCode2UserId(req *types.DouyinCode2UserIdRequest) (resp *types.Auth, err error) {
func (l *DouyinCode2UserIdLogic) DouyinCode2UserId(req *types.DouyinCode2TokenRequest) (resp *types.Auth, err error) {
resp = new(types.Auth)
douyinCli, err := app_api_helper.DouyinCli.GetDouYinOpenApi(req.AppId)

View File

@ -0,0 +1,30 @@
package douyin
import (
"context"
"youtu_server/game_open_api/internal/svc"
"youtu_server/game_open_api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DouyinCode2tokenLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDouyinCode2tokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DouyinCode2tokenLogic {
return &DouyinCode2tokenLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DouyinCode2tokenLogic) DouyinCode2token(req *types.DouyinCode2TokenRequest) (resp *types.Auth, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -29,7 +29,7 @@ func NewWechatCode2UserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *WechatCode2UserIdLogic) WechatCode2UserId(req *types.WechatCode2UserIdRequest) (resp *types.Auth, err error) {
func (l *WechatCode2UserIdLogic) WechatCode2UserId(req *types.WechatCode2TokenRequest) (resp *types.Auth, err error) {
resp = new(types.Auth)
wechatCli, err := app_api_helper.WechatCli.GetWechatOpenApi(req.AppId)
if err != nil {

View File

@ -13,7 +13,7 @@ type Base struct {
Message string `json:"message,omitempty"`
}
type DouyinCode2UserIdRequest struct {
type DouyinCode2TokenRequest struct {
AppId string `form:"appId"`
Code string `form:"code,optional"`
AnonymousCode string `form:"anonymousCode,optional"`
@ -41,7 +41,7 @@ type UserId struct {
UserId uint64 `json:"userId"`
}
type WechatCode2UserIdRequest struct {
type WechatCode2TokenRequest struct {
AppId string `form:"appId"`
Code string `form:"code"`
}

View File

@ -3,7 +3,7 @@ syntax = "v1"
import "common.api"
type WechatCode2UserIdRequest {
type WechatCode2TokenRequest {
AppId string `form:"appId"`
Code string `form:"code"`
}
@ -18,6 +18,6 @@ type WechatCode2UserIdRequest {
service game_open_api-api {
@handler wechatCode2UserId
get /code2userId (WechatCode2UserIdRequest) returns (Auth )
get /code2token (WechatCode2TokenRequest) returns (Auth )
}