获取当前生效的appid
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m46s

This commit is contained in:
2026-04-30 10:52:33 +08:00
parent 66e12e9629
commit 248ed55f4e
4 changed files with 33 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
package app
import (
"strings"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
wechatConfigSvc "github.com/break/junhong_cmp_fiber/internal/service/wechat_config"
@@ -76,3 +78,19 @@ func (h *ClientWechatHandler) GetJSSDKConfig(c *fiber.Ctx) error {
Signature: jssdkConfig.Signature,
})
}
// GetAppID 获取当前生效的公众号 AppID
// GET /api/c/v1/wechat/appid
func (h *ClientWechatHandler) GetAppID(c *fiber.Ctx) error {
wechatConfig, err := h.wechatConfigService.GetActiveConfig(c.UserContext())
if err != nil {
return err
}
if wechatConfig == nil || strings.TrimSpace(wechatConfig.OaAppID) == "" {
return errors.New(errors.CodeWechatConfigUnavailable)
}
return response.Success(c, &dto.WechatAppIDResponse{
AppID: wechatConfig.OaAppID,
})
}

View File

@@ -68,3 +68,8 @@ type JSSDKConfigResponse struct {
NonceStr string `json:"nonce_str" description:"随机字符串"`
Signature string `json:"signature" description:"签名SHA1"`
}
// WechatAppIDResponse 微信 AppID 响应
type WechatAppIDResponse struct {
AppID string `json:"app_id" description:"当前生效的公众号 AppID"`
}

View File

@@ -22,6 +22,15 @@ func RegisterPersonalCustomerRoutes(router fiber.Router, doc *openapi.Generator,
authBasePath := "/auth"
// === 公开路由(无需认证)===
Register(router, doc, basePath, "GET", "/wechat/appid", handlers.ClientWechat.GetAppID, RouteSpec{
Summary: "获取当前生效的公众号 AppID",
Description: "用于 C 端免登录场景获取当前生效微信配置中的公众号 AppID响应仅返回 app_id 字段",
Tags: []string{"个人客户 - 微信"},
Auth: false,
Input: nil,
Output: &dto.WechatAppIDResponse{},
})
Register(router, doc, basePath, "GET", "/wechat/jssdk-config", handlers.ClientWechat.GetJSSDKConfig, RouteSpec{
Summary: "获取微信 JSSDK 签名配置",
Description: "前端调用 wx.config() 初始化微信 JS-SDK 时所需的签名参数,需传入当前页面完整 URL",