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 ReportPage 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" } reportPage := utils.GetConfigString("wechat.report_page") if reportPage == utils.StringEmpty { reportPage = "pagesB/details/index" } 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, ReportPage: reportPage, 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()) }