diff --git a/cmd/config/config.go b/cmd/config/config.go index f02dec1..0d8f42e 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -113,6 +113,7 @@ type System struct { HttpPort string Host string RedirectUri string + Domain string } type Oss struct { AccessKeyId string diff --git a/pkg/common/jwt/common.go b/pkg/common/jwt/common.go index 3691777..dafcc8c 100644 --- a/pkg/common/jwt/common.go +++ b/pkg/common/jwt/common.go @@ -10,7 +10,7 @@ import ( "context" "fonchain-fiee/api/account" "fonchain-fiee/api/accountFiee" - "fonchain-fiee/pkg/config" + "fonchain-fiee/cmd/config" "fonchain-fiee/pkg/e" "fonchain-fiee/pkg/service" "fonchain-fiee/pkg/utils/secret" @@ -19,7 +19,7 @@ import ( // ParseToChatUser 将token信息转换为聊天室用户信息 func ParseToChatUser(c *gin.Context) (chatUserInfo *accountFiee.ChatUserData, code e.ErrorCodeType) { - domain := config.Domain + domain := config.AppConfig.System.Domain domainAny, exist := c.Get("domain") if exist { domain = domainAny.(string) @@ -34,7 +34,7 @@ func ParseToChatUser(c *gin.Context) (chatUserInfo *accountFiee.ChatUserData, co ctx := context.Background() var originId int64 = 0 switch domain { - case config.Domain: + case config.AppConfig.System.Domain: //fiee token校验 token, err = secret.GetJwtFromStr(token) if err != nil { diff --git a/pkg/common/ws/wsMessageHandle.go b/pkg/common/ws/wsMessageHandle.go index c04bbbd..f0ae5b6 100644 --- a/pkg/common/ws/wsMessageHandle.go +++ b/pkg/common/ws/wsMessageHandle.go @@ -12,7 +12,7 @@ import ( "fmt" "fonchain-fiee/api/account" "fonchain-fiee/api/accountFiee" - "fonchain-fiee/pkg/config" + "fonchain-fiee/cmd/config" "fonchain-fiee/pkg/e" "fonchain-fiee/pkg/service" "fonchain-fiee/pkg/utils/secret" @@ -33,14 +33,14 @@ func AuthorizationVerify(sourceData []byte) (userInfo *accountFiee.ChatUserData, var ctx = context.Background() var accountInfo accountFiee.ChatUserData switch msg.Content.Domain { - case config.Domain: + case config.AppConfig.System.Domain: //fiee token校验 msg.Content.Auth, err = secret.GetJwtFromStr(msg.Content.Auth) if err != nil { return } var fieeJwtInfo *accountFiee.DecryptJwtResponse - fieeJwtInfo, err = service.AccountFieeProvider.DecryptJwt(ctx, &accountFiee.DecryptJwtRequest{Token: msg.Content.Auth, Domain: msg.Content.Domain}) + fieeJwtInfo, err = service.AccountFieeProvider.DecryptJwt(ctx, &accountFiee.DecryptJwtRequest{Token: msg.Content.Auth, Domain: config.AppConfig.System.Domain}) if err != nil || fieeJwtInfo.IsOffline { return } diff --git a/pkg/router/router.go b/pkg/router/router.go index 58c37b5..dc7a80a 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -127,6 +127,9 @@ func NewRouter() *gin.Engine { v1.POST("aschat/autoReplyRuler/update", asChat.Handler.UpdateChatAutoReplyRuler) v1.POST("aschat/autoReplyRuler/detail", asChat.Handler.GetChatAutoReplyRulerDetail) v1.POST("aschat/autoReplyRuler/query", asChat.Handler.GetChatAutoReplyRulerList) + + v1.POST("/test/user/log/erp", asChat.Handler.ErpLoginDemo) + v1.POST("/test/user/log/fiee", asChat.Handler.FieeLoginDemo) } //静态文件 diff --git a/pkg/service/asChat/chatAutoReplyRulerHandler.go b/pkg/service/asChat/chatAutoReplyRulerHandler.go index 7905472..61dad63 100644 --- a/pkg/service/asChat/chatAutoReplyRulerHandler.go +++ b/pkg/service/asChat/chatAutoReplyRulerHandler.go @@ -1,10 +1,17 @@ package asChat import ( + "fmt" + "fonchain-fiee/api/account" "fonchain-fiee/api/accountFiee" + "fonchain-fiee/cmd/config" "fonchain-fiee/pkg/service" "fonchain-fiee/pkg/utils" + "fonchain-fiee/pkg/utils/secret" + "fonchain-fiee/pkg/utils/stime" "github.com/gin-gonic/gin" + "math/rand" + "time" ) var Handler = &ChatAutoReplyRulerHandler{} @@ -88,3 +95,93 @@ func (a *ChatAutoReplyRulerHandler) GetChatAutoReplyRulerList(c *gin.Context) { } service.Success(c, resp.List) } +func (a *ChatAutoReplyRulerHandler) ErpLoginDemo(c *gin.Context) { + var req ErpLoginDemoReq + if err := c.ShouldBindJSON(&req); err != nil { + service.Error(c, err) + return + } + loginRes, err := service.AccountProvider.Login(c, &account.LoginRequest{ + Domain: "fontree", + TelNum: req.TelNum, + Password: req.Password, + }) + if err != nil { + if err.Error() == "没有找到数据" || err.Error() == "No data found" { + registerRequest := account.RegistRequest{ + Domain: "fontree", + NickName: req.TelNum, + TelNum: req.TelNum, + Password: req.Password, + EnterDate: time.Now().Format(stime.Format_Normal_YMD), + Extend: &account.Extend{JumpTo: "onsite"}, //origin-老平台 onsite 当前 + JobNum: fmt.Sprintf("%d", rand.Intn(1000)), + } + registerRes, errs := service.AccountProvider.Register(c, ®isterRequest) + if errs != nil { + service.Error(c, errs) + return + } + service.Success(c, registerRes) + } else { + service.Error(c, err) + } + return + } + + departmentName := "" + if loginRes.AccountInfo != nil && len(loginRes.AccountInfo.Departments) > 0 { + departmentName = loginRes.AccountInfo.Departments[0].Name + } + loginRes.Token, err = secret.CombineSecret("xxx", departmentName, loginRes.Token) + if err != nil { + service.Error(c, err) + return + } + service.Success(c, loginRes) +} +func (a *ChatAutoReplyRulerHandler) FieeLoginDemo(c *gin.Context) { + var req ErpLoginDemoReq + if err := c.ShouldBindJSON(&req); err != nil { + service.Error(c, err) + return + } + loginRes, err := service.AccountFieeProvider.Login(c, &accountFiee.LoginRequest{ + Domain: config.AppConfig.System.Domain, + TelNum: req.TelNum, + Password: req.Password, + }) + if err != nil { + if err.Error() == "账号不存在" || err.Error() == "Account does not exist" { + registerRequest := accountFiee.RegistRequest{ + Domain: config.AppConfig.System.Domain, + NickName: req.TelNum, + TelNum: req.TelNum, + //Password: req.Password, + //EnterDate: time.Now().Format(stime.Format_Normal_YMD), + //Extend: &account.Extend{JumpTo: "onsite"}, //origin-老平台 onsite 当前 + //JobNum: fmt.Sprintf("%d", rand.Intn(1000)), + } + registerRes, errs := service.AccountFieeProvider.Register(c, ®isterRequest) + if errs != nil { + service.Error(c, errs) + return + } + service.Success(c, registerRes) + } else { + service.Error(c, err) + } + return + } + + departmentName := "" + if loginRes.AccountInfo != nil && len(loginRes.AccountInfo.Departments) > 0 { + departmentName = loginRes.AccountInfo.Departments[0].Name + } + loginRes.Token, err = secret.CombineSecret("xxx", departmentName, loginRes.Token) + if err != nil { + service.Error(c, err) + return + } + service.Success(c, loginRes) +} diff --git a/pkg/service/asChat/dto.go b/pkg/service/asChat/dto.go index 5afc57b..154900e 100644 --- a/pkg/service/asChat/dto.go +++ b/pkg/service/asChat/dto.go @@ -134,3 +134,9 @@ type GetChatAutoReplyRulerListRequest struct { PageSize int64 `json:"pageSize"` accountFiee.ChatAutoReplyRulerData } +type ErpLoginDemoReq struct { + TelNum string `json:"telNum"` + Password string `json:"password"` + Nickname string `json:"nickname"` + RealName string `json:"realName"` +}