作者 tangxuhui

更新

... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
)
// 组织管理
... ... @@ -26,6 +27,7 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{
case "signInPassword":
result, err = srv.SignInPassword(loginCommand.Phone, loginCommand.Password)
case "signInCaptcha":
result, err = srv.SignInCaptcha(loginCommand.Phone, loginCommand.Captcha)
default:
err = errors.New("登录方式无法解析")
}
... ... @@ -60,7 +62,25 @@ func (srv AuthService) SignInPassword(account string, password string) (interfac
//SignInCaptcha 使用手机验证码登录
func (srv AuthService) SignInCaptcha(phone string, captcha string) (interface{}, error) {
return nil, nil
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
err := smsServeGateway.CheckSmsCode(phone, captcha)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
ltoken := domain.LoginToken{
UserId: 0,
Account: phone,
Platform: domain.LoginPlatformApp,
CompanyId: 0,
}
authcode, err := ltoken.GenerateAuthCode()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := map[string]string{
"authCode": authcode,
}
return result, nil
}
//GetAuthAccessToken 获取令牌Token
... ... @@ -153,7 +173,7 @@ loopUser1:
}
}
}
//TODO
loginToken := domain.LoginToken{
UserId: currentAccess.UserId,
Account: currentAccess.Account,
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type SendSmsCodeCommand struct {
Phone string `json:"phone" valid:"Required"`
}
func (orgAddCommand *SendSmsCodeCommand) Valid(validation *validation.Validation) {
}
func (orgAddCommand *SendSmsCodeCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
)
type UserService struct {
}
//SendSmsCaptcha 发送验证码短信
func (srv UserService) SendSmsCaptcha(smsCodeCommand *command.SendSmsCodeCommand) error {
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
err := smsServeGateway.SendSms(smsCodeCommand.Phone)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -44,7 +44,7 @@ func (menuService *MenuService) MenuList(menuListQuery *query.MenuListQuery) (in
}, nil
}
// 更新菜单
// 更新自定义菜单
func (menuService *MenuService) MenuUpdate(menuUpdateCommand *command.MenuUpdateCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
menuUpdateCommand.Operator.CompanyId,
... ...
... ... @@ -6,10 +6,15 @@ const SERVICE_NAME = "project"
var LOG_LEVEL = "debug"
//天联共创基础模块
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
//天联共创用户模块
var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
//通用模块短信服务
var SMS_SERVE_HOST = "http://localhost:8081"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
... ...
... ... @@ -73,7 +73,7 @@ func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*Dat
// MenusRemove 移除菜单
func (gateway HttplibAlliedCreationUser) MenusRemove(param ReqMenusRemove) (*DataMenusRemove, error) {
url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.RoleId, 10)
url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenuId, 10)
method := "delete"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:移除菜单。", map[string]interface{}{
... ...
... ... @@ -3,7 +3,7 @@ package allied_creation_user
//更新我喜欢菜单列表
type (
ReqFavoriteMenusUpdate struct {
UserId int64
UserId int64 `json:"userId"`
}
DataFavoriteMenusUpdate struct {
... ... @@ -13,8 +13,8 @@ type (
//移除我收藏的菜单
type (
ReqFavoriteMenusRemove struct {
UserId int64
MenuCode string
UserId int64 `json:"userId"`
MenuCode string `json:"menuCode"`
}
DataFavoriteMenusRemove struct {
... ... @@ -24,7 +24,7 @@ type (
//获取我收藏的菜单
type (
ReqFavoriteMenusGet struct {
UserId int64
UserId int64 `json:"userId"`
}
DataFavoriteMenusGet struct {
... ...
... ... @@ -12,7 +12,7 @@ type (
//更新菜单
type (
ReqMenusUpdate struct {
MenusId int64
MenusId int64 `json:"menusId"`
}
DataMenusUpdate struct {
... ... @@ -22,7 +22,7 @@ type (
//移除菜单
type (
ReqMenusRemove struct {
RoleId int64
MenuId int64 `json:"roleId"`
}
DataMenusRemove struct {
... ... @@ -32,7 +32,7 @@ type (
//返回菜单
type (
ReqMenusGet struct {
MenuId int64
MenuId int64 `json:"menuId"`
}
DataMenusGet struct {
... ...
... ... @@ -36,7 +36,7 @@ type (
//移除组织
type (
ReqOrgRemove struct {
OrgId int64
OrgId int64 `json:"orgId"`
}
DataOrgRemove struct {
... ...
... ... @@ -36,7 +36,7 @@ type (
}
DataRoleSearch struct {
Count int64
Count int64 `json:"count"`
Roles []struct {
AccessMenus []Int64String `json:"accessMenus"`
CompanyID Int64String `json:"companyId"`
... ... @@ -87,8 +87,8 @@ type (
//分配角色给多个用户
type (
ReqRoleAssign struct {
RoleId int64
UserIds []int64
RoleId int64 `json:"roleId"`
UserIds []int64 `json:"userIds"`
}
DataRoleAssign struct {
... ...
package sms_serve
import (
"encoding/json"
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
)
//公共短信服务模块
type HttplibSmsServe struct {
service_gateway.BaseServiceGateway
baseUrL string
}
func NewHttplibHttplibSmsServe() *HttplibSmsServe {
return &HttplibSmsServe{
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
baseUrL: constant.ALLIED_CREATION_USER_HOST,
}
}
//SendSms 公共短信验证码服务 发送验证码
func (smsServe HttplibSmsServe) SendSms(phone string) error {
url := smsServe.baseUrL + "/service/sendSms"
method := "post"
req := smsServe.CreateRequest(url, method)
param := map[string]string{
"phone": phone,
}
log.Logger.Debug("向公共短信验证码服务请求数据:短信验证码接口。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return fmt.Errorf("请求公共短信验证码服务失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return fmt.Errorf("获取公共短信验证码服务失败:%w", err)
}
log.Logger.Debug("获取公共短信验证码服务请求数据", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return fmt.Errorf("解析更新组织:%w", err)
}
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
return nil
}
//CheckSmsCode 公共短信验证码服务 校验验证码
func (smsServe HttplibSmsServe) CheckSmsCode(phone string, code string) error {
url := smsServe.baseUrL + "/service/sendSms"
method := "post"
req := smsServe.CreateRequest(url, method)
param := map[string]string{
"phone": phone,
"code": code,
}
log.Logger.Debug("向公共短信验证码服务请求数据:短信验证码接口。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return fmt.Errorf("请求公共短信验证码服务失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return fmt.Errorf("获取公共短信验证码服务失败:%w", err)
}
log.Logger.Debug("获取公共短信验证码服务请求数据", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return fmt.Errorf("解析更新组织:%w", err)
}
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
return nil
}
... ...
package mobile_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/service"
)
type UserController struct {
baseController
}
func (controller *UserController) SendSmsCode() {
authService := service.UserService{}
smsCodeCmd := &command.SendSmsCodeCommand{}
err := controller.Unmarshal(smsCodeCmd)
if err != nil {
controller.Response(nil, err)
return
}
err = authService.SendSmsCaptcha(smsCodeCmd)
controller.Response(nil, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
)
func init() {
web.Router("/v1/app/users/smsCode", &mobile_client.UserController{}, "Post:SendSmsCode")
}
... ...