By Robin at 20240615

This commit is contained in:
Leufolium 2024-06-15 11:41:12 +08:00
parent 3cf7e543fd
commit f73dd1cff7
13 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,4 @@
package request
type HYG10000001Req struct {
}

View File

@ -0,0 +1 @@
package request

View File

@ -0,0 +1 @@
package request

View File

@ -0,0 +1 @@
package response

View File

@ -0,0 +1 @@
package response

View File

@ -0,0 +1 @@
package response

View File

@ -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],
})
}

View File

@ -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"`
}

View File

@ -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"`
}

View File

@ -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)
}

View File

@ -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())

View File

@ -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

View File

@ -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