更新若干功能
This commit is contained in:
1 parent
892ba5886d
commit
79d5ae6b66
45 files changed
+6755
-38
No files matched your search
@@ -24,6 +24,7 @@ type Config struct {
|
||||
Name string
|
||||
AppID string
|
||||
AppSecret string // 明文
|
||||
QrcodeURL string // 小程序码图片地址(对外展示)
|
||||
Enabled bool
|
||||
AutoBind bool
|
||||
Remark string
|
||||
@@ -35,12 +36,13 @@ var ErrNotConfigured = errors.New("微信小程序未配置或未启用")
|
||||
// appFromRow 解密行数据为运行配置
|
||||
func appFromRow(row models.WechatMiniApp) (*Config, error) {
|
||||
cfg := &Config{
|
||||
ID: row.ID,
|
||||
Name: row.Name,
|
||||
AppID: strings.TrimSpace(row.AppID),
|
||||
Enabled: row.Enabled == 1,
|
||||
AutoBind: row.AutoBind != 0,
|
||||
Remark: row.Remark,
|
||||
ID: row.ID,
|
||||
Name: row.Name,
|
||||
AppID: strings.TrimSpace(row.AppID),
|
||||
QrcodeURL: strings.TrimSpace(row.QrcodeURL),
|
||||
Enabled: row.Enabled == 1,
|
||||
AutoBind: row.AutoBind != 0,
|
||||
Remark: row.Remark,
|
||||
}
|
||||
if row.AppSecret != "" {
|
||||
plain, derr := wechatmp.DecryptSecret(row.AppSecret)
|
||||
@@ -140,12 +142,44 @@ func ListApps() ([]models.WechatMiniApp, error) {
|
||||
return rows, err
|
||||
}
|
||||
|
||||
// PublicApp 对外公布的小程序信息(供官网 / H5 等其他端展示二维码)
|
||||
type PublicApp struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
AppID string `json:"app_id"`
|
||||
QrcodeURL string `json:"qrcode_url"`
|
||||
}
|
||||
|
||||
// ListEnabledApps 已启用的小程序(含二维码地址),供其他端公开读取
|
||||
func ListEnabledApps() ([]PublicApp, error) {
|
||||
var rows []models.WechatMiniApp
|
||||
_, err := models.Orm.QueryTable(new(models.WechatMiniApp)).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("enabled", 1).
|
||||
OrderBy("id").
|
||||
All(&rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]PublicApp, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, PublicApp{
|
||||
ID: r.ID,
|
||||
Name: strings.TrimSpace(r.Name),
|
||||
AppID: strings.TrimSpace(r.AppID),
|
||||
QrcodeURL: strings.TrimSpace(r.QrcodeURL),
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// SaveAppInput 保存应用入参(AppSecret 支持掩码表示不修改)
|
||||
type SaveAppInput struct {
|
||||
ID uint64
|
||||
Name string
|
||||
AppID string
|
||||
AppSecret string // 掩码 / 空串 = 保持不变
|
||||
QrcodeURL string // 空串 = 清空二维码
|
||||
Enabled bool
|
||||
AutoBind bool
|
||||
Remark string
|
||||
@@ -202,6 +236,7 @@ func SaveApp(in SaveAppInput) (uint64, error) {
|
||||
if in.Enabled {
|
||||
row.Enabled = 1
|
||||
}
|
||||
row.QrcodeURL = strings.TrimSpace(in.QrcodeURL)
|
||||
row.AutoBind = 0
|
||||
if in.AutoBind {
|
||||
row.AutoBind = 1
|
||||
@@ -273,6 +308,7 @@ func SaveConfig(in SaveInput) error {
|
||||
Name: row.Name,
|
||||
AppID: in.AppID,
|
||||
AppSecret: in.AppSecret,
|
||||
QrcodeURL: row.QrcodeURL, // 旧端点不改动二维码
|
||||
Enabled: in.Enabled,
|
||||
AutoBind: in.AutoBind,
|
||||
Remark: in.Remark,
|
||||
|
||||
Reference in new issue
Block a user