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:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user