fix(common): platformUrl 可选,不传使用默认公有平台
XuqmInitOptions.platformUrl 改为可选字段。 initialize() 内部:platformUrl ?? DEFAULT_TENANT_PLATFORM_URL。 公有云用户无需传 platformUrl,私有化部署传自有平台地址。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
d86cab56b3
当前提交
8fb59bb5f2
@ -42,16 +42,29 @@ SDK 读取配置文件后,自动调用 **方式 B** 完成完整初始化(
|
|||||||
App 主动调用,适用于无法提前写入配置文件或需要动态切换环境的场景。
|
App 主动调用,适用于无法提前写入配置文件或需要动态切换环境的场景。
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
await XuqmSDK.initialize({
|
// 使用默认公有平台(www.51szyx.com)
|
||||||
appKey: 'your-app-key',
|
await XuqmSDK.initialize({ appKey: 'your-app-key', debug: __DEV__ })
|
||||||
platformUrl: 'https://www.51szyx.com', // 平台地址,必填
|
|
||||||
debug: __DEV__,
|
// 使用私有化部署平台
|
||||||
})
|
await XuqmSDK.initialize({ appKey: 'your-app-key', platformUrl: 'https://your-server.com' })
|
||||||
|
```
|
||||||
|
|
||||||
|
**签名**:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface XuqmInitOptions {
|
||||||
|
appKey: string
|
||||||
|
platformUrl?: string // 平台地址,可选;不传则使用内置默认公有平台地址
|
||||||
|
debug?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
XuqmSDK.initialize(options: XuqmInitOptions): Promise<void>
|
||||||
```
|
```
|
||||||
|
|
||||||
**行为**:
|
**行为**:
|
||||||
1. 请求 `{platformUrl}/api/sdk/config?appKey={appKey}`
|
1. `platformUrl` 未传时使用内置默认公有平台地址(`DEFAULT_TENANT_PLATFORM_URL`)
|
||||||
2. 平台根据 appKey 和租户服务开通情况,返回该 App 专属的服务配置:
|
2. 请求 `{platformUrl}/api/sdk/config?appKey={appKey}`
|
||||||
|
3. 平台根据 appKey 和租户服务开通情况,返回该 App 专属的服务配置:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"apiUrl": "...", // 通用 API 地址
|
"apiUrl": "...", // 通用 API 地址
|
||||||
@ -62,20 +75,8 @@ await XuqmSDK.initialize({
|
|||||||
"imEnabled": true // 是否开通 IM 服务
|
"imEnabled": true // 是否开通 IM 服务
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
3. SDK 将服务配置保存,供所有子 SDK 使用。
|
4. SDK 将服务配置保存,供所有子 SDK 使用。
|
||||||
4. **失败时直接抛出错误**,不降级,不回退到默认地址。调用方必须处理异常。
|
5. **失败时直接抛出错误**,不降级。调用方必须处理异常。
|
||||||
|
|
||||||
**签名**:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
interface XuqmInitOptions {
|
|
||||||
appKey: string
|
|
||||||
platformUrl: string // 平台地址,必填
|
|
||||||
debug?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
XuqmSDK.initialize(options: XuqmInitOptions): Promise<void>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -471,11 +472,10 @@ App
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// 1. 初始化(通常在 App 入口,配置文件模式下可省略)
|
// 1. 初始化(通常在 App 入口,配置文件模式下可省略)
|
||||||
await XuqmSDK.initialize({
|
// 公有平台:不传 platformUrl
|
||||||
appKey: 'your-app-key',
|
await XuqmSDK.initialize({ appKey: 'your-app-key', debug: __DEV__ })
|
||||||
platformUrl: 'https://www.51szyx.com',
|
// 私有化部署:传入自有平台地址
|
||||||
debug: __DEV__,
|
// await XuqmSDK.initialize({ appKey: 'your-app-key', platformUrl: 'https://your-server.com' })
|
||||||
})
|
|
||||||
|
|
||||||
// 2. 业务登录(App 自有登录逻辑)
|
// 2. 业务登录(App 自有登录逻辑)
|
||||||
const result = await api.login(phone, verifyCode)
|
const result = await api.login(phone, verifyCode)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export interface XuqmInitOptions {
|
export interface XuqmInitOptions {
|
||||||
appKey: string
|
appKey: string
|
||||||
|
platformUrl?: string // 不传则使用内置默认公有平台地址
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,8 @@ export const XuqmSDK = {
|
|||||||
async initialize(options: XuqmInitOptions): Promise<void> {
|
async initialize(options: XuqmInitOptions): Promise<void> {
|
||||||
if (isInitialized()) return
|
if (isInitialized()) return
|
||||||
ensureInitPromise()
|
ensureInitPromise()
|
||||||
const configUrl = `${DEFAULT_TENANT_PLATFORM_URL}/api/sdk/config?appKey=${options.appKey}`
|
const baseUrl = options.platformUrl ?? DEFAULT_TENANT_PLATFORM_URL
|
||||||
|
const configUrl = `${baseUrl}/api/sdk/config?appKey=${options.appKey}`
|
||||||
try {
|
try {
|
||||||
const res = await fetch(configUrl)
|
const res = await fetch(configUrl)
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户