diff --git a/game_open_api/douyin.api b/game_open_api/douyin.api index bb8322c..3baf49b 100644 --- a/game_open_api/douyin.api +++ b/game_open_api/douyin.api @@ -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) } diff --git a/game_open_api/internal/handler/douyin/douyinCode2UserIdHandler.go b/game_open_api/internal/handler/douyin/douyinCode2UserIdHandler.go index 4f45729..d1597c8 100644 --- a/game_open_api/internal/handler/douyin/douyinCode2UserIdHandler.go +++ b/game_open_api/internal/handler/douyin/douyinCode2UserIdHandler.go @@ -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 diff --git a/game_open_api/internal/handler/douyin/douyinCode2tokenHandler.go b/game_open_api/internal/handler/douyin/douyinCode2tokenHandler.go new file mode 100644 index 0000000..04ac5df --- /dev/null +++ b/game_open_api/internal/handler/douyin/douyinCode2tokenHandler.go @@ -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) + } + } +} diff --git a/game_open_api/internal/handler/routes.go b/game_open_api/internal/handler/routes.go index 80c2ab5..695c29d 100644 --- a/game_open_api/internal/handler/routes.go +++ b/game_open_api/internal/handler/routes.go @@ -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), }, }, diff --git a/game_open_api/internal/handler/wechat/wechatCode2UserIdHandler.go b/game_open_api/internal/handler/wechat/wechatCode2UserIdHandler.go index 027a889..1464584 100644 --- a/game_open_api/internal/handler/wechat/wechatCode2UserIdHandler.go +++ b/game_open_api/internal/handler/wechat/wechatCode2UserIdHandler.go @@ -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 diff --git a/game_open_api/internal/logic/douyin/douyinCode2UserIdLogic.go b/game_open_api/internal/logic/douyin/douyinCode2UserIdLogic.go index 5029241..c361295 100644 --- a/game_open_api/internal/logic/douyin/douyinCode2UserIdLogic.go +++ b/game_open_api/internal/logic/douyin/douyinCode2UserIdLogic.go @@ -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) diff --git a/game_open_api/internal/logic/douyin/douyinCode2tokenLogic.go b/game_open_api/internal/logic/douyin/douyinCode2tokenLogic.go new file mode 100644 index 0000000..b835d1c --- /dev/null +++ b/game_open_api/internal/logic/douyin/douyinCode2tokenLogic.go @@ -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 +} diff --git a/game_open_api/internal/logic/wechat/wechatCode2UserIdLogic.go b/game_open_api/internal/logic/wechat/wechatCode2UserIdLogic.go index 7a826ca..83c4054 100644 --- a/game_open_api/internal/logic/wechat/wechatCode2UserIdLogic.go +++ b/game_open_api/internal/logic/wechat/wechatCode2UserIdLogic.go @@ -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 { diff --git a/game_open_api/internal/types/types.go b/game_open_api/internal/types/types.go index 31d6c5b..0bac83f 100644 --- a/game_open_api/internal/types/types.go +++ b/game_open_api/internal/types/types.go @@ -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"` } diff --git a/game_open_api/wechat.api b/game_open_api/wechat.api index 8d59a84..8db5c37 100644 --- a/game_open_api/wechat.api +++ b/game_open_api/wechat.api @@ -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 ) }