46 lines
980 B
Go
46 lines
980 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/wechat/qrcode"
|
|
)
|
|
|
|
type WechatQrcodeConfig struct {
|
|
AppID string
|
|
Secret string
|
|
Page string
|
|
Width int
|
|
EnvVersion string
|
|
}
|
|
|
|
func LoadWechatQrcodeConfig() (*WechatQrcodeConfig, 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")
|
|
|
|
width := utils.GetConfigInt("wechat.width")
|
|
envVersion := utils.GetConfigString("wechat.env_version")
|
|
if envVersion == utils.StringEmpty {
|
|
envVersion = "trial"
|
|
}
|
|
|
|
return &WechatQrcodeConfig{
|
|
AppID: appID,
|
|
Secret: secret,
|
|
Page: page,
|
|
Width: width,
|
|
EnvVersion: envVersion,
|
|
}, nil
|
|
}
|
|
|
|
func (c *WechatQrcodeConfig) NewQrcodeClient() *qrcode.Client {
|
|
return qrcode.NewClient(c.AppID, c.Secret)
|
|
}
|