让信任可见:打造家政人员的数字化"健康码"
对于雇主而言,一份几十页的专业背调报告往往过于晦涩。他们在浏览家政 App 时,更希望看到直观的"实名认证"、"无犯罪记录"、"从业稳定"等可视化标签。
作为全栈开发者,我们的任务不仅是调用接口,更是充当"翻译官"的角色。我们需要接入 天远家政风险报告 (接口代码 COMBTY15),将底层复杂的司法、公安、租赁行为数据,清洗为前端友好的 ViewModel,从而在 UI 层展示出具有说服力的信任画像。
本文将演示如何在 Node.js (TypeScript) 环境下对接该接口,并实现一个"风险转标签"的转换器(Transformer)。
TypeScript 类型定义:构建数据基石
COMBTY15 返回的是一个包含多个子产品的聚合包。为了保证数据流转的安全,我们需要利用 TypeScript 的 Interface 来严格定义结构。
1. 定义核心数据契约
TypeScript
jsx
// types/tianyuan.ts
// API 请求参数
export interface RiskCheckRequest {
name: string;
id_card: string;
mobile_no: string;
authorization_url: string; // 必填:授权书链接
}
// 核心:司南报告数据结构 (DWBG6A2C)
export interface SinanReportData {
baseInfo: {
name: string;
age: number;
phoneArea: string;
status: number; // 0:空号 1:实号 4:沉默号 5:风险号
};
securityInfo: {
front: number; // 前科
drug: number; // 涉毒
escape: number; // 在逃
ikey: number; // 重点人员
};
riskPoint: {
judicialRisk: number; // 司法涉诉
multiQuery: number; // 多头借贷
};
rentalBehavior: {
// 租赁申请频次,用于分析稳定性
rentalApplicationCountLast3Months: string;
rentalApplicationInstitutionsLast12Months: string;
};
riskList: {
courtViolator: number; // 法院被执行
industryBlacklist: number; // 行业黑名单
};
}
// UI 视图模型 (清洗后的数据)
export interface NannyProfileViewModel {
isVerified: boolean; // 是否实名
safetyBadges: string[]; // 安全徽章 ["无犯罪记录", "身份核验通过"]
stabilityScore: number; // 稳定性评分 (0-100)
riskAlerts: string[]; // 风险提示 (仅管理员可见)
}
Node.js 集成与数据清洗 (Transformer)
在 BFF 层,我们需要完成从 API Response 到 ViewModel 的转换。
2. Service 层实现
TypeScript
jsx
import axios from 'axios';
import { RiskCheckRequest, SinanReportData, NannyProfileViewModel } from './types/tianyuan';
const API_URL = 'https://api.tianyuanapi.com/api/v1/COMBTY15';
// 模拟加密工具
const encryptData = (data: any) => Buffer.from(JSON.stringify(data)).toString('base64');
export const fetchAndTransformProfile = async (
candidate: RiskCheckRequest
): Promise<NannyProfileViewModel | null> => {
try {
// 1. 调用天远接口
const timestamp = Date.now();
const payload = { data: encryptData(candidate) };
const { data } = await axios.post(`${API_URL}?t=${timestamp}`, payload);
// 2. 提取司南报告 (DWBG6A2C)
const reportItem = data.responses?.find((r: any) => r.api_code === 'DWBG6A2C');
if (!reportItem || !reportItem.success || !reportItem.data) {
throw new Error('Risk report not found');
}
const rawData = reportItem.data as SinanReportData;
// 3. 执行数据清洗与标签生成
return transformToViewModel(rawData);
} catch (error) {
console.error('Background check failed:', error);
return null;
}
};
// 核心转换逻辑:将数据转为 UI 标签
const transformToViewModel = (data: SinanReportData): NannyProfileViewModel => {
const badges: string[] = [];
const alerts: string[] = [];
// A. 安全维度 (Security)
const sec = data.securityInfo;
if (sec.front === 0 && sec.drug === 0 && sec.escape === 0 && sec.ikey === 0) {
badges.push('无犯罪记录承诺');
badges.push('公安背景核验通过');
} else {
alerts.push('命中公安重点人员库');
}
// B. 诚信维度 (Integrity)
if (data.riskList.courtViolator === 0 && data.riskPoint.judicialRisk === 0) {
badges.push('无司法诉讼记录');
} else {
alerts.push('存在司法涉诉或被执行记录');
}
// C. 稳定性计算 (Stability Logic)
// 解析租赁频次:如果近3个月频繁申请租赁,说明居无定所
let stability = 100;
const recentRentals = parseInt(data.rentalBehavior.rentalApplicationCountLast3Months || '0');
if (recentRentals > 5) {
stability -= 30;
alerts.push('近期居住地变动频繁');
}
// 手机号状态检查
if (data.baseInfo.status === 4 || data.baseInfo.status === 5) {
stability -= 40;
alerts.push('联系方式异常(沉默号/风险号)');
}
return {
isVerified: true,
safetyBadges: badges,
stabilityScore: Math.max(0, stability),
riskAlerts: alerts
};
};
深度解析:租赁行为与稳定性的关联
在家政行业,阿姨的稳定性 是雇主极其看重的指标(谁也不想刚习惯一个月嫂就换人)。天远接口独有的 rentalBehavior 数据为了解阿姨的生活状态提供了绝佳窗口。
1. 居住稳定性画像
- 字段 :
rentalApplicationCountLast3Months(近3个月租赁申请次数) 。 - 分析 :
- 低频 (0-1次): 居住稳定,适合推荐"长期住家"或"包月保洁"岗位。
- 高频 (>5次): 可能正在频繁找房、搬家,或者从事与租房相关的黑产。此类人员在服务期间突然离职的风险较高。
- 夜间申请 :
rentalApplicationCountLast3DaysNight。若夜间频繁申请,需警惕其生活作息是否规律,是否适合照顾婴儿。
2. 身份伪冒风险
- 字段 :
riskList.identityFake和riskList.riskPhoneNumber。 - 分析 : 家政行业存在"买证上岗"的乱象。如果
identityFake为 1,说明该身份证号在网络上可能已被标记为虚假或冒用。此时前端应直接展示"认证失败",禁止接单。
业务价值延伸:动态标签系统
基于上述清洗逻辑,我们可以在 App 端实现动态标签展示:
- 金牌认证徽章 : 当
safetyBadges包含"无犯罪记录承诺"且stabilityScore > 90时,自动点亮。 - 高危预警弹窗 : 当运营人员在后台查看阿姨详情时,如果
riskAlerts非空,以红色 Banner 醒目展示(例如:"该人员涉及司法纠纷,请谨慎派单")。 - 智能匹配 : 算法在派单时,优先将
stabilityScore高的人员匹配给"包年/包季"的 VIP 客户。
结语
通过 Node.js 与 TypeScript 的结合,我们不仅实现了对 天远家政风险报告 接口的类型安全调用,更重要的是建立了一套**"数据翻译机制"**。
这套机制将冷冰冰的 API 字段(如 rentalBehavior、securityInfo)转化为了雇主能看懂、平台能运营的 "信任资产"。在高度依赖信任的家政行业,这正是技术驱动业务增长的最佳实践。