bjchy-udg-sdk 1.4.1 → 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.
- package/README.md +4 -0
- 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 的跨域白名单里。
|
|
@@ -198,6 +199,7 @@ wx.error((res) => {
|
|
|
198
199
|
| `config:invalid url domain` | 微信 | 页面域名没加到公众号后台的「JS 接口安全域名」。到公众号后台 → 设置与开发 → 公众号设置 → 功能设置里添加,并把校验文件放到**域名根目录**可访问 |
|
|
199
200
|
| `config:permission denied` | 微信 | 该公众号没有此接口权限(未认证服务号权限受限),或接口名拼错 |
|
|
200
201
|
| 调接口时 `xxx:fail, the permission value is offline verifying` | 微信 | `jsApiList` 里没声明这个接口,或没等 `wx.ready` 就调用了 |
|
|
202
|
+
| `微信接口返回错误:40001 invalid credential` | 微信(经 UDG 转出) | 网关缓存的公众号 access_token 被别处刷新踢掉了(同一公众号被多个服务共用时会发生)。**网关会自动作废缓存重取并重试一次,正常情况下你看不到这个错误**;若仍抛出,说明重试后依然失败,需要检查网关的 `WX_MP_SECRET` 是否与公众号后台一致 |
|
|
201
203
|
| `微信接口返回错误(cgi-bin/token):40164 invalid ip xxx, not in whitelist` | 微信(经 UDG 转出) | **网关所在服务器的出口 IP 不在公众号后台的「IP 白名单」里**。这是独立于域名的一道闸门:公众号后台 → 设置与开发 → 基本配置 → IP 白名单,把报错里那个 IP 加进去。**只影响 `jsapiSign()`**(它要 access_token),`login({ mpCode })` 走网页授权接口、不受 IP 白名单限制 |
|
|
202
204
|
| `域名 xxx 不在 JSAPI 白名单内(WX_MP_JSAPI_HOSTS)` | UDG | 网关的 `.env` 里 `WX_MP_JSAPI_HOSTS` 没包含该域名。**这是精确匹配 host,子域不会自动放行**(`a.example.cn` 不因 `example.cn` 在名单里而通过)。需要运维在 `gateway/.env` 追加该域名(逗号分隔)后 `pm2 restart udg-gateway` |
|
|
203
205
|
| `url 必须是 https` | UDG | 公众号 JS 接口安全域名只支持 https,本地 http 调试拿不到签名(可在真机上用正式域名联调) |
|
|
@@ -211,6 +213,8 @@ wx.error((res) => {
|
|
|
211
213
|
|
|
212
214
|
**openId 约定**:JWT 内统一字段名为 `openId`(小程序 `wx.login`、公众号网页授权、网页扫码、外部 MGAPIV3 token 均如此)。小程序 `login()` 与公众号 `login({ mpCode })` 成功时响应含 `openId`;扫码登录的 `openId` 在 JWT 中,业务侧一般从 `userInfo` 或解码 token 读取。
|
|
213
215
|
|
|
216
|
+
⚠️ **小程序 openid 是按微信小程序(`miniAppId`)划分的,不是按 UDG 租户划分**:多个 UDG 租户若配了**同一个** `miniAppId`,同一个微信用户在这些租户里换回的 openid 是**同一个值**(可用于跨租户按 openid 关联同一自然人);配**不同** `miniAppId` 则 openid 不同、不能跨租户直接对人。
|
|
217
|
+
|
|
214
218
|
envId / mongoDatabase / AppSecret 由服务端从 `wxdb.config` 读取,客户端不传、不可传。
|
|
215
219
|
|
|
216
220
|
**同一 appid 多数据源**(一个 client、一份 token,用 `dbKey` 切换;管理后台里租户的 `bindings[]` 把 `dbKey` 路由到数据源注册中心里的某个数据源,详见 `docs/datasource-registry-and-schema-dictionary.md`;`dbKey` 路由思路的历史版本见 `docs/archive/multi-database-dbkey.md`):
|