2026-04-28 19:56:27 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cs-agent/internal/pkg/openidentity"
|
|
|
|
|
"cs-agent/internal/services"
|
|
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2026-04-28 19:56:27 +08:00
|
|
|
"github.com/mlogclub/simple/web"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CustomerController struct {
|
2026-05-23 22:10:20 +08:00
|
|
|
Ctx *gin.Context
|
2026-04-28 19:56:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *CustomerController) PostSession_exchange() *web.JsonResult {
|
|
|
|
|
channel := services.ChannelService.GetEnabledChannel(c.Ctx)
|
|
|
|
|
if channel == nil {
|
|
|
|
|
return web.JsonErrorMsg("接入渠道不存在或已停用")
|
|
|
|
|
}
|
|
|
|
|
externalUser, err := openidentity.GetExternalUser(c.Ctx, services.ChannelService.GetUserTokenSecret(channel))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return web.JsonError(err)
|
|
|
|
|
}
|
|
|
|
|
resp, err := services.CustomerSessionService.Exchange(channel, *externalUser)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return web.JsonError(err)
|
|
|
|
|
}
|
|
|
|
|
return web.JsonData(resp)
|
|
|
|
|
}
|