2026-04-28 19:56:27 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-23 22:22:18 +08:00
|
|
|
"cs-agent/internal/pkg/httpx"
|
2026-04-28 19:56:27 +08:00
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func CustomerPostSession_exchange(ctx *gin.Context) {
|
|
|
|
|
channel := services.ChannelService.GetEnabledChannel(ctx)
|
2026-04-28 19:56:27 +08:00
|
|
|
if channel == nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道不存在或已停用"))
|
|
|
|
|
return
|
2026-04-28 19:56:27 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
externalUser, err := openidentity.GetExternalUser(ctx, services.ChannelService.GetUserTokenSecret(channel))
|
2026-04-28 19:56:27 +08:00
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-28 19:56:27 +08:00
|
|
|
}
|
|
|
|
|
resp, err := services.CustomerSessionService.Exchange(channel, *externalUser)
|
|
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-28 19:56:27 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, resp)
|
2026-04-28 19:56:27 +08:00
|
|
|
}
|