Files
lone-services/services/analysis/internal/config/wechat.go
T
2026-10-15 09:23:07 +08:00

61 lines
1.3 KiB
Go

package config
import (
"fmt"
"lone-services/pkg/utils"
"lone-services/pkg/wechat/auth"
"lone-services/pkg/wechat/qrcode"
)
type WechatConfig struct {
AppID string
Secret string
Page string
AuthPage string
Width int
EnvVersion string
}
func LoadWechatConfig() (*WechatConfig, error) {
appID := utils.GetConfigString("wechat.appid")
secret := utils.GetConfigString("wechat.secret")
if appID == utils.StringEmpty || secret == utils.StringEmpty {
return nil, fmt.Errorf("wechat config missing")
}
page := utils.GetConfigString("wechat.page")
if page == utils.StringEmpty {
page = "pages/index/index"
}
authPage := utils.GetConfigString("wechat.auth_page")
if authPage == utils.StringEmpty {
authPage = "pagesB/authorize/scan"
}
width := utils.GetConfigInt("wechat.width")
if width <= 0 {
width = 430
}
envVersion := utils.GetConfigString("wechat.env_version")
if envVersion == utils.StringEmpty {
envVersion = "trial"
}
return &WechatConfig{
AppID: appID,
Secret: secret,
Page: page,
AuthPage: authPage,
Width: width,
EnvVersion: envVersion,
}, nil
}
func (c *WechatConfig) NewAuthClient() *auth.Client {
return auth.NewClient(c.AppID, c.Secret)
}
func (c *WechatConfig) NewQrcodeClient() *qrcode.Client {
return qrcode.NewClient(c.NewAuthClient())
}