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

62 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
Width int
EnvVersion string
}
func LoadWechatConfig(clientCode string) (*WechatConfig, error) {
if clientCode == utils.StringEmpty {
return nil, fmt.Errorf("client_code empty")
}
prefix := "wechat." + clientCode
appID := utils.GetConfigString(prefix + ".appid")
secret := utils.GetConfigString(prefix + ".secret")
if appID == utils.StringEmpty || secret == utils.StringEmpty {
return nil, fmt.Errorf("wechat config missing for client %s", clientCode)
}
page := utils.GetConfigString(prefix + ".page")
if page == utils.StringEmpty {
page = "pages/index/index"
}
width := utils.GetConfigInt(prefix + ".width")
if width <= 0 {
width = 430
}
envVersion := utils.GetConfigString(prefix + ".env_version")
if envVersion == utils.StringEmpty {
envVersion = "trial"
}
return &WechatConfig{
AppID: appID,
Secret: secret,
Page: page,
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())
}