批量优化功能
This commit is contained in:
@@ -35,6 +35,8 @@ type Config struct {
|
||||
Verified bool
|
||||
Enabled bool
|
||||
Remark string
|
||||
|
||||
FollowQrcode string // 关注二维码(data URL),绑定页展示供扫码关注
|
||||
}
|
||||
|
||||
// ErrNotConfigured 未配置或未启用
|
||||
@@ -56,9 +58,10 @@ func LoadConfig() (*Config, error) {
|
||||
Token: strings.TrimSpace(row.Token),
|
||||
EncryptMode: strings.TrimSpace(row.EncryptMode),
|
||||
TemplateID: strings.TrimSpace(row.TemplateID),
|
||||
Verified: row.Verified == 1,
|
||||
Enabled: row.Enabled == 1,
|
||||
Remark: row.Remark,
|
||||
Verified: row.Verified == 1,
|
||||
Enabled: row.Enabled == 1,
|
||||
Remark: row.Remark,
|
||||
FollowQrcode: strings.TrimSpace(row.FollowQrcode),
|
||||
}
|
||||
if cfg.EncryptMode == "" {
|
||||
cfg.EncryptMode = EncryptModePlain
|
||||
@@ -171,6 +174,36 @@ func SaveConfig(in SaveInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SaveFollowQrcode 保存/清空关注二维码(data URL,空串表示删除)
|
||||
func SaveFollowQrcode(dataURL string) error {
|
||||
dataURL = strings.TrimSpace(dataURL)
|
||||
now := time.Now()
|
||||
var row models.WechatMpConfig
|
||||
err := models.Orm.QueryTable(new(models.WechatMpConfig)).OrderBy("id").One(&row)
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
// 尚无配置行:仅存二维码,其余字段留空
|
||||
row = models.WechatMpConfig{FollowQrcode: dataURL, EncryptMode: EncryptModePlain, CreateTime: now}
|
||||
_, err = models.Orm.Insert(&row)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
_, err = models.Orm.QueryTable(new(models.WechatMpConfig)).
|
||||
Filter("id", row.ID).
|
||||
Update(map[string]interface{}{"follow_qrcode": dataURL, "update_time": now})
|
||||
return err
|
||||
}
|
||||
|
||||
// FollowQrcodeURL 读取关注二维码(未配置时返回空串)
|
||||
func FollowQrcodeURL() string {
|
||||
cfg, err := LoadConfig()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return cfg.FollowQrcode
|
||||
}
|
||||
|
||||
// CallbackURL 微信服务器回调地址(供公众号后台「服务器配置」填写)。
|
||||
// 优先读取 app.conf 的 wechat_mp_callback_base,其次回落 payment_callback_base(同为对外 API 域名)。
|
||||
func CallbackURL() string {
|
||||
|
||||
Reference in New Issue
Block a user