Files
yunzerwebsiteallinone/go/docs/sql/create_wechat_mini_app.sql
2026-10-21 17:45:50 +08:00

39 lines
2.1 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================
-- 微信小程序多应用配置(yz_platform_wechat_mini_app)
-- 支持配置多个小程序:认证端登录时按客户端传入 appid 精确匹配,
-- 未传 appid 时回退第一条启用记录。
-- AppSecret 以 AES-256-GCM 加密存储(复用 wechatmp 的密钥)。
-- 幂等脚本:重复执行不会产生重复数据。
-- 执行:mysql -h <host> -P <port> -u <user> -p <db> < create_wechat_mini_app.sql
-- ============================================================
CREATE TABLE IF NOT EXISTS yz_platform_wechat_mini_app (
id bigint unsigned NOT NULL AUTO_INCREMENT,
name varchar(128) NOT NULL DEFAULT '' COMMENT '应用名称',
app_id varchar(64) NOT NULL COMMENT '小程序 AppID',
app_secret varchar(512) NOT NULL DEFAULT '' COMMENT 'AppSecret(AES-256-GCM 加密存储)',
qrcode_url varchar(512) NOT NULL DEFAULT '' COMMENT '小程序码图片地址(供官网/H5等其他端调取)',
enabled tinyint NOT NULL DEFAULT 0 COMMENT '1=启用 0=停用',
auto_bind tinyint NOT NULL DEFAULT 1 COMMENT '1=手机号命中身份后自动绑定小程序',
remark varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time datetime NULL COMMENT '更新时间',
delete_time datetime NULL COMMENT '软删时间',
PRIMARY KEY (id),
UNIQUE KEY uk_mini_app_appid (app_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信小程序多应用配置';
-- 迁移旧单行配置(yz_platform_wechat_mini_config)到新表;已存在同 appid 时跳过
INSERT INTO yz_platform_wechat_mini_app (name, app_id, app_secret, enabled, auto_bind, remark)
SELECT COALESCE(NULLIF(c.remark, ''), '默认小程序'), c.app_id, c.app_secret, c.enabled, c.auto_bind, c.remark
FROM yz_platform_wechat_mini_config c
WHERE c.app_id <> ''
AND NOT EXISTS (
SELECT 1 FROM (SELECT 1 FROM yz_platform_wechat_mini_app x WHERE x.app_id = c.app_id) t
);
-- 结果校验
SELECT id, name, app_id, enabled, auto_bind, remark, qrcode_url
FROM yz_platform_wechat_mini_app
WHERE delete_time IS NULL;