fix: 修复聊天中的token校验问题
This commit is contained in:
parent
fb076dd4db
commit
b979be1484
@ -113,6 +113,7 @@ type System struct {
|
|||||||
HttpPort string
|
HttpPort string
|
||||||
Host string
|
Host string
|
||||||
RedirectUri string
|
RedirectUri string
|
||||||
|
Domain string
|
||||||
}
|
}
|
||||||
type Oss struct {
|
type Oss struct {
|
||||||
AccessKeyId string
|
AccessKeyId string
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fonchain-fiee/api/account"
|
"fonchain-fiee/api/account"
|
||||||
"fonchain-fiee/api/accountFiee"
|
"fonchain-fiee/api/accountFiee"
|
||||||
"fonchain-fiee/pkg/config"
|
"fonchain-fiee/cmd/config"
|
||||||
"fonchain-fiee/pkg/e"
|
"fonchain-fiee/pkg/e"
|
||||||
"fonchain-fiee/pkg/service"
|
"fonchain-fiee/pkg/service"
|
||||||
"fonchain-fiee/pkg/utils/secret"
|
"fonchain-fiee/pkg/utils/secret"
|
||||||
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
// ParseToChatUser 将token信息转换为聊天室用户信息
|
// ParseToChatUser 将token信息转换为聊天室用户信息
|
||||||
func ParseToChatUser(c *gin.Context) (chatUserInfo *accountFiee.ChatUserData, code e.ErrorCodeType) {
|
func ParseToChatUser(c *gin.Context) (chatUserInfo *accountFiee.ChatUserData, code e.ErrorCodeType) {
|
||||||
domain := config.Domain
|
domain := config.AppConfig.System.Domain
|
||||||
domainAny, exist := c.Get("domain")
|
domainAny, exist := c.Get("domain")
|
||||||
if exist {
|
if exist {
|
||||||
domain = domainAny.(string)
|
domain = domainAny.(string)
|
||||||
@ -34,7 +34,7 @@ func ParseToChatUser(c *gin.Context) (chatUserInfo *accountFiee.ChatUserData, co
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var originId int64 = 0
|
var originId int64 = 0
|
||||||
switch domain {
|
switch domain {
|
||||||
case config.Domain:
|
case config.AppConfig.System.Domain:
|
||||||
//fiee token校验
|
//fiee token校验
|
||||||
token, err = secret.GetJwtFromStr(token)
|
token, err = secret.GetJwtFromStr(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"fonchain-fiee/api/account"
|
"fonchain-fiee/api/account"
|
||||||
"fonchain-fiee/api/accountFiee"
|
"fonchain-fiee/api/accountFiee"
|
||||||
"fonchain-fiee/pkg/config"
|
"fonchain-fiee/cmd/config"
|
||||||
"fonchain-fiee/pkg/e"
|
"fonchain-fiee/pkg/e"
|
||||||
"fonchain-fiee/pkg/service"
|
"fonchain-fiee/pkg/service"
|
||||||
"fonchain-fiee/pkg/utils/secret"
|
"fonchain-fiee/pkg/utils/secret"
|
||||||
@ -33,14 +33,14 @@ func AuthorizationVerify(sourceData []byte) (userInfo *accountFiee.ChatUserData,
|
|||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
var accountInfo accountFiee.ChatUserData
|
var accountInfo accountFiee.ChatUserData
|
||||||
switch msg.Content.Domain {
|
switch msg.Content.Domain {
|
||||||
case config.Domain:
|
case config.AppConfig.System.Domain:
|
||||||
//fiee token校验
|
//fiee token校验
|
||||||
msg.Content.Auth, err = secret.GetJwtFromStr(msg.Content.Auth)
|
msg.Content.Auth, err = secret.GetJwtFromStr(msg.Content.Auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var fieeJwtInfo *accountFiee.DecryptJwtResponse
|
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 {
|
if err != nil || fieeJwtInfo.IsOffline {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,9 @@ func NewRouter() *gin.Engine {
|
|||||||
v1.POST("aschat/autoReplyRuler/update", asChat.Handler.UpdateChatAutoReplyRuler)
|
v1.POST("aschat/autoReplyRuler/update", asChat.Handler.UpdateChatAutoReplyRuler)
|
||||||
v1.POST("aschat/autoReplyRuler/detail", asChat.Handler.GetChatAutoReplyRulerDetail)
|
v1.POST("aschat/autoReplyRuler/detail", asChat.Handler.GetChatAutoReplyRulerDetail)
|
||||||
v1.POST("aschat/autoReplyRuler/query", asChat.Handler.GetChatAutoReplyRulerList)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
//静态文件
|
//静态文件
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
package asChat
|
package asChat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"fonchain-fiee/api/account"
|
||||||
"fonchain-fiee/api/accountFiee"
|
"fonchain-fiee/api/accountFiee"
|
||||||
|
"fonchain-fiee/cmd/config"
|
||||||
"fonchain-fiee/pkg/service"
|
"fonchain-fiee/pkg/service"
|
||||||
"fonchain-fiee/pkg/utils"
|
"fonchain-fiee/pkg/utils"
|
||||||
|
"fonchain-fiee/pkg/utils/secret"
|
||||||
|
"fonchain-fiee/pkg/utils/stime"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Handler = &ChatAutoReplyRulerHandler{}
|
var Handler = &ChatAutoReplyRulerHandler{}
|
||||||
@ -88,3 +95,93 @@ func (a *ChatAutoReplyRulerHandler) GetChatAutoReplyRulerList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
service.Success(c, resp.List)
|
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)
|
||||||
|
}
|
||||||
|
@ -134,3 +134,9 @@ type GetChatAutoReplyRulerListRequest struct {
|
|||||||
PageSize int64 `json:"pageSize"`
|
PageSize int64 `json:"pageSize"`
|
||||||
accountFiee.ChatAutoReplyRulerData
|
accountFiee.ChatAutoReplyRulerData
|
||||||
}
|
}
|
||||||
|
type ErpLoginDemoReq struct {
|
||||||
|
TelNum string `json:"telNum"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
RealName string `json:"realName"`
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user