作者 tangxuhui

更新

@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
13 ) 14 )
14 15
15 // 组织管理 16 // 组织管理
@@ -26,6 +27,7 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{ @@ -26,6 +27,7 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{
26 case "signInPassword": 27 case "signInPassword":
27 result, err = srv.SignInPassword(loginCommand.Phone, loginCommand.Password) 28 result, err = srv.SignInPassword(loginCommand.Phone, loginCommand.Password)
28 case "signInCaptcha": 29 case "signInCaptcha":
  30 + result, err = srv.SignInCaptcha(loginCommand.Phone, loginCommand.Captcha)
29 default: 31 default:
30 err = errors.New("登录方式无法解析") 32 err = errors.New("登录方式无法解析")
31 } 33 }
@@ -60,7 +62,25 @@ func (srv AuthService) SignInPassword(account string, password string) (interfac @@ -60,7 +62,25 @@ func (srv AuthService) SignInPassword(account string, password string) (interfac
60 62
61 //SignInCaptcha 使用手机验证码登录 63 //SignInCaptcha 使用手机验证码登录
62 func (srv AuthService) SignInCaptcha(phone string, captcha string) (interface{}, error) { 64 func (srv AuthService) SignInCaptcha(phone string, captcha string) (interface{}, error) {
63 - return nil, nil 65 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  66 + err := smsServeGateway.CheckSmsCode(phone, captcha)
  67 + if err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + ltoken := domain.LoginToken{
  71 + UserId: 0,
  72 + Account: phone,
  73 + Platform: domain.LoginPlatformApp,
  74 + CompanyId: 0,
  75 + }
  76 + authcode, err := ltoken.GenerateAuthCode()
  77 + if err != nil {
  78 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  79 + }
  80 + result := map[string]string{
  81 + "authCode": authcode,
  82 + }
  83 + return result, nil
64 } 84 }
65 85
66 //GetAuthAccessToken 获取令牌Token 86 //GetAuthAccessToken 获取令牌Token
@@ -153,7 +173,7 @@ loopUser1: @@ -153,7 +173,7 @@ loopUser1:
153 } 173 }
154 } 174 }
155 } 175 }
156 - //TODO 176 +
157 loginToken := domain.LoginToken{ 177 loginToken := domain.LoginToken{
158 UserId: currentAccess.UserId, 178 UserId: currentAccess.UserId,
159 Account: currentAccess.Account, 179 Account: currentAccess.Account,
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type SendSmsCodeCommand struct {
  10 + Phone string `json:"phone" valid:"Required"`
  11 +}
  12 +
  13 +func (orgAddCommand *SendSmsCodeCommand) Valid(validation *validation.Validation) {
  14 +
  15 +}
  16 +
  17 +func (orgAddCommand *SendSmsCodeCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(orgAddCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
1 package service 1 package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
  7 +)
  8 +
  9 +type UserService struct {
  10 +}
  11 +
  12 +//SendSmsCaptcha 发送验证码短信
  13 +func (srv UserService) SendSmsCaptcha(smsCodeCommand *command.SendSmsCodeCommand) error {
  14 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  15 + err := smsServeGateway.SendSms(smsCodeCommand.Phone)
  16 + if err != nil {
  17 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  18 + }
  19 + return nil
  20 +}
@@ -44,7 +44,7 @@ func (menuService *MenuService) MenuList(menuListQuery *query.MenuListQuery) (in @@ -44,7 +44,7 @@ func (menuService *MenuService) MenuList(menuListQuery *query.MenuListQuery) (in
44 }, nil 44 }, nil
45 } 45 }
46 46
47 -// 更新菜单 47 +// 更新自定义菜单
48 func (menuService *MenuService) MenuUpdate(menuUpdateCommand *command.MenuUpdateCommand) (interface{}, error) { 48 func (menuService *MenuService) MenuUpdate(menuUpdateCommand *command.MenuUpdateCommand) (interface{}, error) {
49 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( 49 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
50 menuUpdateCommand.Operator.CompanyId, 50 menuUpdateCommand.Operator.CompanyId,
@@ -6,10 +6,15 @@ const SERVICE_NAME = "project" @@ -6,10 +6,15 @@ const SERVICE_NAME = "project"
6 6
7 var LOG_LEVEL = "debug" 7 var LOG_LEVEL = "debug"
8 8
  9 +//天联共创基础模块
9 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" 10 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
10 11
  12 +//天联共创用户模块
11 var ALLIED_CREATION_USER_HOST = "http://localhost:8081" 13 var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
12 14
  15 +//通用模块短信服务
  16 +var SMS_SERVE_HOST = "http://localhost:8081"
  17 +
13 func init() { 18 func init() {
14 if os.Getenv("LOG_LEVEL") != "" { 19 if os.Getenv("LOG_LEVEL") != "" {
15 LOG_LEVEL = os.Getenv("LOG_LEVEL") 20 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -73,7 +73,7 @@ func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*Dat @@ -73,7 +73,7 @@ func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*Dat
73 73
74 // MenusRemove 移除菜单 74 // MenusRemove 移除菜单
75 func (gateway HttplibAlliedCreationUser) MenusRemove(param ReqMenusRemove) (*DataMenusRemove, error) { 75 func (gateway HttplibAlliedCreationUser) MenusRemove(param ReqMenusRemove) (*DataMenusRemove, error) {
76 - url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.RoleId, 10) 76 + url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenuId, 10)
77 method := "delete" 77 method := "delete"
78 req := gateway.CreateRequest(url, method) 78 req := gateway.CreateRequest(url, method)
79 log.Logger.Debug("向用户模块请求数据:移除菜单。", map[string]interface{}{ 79 log.Logger.Debug("向用户模块请求数据:移除菜单。", map[string]interface{}{
@@ -3,7 +3,7 @@ package allied_creation_user @@ -3,7 +3,7 @@ package allied_creation_user
3 //更新我喜欢菜单列表 3 //更新我喜欢菜单列表
4 type ( 4 type (
5 ReqFavoriteMenusUpdate struct { 5 ReqFavoriteMenusUpdate struct {
6 - UserId int64 6 + UserId int64 `json:"userId"`
7 } 7 }
8 8
9 DataFavoriteMenusUpdate struct { 9 DataFavoriteMenusUpdate struct {
@@ -13,8 +13,8 @@ type ( @@ -13,8 +13,8 @@ type (
13 //移除我收藏的菜单 13 //移除我收藏的菜单
14 type ( 14 type (
15 ReqFavoriteMenusRemove struct { 15 ReqFavoriteMenusRemove struct {
16 - UserId int64  
17 - MenuCode string 16 + UserId int64 `json:"userId"`
  17 + MenuCode string `json:"menuCode"`
18 } 18 }
19 19
20 DataFavoriteMenusRemove struct { 20 DataFavoriteMenusRemove struct {
@@ -24,7 +24,7 @@ type ( @@ -24,7 +24,7 @@ type (
24 //获取我收藏的菜单 24 //获取我收藏的菜单
25 type ( 25 type (
26 ReqFavoriteMenusGet struct { 26 ReqFavoriteMenusGet struct {
27 - UserId int64 27 + UserId int64 `json:"userId"`
28 } 28 }
29 29
30 DataFavoriteMenusGet struct { 30 DataFavoriteMenusGet struct {
@@ -12,7 +12,7 @@ type ( @@ -12,7 +12,7 @@ type (
12 //更新菜单 12 //更新菜单
13 type ( 13 type (
14 ReqMenusUpdate struct { 14 ReqMenusUpdate struct {
15 - MenusId int64 15 + MenusId int64 `json:"menusId"`
16 } 16 }
17 17
18 DataMenusUpdate struct { 18 DataMenusUpdate struct {
@@ -22,7 +22,7 @@ type ( @@ -22,7 +22,7 @@ type (
22 //移除菜单 22 //移除菜单
23 type ( 23 type (
24 ReqMenusRemove struct { 24 ReqMenusRemove struct {
25 - RoleId int64 25 + MenuId int64 `json:"roleId"`
26 } 26 }
27 27
28 DataMenusRemove struct { 28 DataMenusRemove struct {
@@ -32,7 +32,7 @@ type ( @@ -32,7 +32,7 @@ type (
32 //返回菜单 32 //返回菜单
33 type ( 33 type (
34 ReqMenusGet struct { 34 ReqMenusGet struct {
35 - MenuId int64 35 + MenuId int64 `json:"menuId"`
36 } 36 }
37 37
38 DataMenusGet struct { 38 DataMenusGet struct {
@@ -36,7 +36,7 @@ type ( @@ -36,7 +36,7 @@ type (
36 //移除组织 36 //移除组织
37 type ( 37 type (
38 ReqOrgRemove struct { 38 ReqOrgRemove struct {
39 - OrgId int64 39 + OrgId int64 `json:"orgId"`
40 } 40 }
41 41
42 DataOrgRemove struct { 42 DataOrgRemove struct {
@@ -36,7 +36,7 @@ type ( @@ -36,7 +36,7 @@ type (
36 } 36 }
37 37
38 DataRoleSearch struct { 38 DataRoleSearch struct {
39 - Count int64 39 + Count int64 `json:"count"`
40 Roles []struct { 40 Roles []struct {
41 AccessMenus []Int64String `json:"accessMenus"` 41 AccessMenus []Int64String `json:"accessMenus"`
42 CompanyID Int64String `json:"companyId"` 42 CompanyID Int64String `json:"companyId"`
@@ -87,8 +87,8 @@ type ( @@ -87,8 +87,8 @@ type (
87 //分配角色给多个用户 87 //分配角色给多个用户
88 type ( 88 type (
89 ReqRoleAssign struct { 89 ReqRoleAssign struct {
90 - RoleId int64  
91 - UserIds []int64 90 + RoleId int64 `json:"roleId"`
  91 + UserIds []int64 `json:"userIds"`
92 } 92 }
93 93
94 DataRoleAssign struct { 94 DataRoleAssign struct {
  1 +package sms_serve
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "time"
  7 +
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
  12 +)
  13 +
  14 +//公共短信服务模块
  15 +type HttplibSmsServe struct {
  16 + service_gateway.BaseServiceGateway
  17 + baseUrL string
  18 +}
  19 +
  20 +func NewHttplibHttplibSmsServe() *HttplibSmsServe {
  21 + return &HttplibSmsServe{
  22 + BaseServiceGateway: service_gateway.BaseServiceGateway{
  23 + ConnectTimeout: 100 * time.Second,
  24 + ReadWriteTimeout: 30 * time.Second,
  25 + },
  26 + baseUrL: constant.ALLIED_CREATION_USER_HOST,
  27 + }
  28 +
  29 +}
  30 +
  31 +//SendSms 公共短信验证码服务 发送验证码
  32 +func (smsServe HttplibSmsServe) SendSms(phone string) error {
  33 + url := smsServe.baseUrL + "/service/sendSms"
  34 + method := "post"
  35 + req := smsServe.CreateRequest(url, method)
  36 + param := map[string]string{
  37 + "phone": phone,
  38 + }
  39 + log.Logger.Debug("向公共短信验证码服务请求数据:短信验证码接口。", map[string]interface{}{
  40 + "api": method + ":" + url,
  41 + "param": param,
  42 + })
  43 + req, err := req.JSONBody(param)
  44 + if err != nil {
  45 + return fmt.Errorf("请求公共短信验证码服务失败:%w", err)
  46 + }
  47 +
  48 + byteResult, err := req.Bytes()
  49 + if err != nil {
  50 + return fmt.Errorf("获取公共短信验证码服务失败:%w", err)
  51 + }
  52 + log.Logger.Debug("获取公共短信验证码服务请求数据", map[string]interface{}{
  53 + "result": string(byteResult),
  54 + })
  55 + var result service_gateway.GatewayResponse
  56 + err = json.Unmarshal(byteResult, &result)
  57 + if err != nil {
  58 + return fmt.Errorf("解析更新组织:%w", err)
  59 + }
  60 + if result.Code != 0 {
  61 + return fmt.Errorf(result.Msg)
  62 + }
  63 + return nil
  64 +}
  65 +
  66 +//CheckSmsCode 公共短信验证码服务 校验验证码
  67 +func (smsServe HttplibSmsServe) CheckSmsCode(phone string, code string) error {
  68 + url := smsServe.baseUrL + "/service/sendSms"
  69 + method := "post"
  70 + req := smsServe.CreateRequest(url, method)
  71 + param := map[string]string{
  72 + "phone": phone,
  73 + "code": code,
  74 + }
  75 + log.Logger.Debug("向公共短信验证码服务请求数据:短信验证码接口。", map[string]interface{}{
  76 + "api": method + ":" + url,
  77 + "param": param,
  78 + })
  79 + req, err := req.JSONBody(param)
  80 + if err != nil {
  81 + return fmt.Errorf("请求公共短信验证码服务失败:%w", err)
  82 + }
  83 +
  84 + byteResult, err := req.Bytes()
  85 + if err != nil {
  86 + return fmt.Errorf("获取公共短信验证码服务失败:%w", err)
  87 + }
  88 + log.Logger.Debug("获取公共短信验证码服务请求数据", map[string]interface{}{
  89 + "result": string(byteResult),
  90 + })
  91 + var result service_gateway.GatewayResponse
  92 + err = json.Unmarshal(byteResult, &result)
  93 + if err != nil {
  94 + return fmt.Errorf("解析更新组织:%w", err)
  95 + }
  96 + if result.Code != 0 {
  97 + return fmt.Errorf(result.Msg)
  98 + }
  99 + return nil
  100 +}
  1 +package mobile_client
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/service"
  6 +)
  7 +
  8 +type UserController struct {
  9 + baseController
  10 +}
  11 +
  12 +func (controller *UserController) SendSmsCode() {
  13 + authService := service.UserService{}
  14 + smsCodeCmd := &command.SendSmsCodeCommand{}
  15 + err := controller.Unmarshal(smsCodeCmd)
  16 + if err != nil {
  17 + controller.Response(nil, err)
  18 + return
  19 + }
  20 + err = authService.SendSmsCaptcha(smsCodeCmd)
  21 + controller.Response(nil, err)
  22 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/v1/app/users/smsCode", &mobile_client.UserController{}, "Post:SendSmsCode")
  10 +}