2026-04-09 10:01:23 +08:00
|
|
|
package irisx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cs-agent/internal/pkg/openidentity"
|
|
|
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
2026-04-25 10:27:43 +08:00
|
|
|
"github.com/mlogclub/simple/common/strs"
|
|
|
|
|
"github.com/mlogclub/simple/web/params"
|
2026-04-09 10:01:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ctxKeyOpenImChannel = "openImChannel"
|
|
|
|
|
ctxKeyOpenImExternalInfo = "openImExternalInfo"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-25 10:27:43 +08:00
|
|
|
// func SetOpenImChannel(ctx iris.Context, channel *models.Channel) {
|
|
|
|
|
// ctx.Values().Set(ctxKeyOpenImChannel, channel)
|
|
|
|
|
// }
|
2026-04-09 10:01:23 +08:00
|
|
|
|
2026-04-25 10:27:43 +08:00
|
|
|
// // GetChannel 返回 OpenImContextMiddleware 注入的接入渠道(未走中间件时为 nil)。
|
|
|
|
|
// func GetChannel(ctx iris.Context) *models.Channel {
|
|
|
|
|
// v := ctx.Values().Get(ctxKeyOpenImChannel)
|
|
|
|
|
// channel, _ := v.(*models.Channel)
|
|
|
|
|
// return channel
|
|
|
|
|
// }
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
func SetOpenImExternalInfo(ctx iris.Context, ext *openidentity.ExternalInfo) {
|
|
|
|
|
ctx.Values().Set(ctxKeyOpenImExternalInfo, ext)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetExternalInfo 返回中间件注入的外部访客身份;仅 widget 子路径或未启用中间件时为 nil。
|
|
|
|
|
func GetExternalInfo(ctx iris.Context) *openidentity.ExternalInfo {
|
|
|
|
|
v := ctx.Values().Get(ctxKeyOpenImExternalInfo)
|
|
|
|
|
ext, _ := v.(*openidentity.ExternalInfo)
|
|
|
|
|
return ext
|
|
|
|
|
}
|
2026-04-25 10:27:43 +08:00
|
|
|
|
|
|
|
|
func GetChannelID(ctx iris.Context) string {
|
|
|
|
|
if channelID := ctx.GetHeader("X-Channel-ID"); strs.IsNotBlank(channelID) {
|
|
|
|
|
return channelID
|
|
|
|
|
}
|
|
|
|
|
if channelID, _ := params.Get(ctx, "channelId"); strs.IsNotBlank(channelID) {
|
|
|
|
|
return channelID
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|