From f73dd1cff7f49fb8a5b2e32f28f348859502245d Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sat, 15 Jun 2024 11:41:12 +0800 Subject: [PATCH] By Robin at 20240615 --- api/message/request/HYG10000001Req.go | 4 ++ api/message/request/HYG10000002Req.go | 1 + api/message/request/HYG10010001Req.go | 1 + api/message/response/HYG10000001Resp.go | 1 + api/message/response/HYG10000002Resp.go | 1 + api/message/response/HYG10010001Resp.go | 1 + api/message/response/HYGBaseResponse.go | 45 +++++++++++++++++++++++ api/proto/account/proto/account_api.go | 14 +++++++ api/proto/account/proto/account_vo_api.go | 7 ++++ app/mix/controller/account_api.go | 26 +++++++++++++ app/mix/controller/init.go | 1 + app/mix/service/apiservice.go | 27 ++++++++++++++ app/mix/service/service.go | 45 +++++++++++++++++++++++ 13 files changed, 174 insertions(+) create mode 100644 api/message/request/HYG10000001Req.go create mode 100644 api/message/request/HYG10000002Req.go create mode 100644 api/message/request/HYG10010001Req.go create mode 100644 api/message/response/HYG10000001Resp.go create mode 100644 api/message/response/HYG10000002Resp.go create mode 100644 api/message/response/HYG10010001Resp.go create mode 100644 api/message/response/HYGBaseResponse.go diff --git a/api/message/request/HYG10000001Req.go b/api/message/request/HYG10000001Req.go new file mode 100644 index 00000000..b138ec1d --- /dev/null +++ b/api/message/request/HYG10000001Req.go @@ -0,0 +1,4 @@ +package request + +type HYG10000001Req struct { +} diff --git a/api/message/request/HYG10000002Req.go b/api/message/request/HYG10000002Req.go new file mode 100644 index 00000000..725b8fc2 --- /dev/null +++ b/api/message/request/HYG10000002Req.go @@ -0,0 +1 @@ +package request diff --git a/api/message/request/HYG10010001Req.go b/api/message/request/HYG10010001Req.go new file mode 100644 index 00000000..725b8fc2 --- /dev/null +++ b/api/message/request/HYG10010001Req.go @@ -0,0 +1 @@ +package request diff --git a/api/message/response/HYG10000001Resp.go b/api/message/response/HYG10000001Resp.go new file mode 100644 index 00000000..a467149d --- /dev/null +++ b/api/message/response/HYG10000001Resp.go @@ -0,0 +1 @@ +package response diff --git a/api/message/response/HYG10000002Resp.go b/api/message/response/HYG10000002Resp.go new file mode 100644 index 00000000..a467149d --- /dev/null +++ b/api/message/response/HYG10000002Resp.go @@ -0,0 +1 @@ +package response diff --git a/api/message/response/HYG10010001Resp.go b/api/message/response/HYG10010001Resp.go new file mode 100644 index 00000000..a467149d --- /dev/null +++ b/api/message/response/HYG10010001Resp.go @@ -0,0 +1 @@ +package response diff --git a/api/message/response/HYGBaseResponse.go b/api/message/response/HYGBaseResponse.go new file mode 100644 index 00000000..6c05ccf3 --- /dev/null +++ b/api/message/response/HYGBaseResponse.go @@ -0,0 +1,45 @@ +package response + +import ( + "net/http" + "service/api/errcode" + + "github.com/gin-gonic/gin" +) + +const ( + StatusCodeSuccess = "000000" + StatusCodeFail = "999999" +) + +const ( + MsgSuccess = "业务成功" +) + +type HygBaseResponse struct { + StatusCode string `json:"statusCode"` + StatusText string `json:"statusText"` + Data any `json:"data"` +} + +func ReplyOk(ctx *gin.Context, data any) { + ctx.JSON(http.StatusOK, HygBaseResponse{ + StatusCode: StatusCodeSuccess, + StatusText: MsgSuccess, + Data: data, + }) +} + +func ReplyErrorMsg(ctx *gin.Context, msg string) { + ctx.AbortWithStatusJSON(http.StatusOK, HygBaseResponse{ + StatusCode: StatusCodeFail, + StatusText: msg, + }) +} + +func ReplyErrCodeMsg(ctx *gin.Context, ec errcode.ErrCode) { + ctx.AbortWithStatusJSON(http.StatusOK, HygBaseResponse{ + StatusCode: StatusCodeFail, + StatusText: errcode.ErrCodeMsgMap[ec], + }) +} diff --git a/api/proto/account/proto/account_api.go b/api/proto/account/proto/account_api.go index 22d742ff..18dc1951 100644 --- a/api/proto/account/proto/account_api.go +++ b/api/proto/account/proto/account_api.go @@ -206,3 +206,17 @@ type ApiAbortCancellationResp struct { base.BaseResponse Data *ApiAbortCancellationData `json:"data"` } + +// api 列表-查询手机号 +type ApiGetMobilePhoneReq struct { + Token string `json:"token"` // token +} + +type ApiGetMobilePhoneData struct { + Data *ApiGetMobilePhoneVO `json:"data"` +} + +type ApiGetMobilePhoneResp struct { + base.BaseResponse + Data *ApiGetMobilePhoneResp `json:"data"` +} diff --git a/api/proto/account/proto/account_vo_api.go b/api/proto/account/proto/account_vo_api.go index 8ff5c498..ece69bd1 100644 --- a/api/proto/account/proto/account_vo_api.go +++ b/api/proto/account/proto/account_vo_api.go @@ -74,3 +74,10 @@ func (vo *ApiListOthersVO) CopyAccount(account *dbstruct.Account) *ApiListOthers vo.Role = account.Role return vo } + +// 查询手机号vo +type ApiGetMobilePhoneVO struct { + WorkerMobile string `json:"workerMobile" bcrypto:"aes_cbc"` + WorkerName string `json:"workerName"` + IdCard string `json:"idCard"` +} diff --git a/app/mix/controller/account_api.go b/app/mix/controller/account_api.go index 328442e2..9aa11d8c 100644 --- a/app/mix/controller/account_api.go +++ b/app/mix/controller/account_api.go @@ -3,6 +3,7 @@ package controller import ( "service/api/consts" "service/api/errcode" + "service/api/message/response" accountproto "service/api/proto/account/proto" "service/app/mix/service" "service/bizcommon/util" @@ -207,3 +208,28 @@ func ApiAbortAccountCancellation(ctx *gin.Context) { ReplyOk(ctx, nil) } + +func ApiGetMobilePhone(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountproto.ApiGetMobilePhoneReq) + + // 验证token + mid, err := service.DefaultService.OpParseToken(ctx, req.Token) + if err != nil { + logger.Error("OpParseToken fail, req: %v, err: %v", util.ToJson(req), err) + response.ReplyErrorMsg(ctx, "Token解析失败") + return + } + + vo, ec := service.DefaultService.ApiGetMobilePhoneByMid(ctx, mid) + if ec != errcode.ErrCodeAccountSrvOk { + logger.Error("ApiGetMobilePhoneByMid fail, req: %v, ec: %v", util.ToJson(req), ec) + response.ReplyErrCodeMsg(ctx, ec) + return + } + + data := &accountproto.ApiGetMobilePhoneData{ + Data: vo, + } + + response.ReplyOk(ctx, data) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index f27a5bcf..1ea583b6 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -91,6 +91,7 @@ func Init(r *gin.Engine) { apiAccountGroup.POST("exp_inc", middleware.JSONParamValidator(accountproto.ApiExpIncReq{}), middleware.JwtAuthenticator(), ApiAccountExpInc) apiAccountGroup.POST("cancel", middleware.JSONParamValidator(accountproto.ApiCancelReq{}), middleware.JwtAuthenticator(), ApiCancelAccount) apiAccountGroup.POST("abort_cancellation", middleware.JSONParamValidator(accountproto.ApiAbortCancellationReq{}), middleware.JwtAuthenticator(), ApiAbortAccountCancellation) + apiAccountGroup.POST("get_mobile_phone", middleware.JSONParamValidator(accountproto.ApiGetMobilePhoneReq{}), ApiGetMobilePhone) // 用户关系,用户端支持增删查,不支持改 apiAccountRelationGroup := r.Group("/api/account_relation", PrepareToC()) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 44639a43..a4c1160d 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -37,6 +37,7 @@ import ( "service/dbstruct" "service/library/apollo" "service/library/logger" + interceptor "service/library/taginterceptor" "time" "go.mongodb.org/mongo-driver/mongo" @@ -703,6 +704,32 @@ func (s *Service) ApiAbortAccountCancellation(ctx *gin.Context, req *accountprot } +func (s *Service) ApiGetMobilePhoneByMid(ctx *gin.Context, mid int64) (vo *accountproto.ApiGetMobilePhoneVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountSrvOk + + vo = &accountproto.ApiGetMobilePhoneVO{} + + account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{ + Mid: goproto.Int64(mid), + }) + if err != nil { + logger.Error("OpListByMid fail, err: %v", err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + vo.WorkerMobile = util.DerefString(account.MobilePhone) + + err = interceptor.DecryptTagInterceptorInstance().Intercept(vo, "bcrypto") + if err != nil { + logger.Error("Account decryption err : %v", err) + ec = errcode.ErrCodeDecryptionInterceptFail + return + } + + return +} + // AccountRelation func (s *Service) ApiCreateAccountRelation(ctx *gin.Context, req *accountrelationproto.ApiCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeAccountRelationSrvOk diff --git a/app/mix/service/service.go b/app/mix/service/service.go index f853d2e9..93468f13 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -59,6 +59,7 @@ import ( "service/library/payclients/alipaycli" "service/library/payclients/wxpaycli" "service/library/redis" + "strconv" "strings" "time" @@ -70,6 +71,7 @@ import ( //"service/library/melody" "github.com/gin-gonic/gin" + "github.com/golang-jwt/jwt/v5" "github.com/qiniu/qmgo" ) @@ -1002,6 +1004,49 @@ func (s *Service) OpVerifyToken(ctx *gin.Context, token string) (err error) { return } +func (s *Service) OpParseToken(ctx *gin.Context, tokenString string) (mid int64, err error) { + // 是否携带令牌 + if tokenString == "" { + logger.Error("Missing auth token") + return -1, fmt.Errorf("missing auth token") + } + + // 检查令牌加密方法及签名 + token, err := _DefaultToken.OpVerifyCrypto(ctx, tokenString) + if err != nil { + logger.Error("failed to verify crypto of the token") + return -1, fmt.Errorf("failed to verify crypto of the token") + } + + // 检查token是否可用 + claims, ok := token.Claims.(jwt.MapClaims) + if !ok { + return -1, fmt.Errorf("token type assertion failed") + } + if !token.Valid { + return -1, fmt.Errorf("token is invalid") + } + + // 检查token是否还有效 + tokenUuid, err := strconv.ParseInt(fmt.Sprintf("%.f", claims["token_uuid"]), 10, 64) + if err != nil { + return -1, fmt.Errorf("failed to acquire token_uuid from token") + } + + // 解析mid + list, err := _DefaultToken.OpList(ctx, &tokenproto.OpListReq{ + Id: tokenUuid, + }) + if err != nil { + return -1, fmt.Errorf("error occured when finding the token") + } + if len(list) == 0 { + return -1, fmt.Errorf("failed to find the token") + } + + return list[0].Mid, nil +} + // Vas func (s *Service) GetCoinsProductList(ctx *gin.Context, req *vasproto.GetCoinsProductListReq) (data *vasproto.GetCoinsProductListData, ec errcode.ErrCode) { ec = errcode.ErrCodeVasSrvOk