Files
yunzerwebsiteallinone/go/docs/sql/create_wechat_mini_config.sql
T
2026-10-03 23:46:55 +08:00

43 lines
2.5 KiB
SQL
Raw 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.
-- =============================================================
-- 微信小程序配置(统一认证 · 小程序一键登录)
--
-- 小程序与公众号是两套独立应用,AppID / AppSecret 不可混用,
-- 因此单独建表。app_secret 以 AES-256-GCM 密文存储(YZW1: 前缀)。
--
-- 关联链路:
-- uniapp 小程序 → wx.login / getPhoneNumber
-- → POST /auth/wechat/miniapp/login
-- → jscode2session 换 openid → 按手机号定位 yz_auth_identity
-- → 写入 yz_auth_identity_third(provider='wechat_mini')
-- → 复用统一认证的会话与令牌(yz_auth_session / yz_auth_refresh_token)
-- =============================================================
CREATE TABLE IF NOT EXISTS `yz_platform_wechat_mini_config` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`app_id` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '小程序 AppID',
`app_secret` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '小程序 AppSecret(AES 密文,不回显)',
`enabled` TINYINT NOT NULL DEFAULT 0 COMMENT '是否启用小程序登录:0否 1是',
`auto_bind` TINYINT NOT NULL DEFAULT 1 COMMENT '手机号验证通过后是否自动绑定小程序:0否 1是',
`remark` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '备注',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信小程序配置';
-- -------------------------------------------------------------
-- 接入应用:微信小程序(app_type=4)
-- 小程序不走浏览器跳转,只用 POST /auth/wechat/miniapp/login 换令牌,
-- 因此无需登记 redirect_uris。
-- -------------------------------------------------------------
INSERT INTO `yz_auth_client`
(`client_id`, `app_code`, `name`, `app_type`, `grant_types`, `scope`, `access_ttl`, `refresh_ttl`, `realm`)
VALUES
('yz-miniapp', 'miniapp', '微信小程序', 4, 'authorization_code,refresh_token', 'openid,profile,tenant', 1800, 2592000, 'tenant')
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`);
-- -------------------------------------------------------------
-- 第三方身份源:允许 yz_auth_identity_third.provider 出现 'wechat_mini'
-- (表结构本身为 varchar,无需 DDL;此处仅作说明)
-- provider = 'wechat_mini',open_id = 小程序 openid,union_id = 小程序 unionid
-- -------------------------------------------------------------