bjchy-udg-sdk 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +3 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -119,6 +119,7 @@ await client.login({ code: new URLSearchParams(location.search).get('c') })
119
119
  注意事项:
120
120
 
121
121
  - **不要改传 token**:URL 里的长效 JWT 在有效期内可被完全冒充,且 `init({ token })` 是 external 模式,SDK 不为它续期、过期即失效。
122
+ - **`code` 由哪个小程序签发,该租户就要配同一个小程序**:网关拿 `appid` 查到租户配置的 `miniAppId`(管理后台配置,未配置则沿用 `appid` 本身)去调微信 `jscode2session`,`miniAppId` 与 `code` 的签发方不一致会拿到 `40013 invalid appid`。这一步是服务端配置,SDK/客户端参数不变,也不能传 `miniAppId` 覆盖(服务端强制解析,防止客户端冒领身份)。
122
123
  - **页面刷新**:`login()` 幂等,缓存 token 未过期时直接复用,不会再用已废的 code;前提是 H5 每次 `init` 传的 `appid` 一致(token 存储键依赖它)。
123
124
  - **refreshToken 也过期时**:H5 拿不到新 code,SDK 的自动重登会返回失败并抛鉴权错误(这是预期行为)。业务兜底:`wx.miniProgram.redirectTo` 回中转页重取 code。注意 `wx.miniProgram.postMessage` **不是实时的**(小程序只在分享/复制链接/后退/组件销毁时才收到),不能用它通知小程序。
124
125
  - **CORS**:H5 域名需在 Gateway 的跨域白名单里。
@@ -212,6 +213,8 @@ wx.error((res) => {
212
213
 
213
214
  **openId 约定**:JWT 内统一字段名为 `openId`(小程序 `wx.login`、公众号网页授权、网页扫码、外部 MGAPIV3 token 均如此)。小程序 `login()` 与公众号 `login({ mpCode })` 成功时响应含 `openId`;扫码登录的 `openId` 在 JWT 中,业务侧一般从 `userInfo` 或解码 token 读取。
214
215
 
216
+ ⚠️ **小程序 openid 是按微信小程序(`miniAppId`)划分的,不是按 UDG 租户划分**:多个 UDG 租户若配了**同一个** `miniAppId`,同一个微信用户在这些租户里换回的 openid 是**同一个值**(可用于跨租户按 openid 关联同一自然人);配**不同** `miniAppId` 则 openid 不同、不能跨租户直接对人。
217
+
215
218
  envId / mongoDatabase / AppSecret 由服务端从 `wxdb.config` 读取,客户端不传、不可传。
216
219
 
217
220
  **同一 appid 多数据源**(一个 client、一份 token,用 `dbKey` 切换;管理后台里租户的 `bindings[]` 把 `dbKey` 路由到数据源注册中心里的某个数据源,详见 `docs/datasource-registry-and-schema-dictionary.md`;`dbKey` 路由思路的历史版本见 `docs/archive/multi-database-dbkey.md`):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bjchy-udg-sdk",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Universal Data Gateway SDK - 跨端统一数据访问(微信小程序 / Web / Node.js),API 兼容微信云开发",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",