履约配置优化
This commit is contained in:
@@ -25,6 +25,7 @@ export function resolveCloudtentaclesConfig(overrides = {}) {
|
||||
vnVerifCodePath: '/public/vn_verif_code',
|
||||
vnVerifyLoginCodePath: '/vn/verify_login_code',
|
||||
vnBindUrlPath: '/vn/bind_url',
|
||||
vnBindInfoPath: '/vn/bind_info',
|
||||
vnBackPath: '/vn/back',
|
||||
publicKeyPem: '',
|
||||
clientSource: 'ct-client',
|
||||
@@ -57,6 +58,7 @@ export function resolveCloudtentaclesConfig(overrides = {}) {
|
||||
'/vn/verify_login_code',
|
||||
),
|
||||
vnBindUrlPath: normalizePath(overrides.vnBindUrlPath || baseConfig.vnBindUrlPath, '/vn/bind_url'),
|
||||
vnBindInfoPath: normalizePath(overrides.vnBindInfoPath || baseConfig.vnBindInfoPath, '/vn/bind_info'),
|
||||
vnBackPath: normalizePath(overrides.vnBackPath || baseConfig.vnBackPath, '/vn/back'),
|
||||
publicKeyPem: normalizePem(overrides.publicKeyPem || baseConfig.publicKeyPem),
|
||||
clientSource: String(overrides.clientSource || baseConfig.clientSource || 'ct-client').trim() || 'ct-client',
|
||||
|
||||
@@ -159,6 +159,35 @@ export async function getCloudtentaclesBindUrl(payload = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCloudtentaclesBindInfo(payload = {}) {
|
||||
const token = requireToken(payload.token, 'cloudtentacles 获取绑定信息缺少 token', 'cloudtentacles_vn_bind_info_missing_token')
|
||||
const key = requireKey(payload.key, 'cloudtentacles 获取绑定信息缺少 key', 'cloudtentacles_vn_bind_info_missing_key')
|
||||
const id = requireId(payload.id, 'cloudtentacles 获取绑定信息缺少 id', 'cloudtentacles_vn_bind_info_missing_id')
|
||||
const config = resolveCloudtentaclesConfig(payload)
|
||||
|
||||
const result = await cloudtentaclesRequest(config.vnBindInfoPath, {
|
||||
...config,
|
||||
method: 'POST',
|
||||
token,
|
||||
body: [{ id, key }],
|
||||
businessErrorStatusCode: 401,
|
||||
businessErrorCode: 'cloudtentacles_vn_bind_info_failed',
|
||||
})
|
||||
|
||||
const items = Array.isArray(result.payload?.data) ? result.payload.data : []
|
||||
const matchedItem = items.find((item) => Number(item?.id || 0) === id) || items[0] || {}
|
||||
const bindInfo = parseBindInfo(matchedItem?.bind_info)
|
||||
|
||||
return {
|
||||
baseUrl: config.baseUrl,
|
||||
key,
|
||||
id,
|
||||
bindInfo,
|
||||
rawItem: isPlainObject(matchedItem) ? matchedItem : {},
|
||||
raw: result.payload ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
export async function backCloudtentaclesVirtualNumber(payload = {}) {
|
||||
const token = requireToken(payload.token, 'cloudtentacles 退还号码缺少 token', 'cloudtentacles_vn_back_missing_token')
|
||||
const key = requireKey(payload.key, 'cloudtentacles 退还号码缺少 key', 'cloudtentacles_vn_back_missing_key')
|
||||
@@ -185,14 +214,14 @@ export async function backCloudtentaclesVirtualNumber(payload = {}) {
|
||||
|
||||
function mapVirtualNumberItem(item) {
|
||||
const source = isPlainObject(item) ? item : {}
|
||||
const bindInfoText = String(source.bind_info || '').trim()
|
||||
const bindInfo = parseBindInfo(source.bind_info)
|
||||
|
||||
return {
|
||||
id: Number(source.id || 0),
|
||||
phone: String(source.phone || '').trim(),
|
||||
status: Number(source.status || 0),
|
||||
countTime: Number(source.count_time || 0),
|
||||
bindInfo: tryParseJson(bindInfoText) || bindInfoText || null,
|
||||
bindInfo,
|
||||
raw: source,
|
||||
}
|
||||
}
|
||||
@@ -241,6 +270,11 @@ function tryParseJson(text) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseBindInfo(value) {
|
||||
const bindInfoText = String(value || '').trim()
|
||||
return tryParseJson(bindInfoText) || bindInfoText || null
|
||||
}
|
||||
|
||||
function isPlainObject(value) {
|
||||
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user