2026-04-09 10:01:23 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cs-agent/internal/pkg/irisx"
|
|
|
|
|
"cs-agent/internal/pkg/openidentity"
|
2026-04-28 10:15:15 +08:00
|
|
|
"cs-agent/internal/services"
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
|
"github.com/mlogclub/simple/web"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-25 10:31:35 +08:00
|
|
|
func ExternalInfoMiddleware(ctx iris.Context) {
|
2026-04-28 10:15:15 +08:00
|
|
|
channel := services.ChannelService.GetEnabledChannel(ctx)
|
2026-04-28 10:40:53 +08:00
|
|
|
if channel == nil {
|
|
|
|
|
ctx.StopExecution()
|
|
|
|
|
_ = ctx.JSON(web.JsonErrorMsg("接入渠道异常"))
|
|
|
|
|
return
|
2026-04-28 10:15:15 +08:00
|
|
|
}
|
2026-04-28 10:40:53 +08:00
|
|
|
secret := services.ChannelService.GetUserTokenSecret(channel)
|
|
|
|
|
ext, err := openidentity.GetExternalInfo(ctx, secret)
|
2026-04-09 10:01:23 +08:00
|
|
|
if err != nil {
|
|
|
|
|
ctx.StopExecution()
|
|
|
|
|
_ = ctx.JSON(web.JsonError(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-25 10:31:35 +08:00
|
|
|
irisx.SetExternalInfo(ctx, ext)
|
2026-04-09 10:01:23 +08:00
|
|
|
ctx.Next()
|
|
|
|
|
}
|