fix: 优化企业微信回调处理和配置更新

This commit is contained in:
renzhiyuan 2026-01-06 17:48:35 +08:00
parent f71018dd96
commit 2a567dde86
4 changed files with 32 additions and 17 deletions

View File

@ -159,7 +159,7 @@ dingtalk:
qywx:
corp_id: "ww48151f694fb8ec67"
app_secret: "uYqtdwdtdH4Uv_P4is2AChuGzBCoB6cQDyRvpbW0Vmk"
token: "Jdukry6"
token: "zJdukry6"
aes_key: "4VLH47qRGUogc2d3QLWuUhvJlk8Y0YuRjXzeBquBq8B"
init_account: "les."
chat_id_len: 16

View File

@ -152,15 +152,15 @@ dingtalk:
bbxt: 23
qywx:
# corp_id: "ww48151f694fb8ec67"
# app_secret: "uYqtdwdtdH4Uv_P4is2AChuGzBCoB6cQDyRvpbW0Vmk"
# token: "uYqtdwdtdH4Uv_P4is2AChuGzBCoB6cQDyRvpbW0Vmk"
# aes_key: "4VLH47qRGUogc2d3QLWuUhvJlk8Y0YuRjXzeBquBq8B"
corp_id: "wwabfd0cec7171e769"
corp_id: "ww48151f694fb8ec67"
app_secret: "uYqtdwdtdH4Uv_P4is2AChuGzBCoB6cQDyRvpbW0Vmk"
token: "gY1AGR3mjBhzy"
aes_key: "g8VGfQEqluUhoKOlyjmmll8Q9C5tVFUTX5T2qkmI9Sv"
token: "zJdukry6"
aes_key: "4VLH47qRGUogc2d3QLWuUhvJlk8Y0YuRjXzeBquBq8B"
#
# corp_id: "wx5823bf96d3bd56c7"
# token: "QDG6eK"
# aes_key: "jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C"
# app_secret: "uYqtdwdtdH4Uv_P4is2AChuGzBCoB6cQDyRvpbW0Vmk"
init_account: "les."
chat_id_len: 16
default_config_id: 1

View File

@ -129,7 +129,9 @@ func registerResponse(router fiber.Router) {
func registerCommon(c *fiber.Ctx, err error) error {
// 调用下一个中间件或路由处理函数
if c.Path() == "/api/v1/qywx/callback" {
return nil
}
bsErr, ok := err.(*errors.BusinessErr)
if !ok {
bsErr = errors.SystemError

View File

@ -332,14 +332,21 @@ func (s *CallbackService) handleBugOptimizationSubmitDone(ctx context.Context, t
return msg, nil
}
func (s *CallbackService) QywxCallback(c *fiber.Ctx) error {
func (s *CallbackService) QywxCallback(c *fiber.Ctx) (err error) {
// 读取头
msgSignature := c.Query("msg_signature")
timestamp := c.Query("timestamp")
nonce := c.Query("nonce")
echostr := c.Query("echostr")
httpstr := string(c.Request().URI().QueryString())
start := strings.Index(httpstr, "msg_signature=")
start += len("msg_signature=")
var msgSignature string
next := getString(httpstr, "&timestamp=", start, &msgSignature)
var timestamp string
next = getString(httpstr, "&nonce=", next, &timestamp)
var nonce string
next = getString(httpstr, "&echostr=", next, &nonce)
echostr := httpstr[next:len(httpstr)]
echostr, _ = url.QueryUnescape(echostr)
fmt.Println(msgSignature, timestamp, nonce, echostr)
fmt.Println(httpstr, msgSignature, timestamp, nonce, echostr)
wxcpt := wxbizjsonmsgcrypt.NewWXBizMsgCrypt(s.cfg.Qywx.Token, s.cfg.Qywx.AES_KEY, s.cfg.Qywx.CorpId, wxbizjsonmsgcrypt.JsonType)
echoStr, cryptErr := wxcpt.VerifyURL(msgSignature, timestamp, nonce, echostr)
if nil != cryptErr {
@ -347,7 +354,13 @@ func (s *CallbackService) QywxCallback(c *fiber.Ctx) error {
return fmt.Errorf("%v", cryptErr)
}
fmt.Println("verifyUrl success echoStr", string(echoStr))
err := c.Send(echoStr)
err = c.Send(echoStr)
return err
}
func getString(str, endstr string, start int, msg *string) int {
end := strings.Index(str, endstr)
*msg = str[start:end]
return end + len(endstr)
}