更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -12,37 +12,29 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// =============================================================
|
||||
// 微信公众号(服务号)配置与 access_token
|
||||
// =============================================================
|
||||
|
||||
// 消息加解密方式
|
||||
const (
|
||||
EncryptModePlain = "plain" // 明文模式
|
||||
EncryptModeCompatible = "compatible" // 兼容模式
|
||||
EncryptModeSafe = "safe" // 安全模式
|
||||
EncryptModePlain = "plain"
|
||||
EncryptModeCompatible = "compatible"
|
||||
EncryptModeSafe = "safe"
|
||||
)
|
||||
|
||||
// Config 服务号运行配置(敏感字段已解密)
|
||||
type Config struct {
|
||||
ID uint64
|
||||
AppID string
|
||||
AppSecret string // 明文
|
||||
AppSecret string
|
||||
Token string
|
||||
AESKey string // 明文(43 位 EncodingAESKey)
|
||||
AESKey string
|
||||
EncryptMode string
|
||||
TemplateID string
|
||||
Verified bool
|
||||
Enabled bool
|
||||
Remark string
|
||||
|
||||
FollowQrcode string // 关注二维码(data URL),绑定页展示供扫码关注
|
||||
FollowQrcode string
|
||||
}
|
||||
|
||||
// ErrNotConfigured 未配置或未启用
|
||||
var ErrNotConfigured = errors.New("微信公众号未配置或未启用")
|
||||
|
||||
// LoadConfig 读取服务号配置(单行,敏感字段解密);未配置返回 ErrNotConfigured
|
||||
func LoadConfig() (*Config, error) {
|
||||
var row models.WechatMpConfig
|
||||
err := models.Orm.QueryTable(new(models.WechatMpConfig)).OrderBy("id").One(&row)
|
||||
@@ -83,7 +75,6 @@ func LoadConfig() (*Config, error) {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// LoadEnabledConfig 读取并校验启用状态
|
||||
func LoadEnabledConfig() (*Config, error) {
|
||||
cfg, err := LoadConfig()
|
||||
if err != nil {
|
||||
@@ -95,12 +86,11 @@ func LoadEnabledConfig() (*Config, error) {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// SaveInput 保存配置入参(敏感字段支持掩码表示不改)
|
||||
type SaveInput struct {
|
||||
AppID string
|
||||
AppSecret string // 掩码 / 空串 = 保持不变
|
||||
AppSecret string
|
||||
Token string
|
||||
AESKey string // 掩码 / 空串 = 保持不变
|
||||
AESKey string
|
||||
EncryptMode string
|
||||
TemplateID string
|
||||
Verified bool
|
||||
@@ -108,7 +98,6 @@ type SaveInput struct {
|
||||
Remark string
|
||||
}
|
||||
|
||||
// SaveConfig 保存服务号配置(不存在则创建)
|
||||
func SaveConfig(in SaveInput) error {
|
||||
if strings.TrimSpace(in.AppID) == "" {
|
||||
return errors.New("AppID 不能为空")
|
||||
@@ -130,7 +119,6 @@ func SaveConfig(in SaveInput) error {
|
||||
row = models.WechatMpConfig{}
|
||||
}
|
||||
|
||||
// 敏感字段:掩码/空串表示保持原值
|
||||
secret := strings.TrimSpace(in.AppSecret)
|
||||
if secret != "" && !IsMasked(secret) {
|
||||
enc, eerr := EncryptSecret(secret)
|
||||
@@ -174,7 +162,6 @@ func SaveConfig(in SaveInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SaveFollowQrcode 保存/清空关注二维码(data URL,空串表示删除)
|
||||
func SaveFollowQrcode(dataURL string) error {
|
||||
dataURL = strings.TrimSpace(dataURL)
|
||||
now := time.Now()
|
||||
@@ -182,7 +169,6 @@ func SaveFollowQrcode(dataURL string) error {
|
||||
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
|
||||
@@ -195,7 +181,6 @@ func SaveFollowQrcode(dataURL string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// FollowQrcodeURL 读取关注二维码(未配置时返回空串)
|
||||
func FollowQrcodeURL() string {
|
||||
cfg, err := LoadConfig()
|
||||
if err != nil {
|
||||
@@ -204,8 +189,6 @@ func FollowQrcodeURL() string {
|
||||
return cfg.FollowQrcode
|
||||
}
|
||||
|
||||
// CallbackURL 微信服务器回调地址(供公众号后台「服务器配置」填写)。
|
||||
// 优先读取 app.conf 的 wechat_mp_callback_base,其次回落 payment_callback_base(同为对外 API 域名)。
|
||||
func CallbackURL() string {
|
||||
base, _ := beego.AppConfig.String("wechat_mp_callback_base")
|
||||
if strings.TrimSpace(base) == "" {
|
||||
@@ -218,8 +201,6 @@ func CallbackURL() string {
|
||||
return base + "/api/wechat/mp/callback"
|
||||
}
|
||||
|
||||
// ============================ access_token 缓存 ============================
|
||||
|
||||
type tokenEntry struct {
|
||||
appID string
|
||||
token string
|
||||
@@ -232,7 +213,6 @@ var (
|
||||
tokenMinTTL = 5 * time.Minute
|
||||
)
|
||||
|
||||
// resetTokenCacheForTest 仅供测试清理缓存
|
||||
func resetTokenCacheForTest() {
|
||||
tokenMu.Lock()
|
||||
defer tokenMu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user