更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+6 -32
View File
@@ -1,10 +1,3 @@
// Package wechatmini 微信小程序服务端能力:配置、code 换 openid、手机号快速验证。
//
// 与 services/wechatmp(公众号)分开:小程序走 sns/jscode2session 与
// wxa/business/getuserphonenumber,两者的 AppID / AppSecret 互不相通。
//
// 配置存储:多应用表 yz_platform_wechat_mini_app(docs/sql/create_wechat_mini_app.sql),
// 旧单行表 yz_platform_wechat_mini_config 仅作为未迁移部署的回退数据源。
package wechatmini
import (
@@ -18,22 +11,19 @@ import (
"server/services/wechatmp"
)
// Config 小程序运行配置(敏感字段已解密)
type Config struct {
ID uint64
Name string
AppID string
AppSecret string // 明文
QrcodeURL string // 小程序码图片地址(对外展示)
AppSecret string
QrcodeURL string
Enabled bool
AutoBind bool
Remark string
}
// ErrNotConfigured 未配置或未启用
var ErrNotConfigured = errors.New("微信小程序未配置或未启用")
// appFromRow 解密行数据为运行配置
func appFromRow(row models.WechatMiniApp) (*Config, error) {
cfg := &Config{
ID: row.ID,
@@ -54,8 +44,6 @@ func appFromRow(row models.WechatMiniApp) (*Config, error) {
return cfg, nil
}
// LoadConfig 读取小程序配置(多应用表第一条,敏感字段解密)。
// 新表无数据时回退旧单行表(未执行迁移 SQL 的存量部署);均未配置返回 ErrNotConfigured
func LoadConfig() (*Config, error) {
var rows []models.WechatMiniApp
_, err := models.Orm.QueryTable(new(models.WechatMiniApp)).
@@ -66,7 +54,6 @@ func LoadConfig() (*Config, error) {
return appFromRow(rows[0])
}
// 旧单行表回退
var legacy models.WechatMiniConfig
err = models.Orm.QueryTable(new(models.WechatMiniConfig)).OrderBy("id").One(&legacy)
if err != nil {
@@ -92,7 +79,6 @@ func LoadConfig() (*Config, error) {
return cfg, nil
}
// LoadEnabledConfig 读取并校验启用状态
func LoadEnabledConfig() (*Config, error) {
cfg, err := LoadConfig()
if err != nil {
@@ -104,8 +90,6 @@ func LoadEnabledConfig() (*Config, error) {
return cfg, nil
}
// LoadEnabledAppByAppID 按小程序 AppID 精确读取启用配置(多小程序场景,
// 认证端按客户端传入的 appid 选择对应应用)
func LoadEnabledAppByAppID(appID string) (*Config, error) {
appID = strings.TrimSpace(appID)
if appID == "" {
@@ -132,7 +116,6 @@ func LoadEnabledAppByAppID(appID string) (*Config, error) {
return cfg, nil
}
// ListApps 应用列表(软删除外,AppSecret 不回显)
func ListApps() ([]models.WechatMiniApp, error) {
var rows []models.WechatMiniApp
_, err := models.Orm.QueryTable(new(models.WechatMiniApp)).
@@ -142,7 +125,6 @@ func ListApps() ([]models.WechatMiniApp, error) {
return rows, err
}
// PublicApp 对外公布的小程序信息(供官网 / H5 等其他端展示二维码)
type PublicApp struct {
ID uint64 `json:"id"`
Name string `json:"name"`
@@ -150,7 +132,6 @@ type PublicApp struct {
QrcodeURL string `json:"qrcode_url"`
}
// ListEnabledApps 已启用的小程序(含二维码地址),供其他端公开读取
func ListEnabledApps() ([]PublicApp, error) {
var rows []models.WechatMiniApp
_, err := models.Orm.QueryTable(new(models.WechatMiniApp)).
@@ -173,19 +154,17 @@ func ListEnabledApps() ([]PublicApp, error) {
return list, nil
}
// SaveAppInput 保存应用入参(AppSecret 支持掩码表示不修改)
type SaveAppInput struct {
ID uint64
Name string
AppID string
AppSecret string // 掩码 / 空串 = 保持不变
QrcodeURL string // 空串 = 清空二维码
AppSecret string
QrcodeURL string
Enabled bool
AutoBind bool
Remark string
}
// SaveApp 新增/更新小程序应用(AppID 全局唯一,排除自身)
func SaveApp(in SaveAppInput) (uint64, error) {
appID := strings.TrimSpace(in.AppID)
if appID == "" {
@@ -206,7 +185,6 @@ func SaveApp(in SaveAppInput) (uint64, error) {
row = models.WechatMiniApp{CreateTime: now}
}
// AppID 唯一性校验(排除自身)
dupQ := models.Orm.QueryTable(new(models.WechatMiniApp)).
Filter("app_id", appID).
Filter("delete_time__isnull", true)
@@ -254,7 +232,6 @@ func SaveApp(in SaveAppInput) (uint64, error) {
return row.ID, nil
}
// DeleteApp 删除应用(软删并停用)
func DeleteApp(id uint64) error {
if id == 0 {
return errors.New("无效ID")
@@ -271,17 +248,14 @@ func DeleteApp(id uint64) error {
return err
}
// SaveInput 旧单行配置保存入参(AppSecret 支持掩码表示不修改)——兼容旧端点,
// 现写入新多应用表的第一行(无行时插入)
type SaveInput struct {
AppID string
AppSecret string // 掩码 / 空串 = 保持不变
AppSecret string
Enabled bool
AutoBind bool
Remark string
}
// SaveConfig 保存配置(兼容旧单行端点:写入新表第一行,不存在则创建)
func SaveConfig(in SaveInput) error {
var row models.WechatMiniApp
err := models.Orm.QueryTable(new(models.WechatMiniApp)).
@@ -308,7 +282,7 @@ func SaveConfig(in SaveInput) error {
Name: row.Name,
AppID: in.AppID,
AppSecret: in.AppSecret,
QrcodeURL: row.QrcodeURL, // 旧端点不改动二维码
QrcodeURL: row.QrcodeURL,
Enabled: in.Enabled,
AutoBind: in.AutoBind,
Remark: in.Remark,