Refactor import paths to use internal/pkg/httpx/params

- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params".
- Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context.
- Ensured consistent usage of HTTP status responses across websocket handlers.
This commit is contained in:
mlogclub
2026-05-23 22:10:20 +08:00
parent f8b1ed42fa
commit 79614b2d07
140 changed files with 1117 additions and 595 deletions
+14 -13
View File
@@ -3,17 +3,18 @@ package api
import (
"cs-agent/internal/pkg/config"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/httpx/params"
"cs-agent/internal/services"
"net/http"
"net/url"
"strings"
"github.com/kataras/iris/v12"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AuthController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AuthController) PostLogin() *web.JsonResult {
@@ -23,7 +24,7 @@ func (c *AuthController) PostLogin() *web.JsonResult {
return web.JsonError(err)
}
ret, err := services.AuthService.Login(req, cfg.Auth, c.Ctx.RemoteAddr(), c.Ctx.GetHeader("User-Agent"))
ret, err := services.AuthService.Login(req, cfg.Auth, c.Ctx.ClientIP(), c.Ctx.GetHeader("User-Agent"))
if err != nil {
return web.JsonError(err)
}
@@ -31,37 +32,37 @@ func (c *AuthController) PostLogin() *web.JsonResult {
}
func (c *AuthController) GetWxwork_login() {
loginURL, err := services.WxWorkLoginService.BuildWxWorkLoginURL(c.Ctx.URLParam("next"))
loginURL, err := services.WxWorkLoginService.BuildWxWorkLoginURL(c.Ctx.Query("next"))
if err != nil {
c.redirectWxWorkError(err.Error())
return
}
c.Ctx.Redirect(loginURL, iris.StatusFound)
c.Ctx.Redirect(http.StatusFound, loginURL)
}
func (c *AuthController) GetWxwork_qr_login() {
loginURL, err := services.WxWorkLoginService.BuildWxWorkQRCodeLoginURL(c.Ctx.URLParam("next"))
loginURL, err := services.WxWorkLoginService.BuildWxWorkQRCodeLoginURL(c.Ctx.Query("next"))
if err != nil {
c.redirectWxWorkError(err.Error())
return
}
c.Ctx.Redirect(loginURL, iris.StatusFound)
c.Ctx.Redirect(http.StatusFound, loginURL)
}
func (c *AuthController) GetWxwork_callback() {
cfg := config.Current()
ticket, next, err := services.WxWorkLoginService.LoginByWxWork(
c.Ctx.URLParam("code"),
c.Ctx.URLParam("state"),
c.Ctx.Query("code"),
c.Ctx.Query("state"),
cfg.Auth,
c.Ctx.RemoteAddr(),
c.Ctx.ClientIP(),
c.Ctx.GetHeader("User-Agent"),
)
if err != nil {
c.redirectWxWorkError(err.Error())
return
}
c.Ctx.Redirect("/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next), iris.StatusFound)
c.Ctx.Redirect(http.StatusFound, "/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next))
}
func (c *AuthController) PostWxwork_exchange() *web.JsonResult {
@@ -95,5 +96,5 @@ func (c *AuthController) redirectWxWorkError(message string) {
if idx := strings.Index(message, ": "); idx >= 0 {
message = message[idx+2:]
}
c.Ctx.Redirect("/login?wxworkError="+url.QueryEscape(message), iris.StatusFound)
c.Ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(message))
}
@@ -6,12 +6,12 @@ import (
"cs-agent/internal/pkg/errorsx"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
type ChannelController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *ChannelController) AnyConfig() *web.JsonResult {
@@ -4,23 +4,23 @@ import (
"cs-agent/internal/builders"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/pkg/irisx"
"cs-agent/internal/pkg/httpx"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type ConversationController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *ConversationController) GetBy(id int64) *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -45,7 +45,7 @@ func (c *ConversationController) PostCreate_or_match() *web.JsonResult {
if channel == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -61,7 +61,7 @@ func (c *ConversationController) PostClose() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -4,12 +4,12 @@ import (
"cs-agent/internal/pkg/openidentity"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
type CustomerController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *CustomerController) PostSession_exchange() *web.JsonResult {
+13 -17
View File
@@ -4,26 +4,26 @@ import (
"cs-agent/internal/builders"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/enums"
"cs-agent/internal/pkg/irisx"
"cs-agent/internal/pkg/httpx"
"cs-agent/internal/services"
"strconv"
"strings"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
"github.com/spf13/cast"
)
type MessageController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *MessageController) AnyList() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -57,7 +57,7 @@ func (c *MessageController) PostSend() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -78,7 +78,7 @@ func (c *MessageController) PostRead() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
@@ -97,12 +97,12 @@ func (c *MessageController) PostUpload_image() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
if rawConv == "" {
return web.JsonErrorMsg("conversationId不能为空")
}
@@ -121,12 +121,10 @@ func (c *MessageController) PostUpload_image() *web.JsonResult {
return web.JsonError(err)
}
f, header, err := c.Ctx.FormFile("file")
header, err := c.Ctx.FormFile("file")
if err != nil {
return web.JsonErrorMsg("请选择上传图片")
}
_ = f.Close()
if !strings.HasPrefix(strings.ToLower(header.Header.Get("Content-Type")), "image/") {
return web.JsonErrorMsg("仅支持上传图片文件")
}
@@ -142,12 +140,12 @@ func (c *MessageController) PostUpload_attachment() *web.JsonResult {
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
return web.JsonErrorMsg("接入渠道未初始化")
}
external := irisx.GetExternalUser(c.Ctx)
external := httpx.GetExternalUser(c.Ctx)
if external == nil {
return web.JsonErrorMsg("外部身份未初始化")
}
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
if rawConv == "" {
return web.JsonErrorMsg("conversationId不能为空")
}
@@ -159,12 +157,10 @@ func (c *MessageController) PostUpload_attachment() *web.JsonResult {
return web.JsonError(err)
}
f, header, err := c.Ctx.FormFile("file")
header, err := c.Ctx.FormFile("file")
if err != nil {
return web.JsonErrorMsg("请选择上传附件")
}
_ = f.Close()
item, err := services.AssetService.UploadFile(header, "attachments", nil)
if err != nil {
return web.JsonError(err)
@@ -6,13 +6,13 @@ import (
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AgentController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AgentController) AnyList() *web.JsonResult {
@@ -6,13 +6,13 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AgentRunLogController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AgentRunLogController) AnyList() *web.JsonResult {
@@ -8,14 +8,14 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AgentTeamController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AgentTeamController) AnyList() *web.JsonResult {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AgentTeamScheduleController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AgentTeamScheduleController) AnyList() *web.JsonResult {
@@ -13,14 +13,14 @@ import (
"cs-agent/internal/pkg/utils"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AIAgentController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AIAgentController) AnyList() *web.JsonResult {
@@ -114,7 +114,7 @@ func (c *AIAgentController) PostUpdate_sort() *web.JsonResult {
return web.JsonError(err)
}
var ids []int64
if err := c.Ctx.ReadJSON(&ids); err != nil {
if err := params.ReadJSON(c.Ctx, &ids); err != nil {
return web.JsonError(err)
}
if err := services.AIAgentService.UpdateSort(ids); err != nil {
@@ -7,13 +7,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AIConfigController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AIConfigController) AnyList() *web.JsonResult {
@@ -133,7 +133,7 @@ func (c *AIConfigController) PostUpdate_sort() *web.JsonResult {
}
var ids []int64
if err := c.Ctx.ReadJSON(&ids); err != nil {
if err := params.ReadJSON(c.Ctx, &ids); err != nil {
return web.JsonError(err)
}
if err := services.AIConfigService.UpdateSort(ids); err != nil {
@@ -9,13 +9,13 @@ import (
"cs-agent/internal/services"
"strings"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type AssetController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *AssetController) AnyList() *web.JsonResult {
@@ -29,7 +29,7 @@ func (c *AssetController) AnyList() *web.JsonResult {
params.QueryFilter{ParamName: "createUserId"},
params.QueryFilter{ParamName: "filename", Op: params.Like},
).Desc("id")
if strings.TrimSpace(c.Ctx.URLParam("status")) == "" {
if strings.TrimSpace(c.Ctx.Query("status")) == "" {
cnd = cnd.Eq("status", enums.AssetStatusSuccess)
}
@@ -62,12 +62,10 @@ func (c *AssetController) PostCreate() *web.JsonResult {
if err := params.ReadForm(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
f, header, err := c.Ctx.FormFile("file")
header, err := c.Ctx.FormFile("file")
if err != nil {
return web.JsonErrorMsg("请选择上传文件")
}
_ = f.Close()
item, err := services.AssetService.UploadFile(header, req.Prefix, operator)
if err != nil {
return web.JsonError(err)
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type ChannelController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *ChannelController) AnyList() *web.JsonResult {
@@ -7,13 +7,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type CompanyController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *CompanyController) AnyList() *web.JsonResult {
@@ -10,15 +10,15 @@ import (
"strconv"
"strings"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/common/strs"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
"github.com/spf13/cast"
)
type ConversationController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *ConversationController) AnyList() *web.JsonResult {
@@ -272,7 +272,7 @@ func (c *ConversationController) PostUpload_image() *web.JsonResult {
return web.JsonError(err)
}
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
if rawConv == "" {
return web.JsonErrorMsg("conversationId不能为空")
}
@@ -284,12 +284,10 @@ func (c *ConversationController) PostUpload_image() *web.JsonResult {
return web.JsonError(err)
}
f, header, err := c.Ctx.FormFile("file")
header, err := c.Ctx.FormFile("file")
if err != nil {
return web.JsonErrorMsg("请选择上传图片")
}
_ = f.Close()
if !strings.HasPrefix(strings.ToLower(header.Header.Get("Content-Type")), "image/") {
return web.JsonErrorMsg("仅支持上传图片文件")
}
@@ -307,7 +305,7 @@ func (c *ConversationController) PostUpload_attachment() *web.JsonResult {
return web.JsonError(err)
}
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
if rawConv == "" {
return web.JsonErrorMsg("conversationId不能为空")
}
@@ -319,12 +317,10 @@ func (c *ConversationController) PostUpload_attachment() *web.JsonResult {
return web.JsonError(err)
}
f, header, err := c.Ctx.FormFile("file")
header, err := c.Ctx.FormFile("file")
if err != nil {
return web.JsonErrorMsg("请选择上传附件")
}
_ = f.Close()
item, err := services.AssetService.UploadFile(header, "attachments", operator)
if err != nil {
return web.JsonError(err)
@@ -6,13 +6,13 @@ import (
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type CustomerContactController struct {
Ctx iris.Context
Ctx *gin.Context
}
// AnyList GET/POST /customer-contact/list?customerId=
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type CustomerController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *CustomerController) PostList() *web.JsonResult {
@@ -3,13 +3,13 @@ package dashboard
import (
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type DashboardController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *DashboardController) GetOverview() *web.JsonResult {
@@ -12,14 +12,14 @@ import (
"cs-agent/internal/repositories"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeBaseController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *KnowledgeBaseController) AnyList() *web.JsonResult {
@@ -127,7 +127,7 @@ func (c *KnowledgeBaseController) PostDelete() *web.JsonResult {
func (c *KnowledgeBaseController) PostUpdate_sort() *web.JsonResult {
var ids []int64
if err := c.Ctx.ReadJSON(&ids); err != nil {
if err := params.ReadJSON(c.Ctx, &ids); err != nil {
return web.JsonError(err)
}
if err := services.KnowledgeBaseService.UpdateSort(ids); err != nil {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeDocumentController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *KnowledgeDocumentController) AnyList() *web.JsonResult {
@@ -7,13 +7,13 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeFAQController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *KnowledgeFAQController) AnyList() *web.JsonResult {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeRetrieveController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *KnowledgeRetrieveController) PostDebugSearch() *web.JsonResult {
@@ -6,13 +6,13 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeRetrieveLogController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *KnowledgeRetrieveLogController) AnyList() *web.JsonResult {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type MCPController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *MCPController) AnyList_servers() *web.JsonResult {
@@ -10,13 +10,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type NotificationController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *NotificationController) AnyList() *web.JsonResult {
@@ -31,7 +31,7 @@ func (c *NotificationController) AnyList() *web.JsonResult {
Eq("status", enums.StatusOk).
Desc("id")
switch strings.TrimSpace(c.Ctx.URLParam("readStatus")) {
switch strings.TrimSpace(c.Ctx.Query("readStatus")) {
case "unread":
cnd.Where("read_at IS NULL")
case "read":
@@ -5,14 +5,14 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/common/strs"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type PermissionController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *PermissionController) AnyList() *web.JsonResult {
@@ -7,14 +7,14 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type QuickReplyController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *QuickReplyController) AnyList() *web.JsonResult {
@@ -6,14 +6,14 @@ import (
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type RoleController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *RoleController) AnyList() *web.JsonResult {
@@ -177,7 +177,7 @@ func (c *RoleController) PostAssign_permission() *web.JsonResult {
func (c *RoleController) PostUpdate_sort() *web.JsonResult {
var ids []int64
if err := c.Ctx.ReadJSON(&ids); err != nil {
if err := params.ReadJSON(c.Ctx, &ids); err != nil {
return web.JsonError(err)
}
if err := services.RoleService.UpdateSort(ids); err != nil {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/services"
"time"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type SessionController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *SessionController) AnyList() *web.JsonResult {
@@ -12,13 +12,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type SkillDefinitionController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *SkillDefinitionController) AnyList() *web.JsonResult {
@@ -6,13 +6,13 @@ import (
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type TagController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *TagController) AnyList() *web.JsonResult {
@@ -101,7 +101,7 @@ func (c *TagController) PostDelete() *web.JsonResult {
func (c *TagController) PostUpdate_sort() *web.JsonResult {
var ids []int64
if err := c.Ctx.ReadJSON(&ids); err != nil {
if err := params.ReadJSON(c.Ctx, &ids); err != nil {
return web.JsonError(err)
}
if err := services.TagService.UpdateSort(ids); err != nil {
@@ -8,14 +8,14 @@ import (
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type TicketController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *TicketController) AnyList() *web.JsonResult {
@@ -8,13 +8,13 @@ import (
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type UserController struct {
Ctx iris.Context
Ctx *gin.Context
}
func (c *UserController) AnyList() *web.JsonResult {
+15 -13
View File
@@ -1,35 +1,37 @@
package third
import (
"cs-agent/internal/pkg/httpx/params"
"cs-agent/internal/wxwork"
"io"
"net/http"
"github.com/kataras/iris/v12"
"github.com/gin-gonic/gin"
"github.com/silenceper/wechat/v2/work/kf"
)
type WechatController struct {
Ctx iris.Context
Ctx *gin.Context
}
// GetCallback GET请求用于校验回调是否配置正确
func (c *WechatController) GetCallback() {
cli, err := wxwork.GetWorkCli().GetKF()
if err != nil {
c.Ctx.StopWithError(http.StatusInternalServerError, err)
c.Ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
options := kf.SignatureOptions{}
if err := c.Ctx.ReadForm(&options); err != nil {
c.Ctx.StopWithError(http.StatusUnauthorized, err)
if err := params.ReadForm(c.Ctx, &options); err != nil {
c.Ctx.AbortWithError(http.StatusUnauthorized, err)
return
}
// 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
echo, err := cli.VerifyURL(options)
if err == nil {
c.Ctx.WriteString(echo)
c.Ctx.String(http.StatusOK, echo)
} else {
c.Ctx.StopWithError(http.StatusUnauthorized, err)
c.Ctx.AbortWithError(http.StatusUnauthorized, err)
}
}
@@ -37,7 +39,7 @@ func (c *WechatController) GetCallback() {
func (c *WechatController) PostCallback() {
cli, err := wxwork.GetWorkCli().GetKF()
if err != nil {
c.Ctx.StopWithError(http.StatusInternalServerError, err)
c.Ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
var (
@@ -45,22 +47,22 @@ func (c *WechatController) PostCallback() {
body []byte
)
// 读取原始消息内容
body, err = c.Ctx.GetBody()
body, err = io.ReadAll(c.Ctx.Request.Body)
if err != nil {
c.Ctx.StopWithError(http.StatusInternalServerError, err)
c.Ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
// 解析原始数据
message, err = cli.GetCallbackMessage(body)
if err != nil {
c.Ctx.StopWithError(http.StatusInternalServerError, err)
c.Ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
if err := wxwork.ConsumeCallback(message); err != nil {
c.Ctx.StopWithError(http.StatusInternalServerError, err)
c.Ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
c.Ctx.WriteString("ok")
c.Ctx.String(http.StatusOK, "ok")
}