数据脱敏(敏感信息掩码)

desensitizePOST
POSThttps://v1.apizero.cn/api/desensitize

概述

自动检测并脱敏文本中的手机号、身份证(15/18 位)、银行卡(16-19 位)、邮箱、中文姓名等敏感信息。支持按类型组合,纯本地正则匹配,毫秒级返回。默认不回显原文,避免日志泄漏。

调用约定

  • 网关 · https://v1.apizero.cn
  • 鉴权 · Authorization: Bearer <API Key>
  • 回包 · JSON {code, msg, data}。成功看 code === 0,不要只看 HTTP 200。
/aidocs/desensitize/raw.md
打开 Markdown

鉴权

匿名免登录可调,每日 50 次;登录用户每日 200 次。

获取 API Key

请求头

Authorizationstring选填

推荐:Bearer <API Key>。兼容请求头 X-API-Key,以及 Query api_key / apikey / key(key 仅当值为 sk_live_/sk_test_/sk_stag_ 形态时生效)。匿名可不传,受每日免费额度限制。

全部类型(推荐)

POSTFORM / QUERY / JSON·APPLICATION/JSON

types 默认 all,一次脱敏手机号 / 身份证 / 银行卡 / 邮箱 / 姓名。文档示例为真实调用。

https://v1.apizero.cn/api/desensitize?types=all&text=%E8%81%94%E7%B3%BB%E4%BA%BA%EF%BC%9A%E5%BC%A0%E5%85%88%E7%94%9F%EF%BC%8C%E6%89%8B%E6%9C%BA13800138000%EF%BC%8C%E8%BA%AB%E4%BB%BD%E8%AF%8111010519491231002X%EF%BC%8C%E5%8D%A1%E5%8F%B76222021234567890123%EF%BC%8C%E9%82%AE%E7%AE%B1zhangsan%40example.com&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例联系人:张先生,手机13800138000,身份证11010519491231002X,卡号6222021234567890123,邮箱zhangsan@example.com

typesstring选填

脱敏类型,此处固定 all(也支持逗号组合)

例all

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "all",
  "text": "联系人:张先生,手机13800138000,身份证11010519491231002X,卡号6222021234567890123,邮箱zhangsan@example.com",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

idcardnumber

idcard

bankcardnumber

bankcard

phonenumber

phone

emailnumber

email

namenumber

名称

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "联系人:张**,手机138****8000,身份证110105********002X,卡号6222 **** **** 0123,邮箱zh******@example.com",
    "detection_count": 5,
    "summary": {
      "idcard": 1,
      "bankcard": 1,
      "phone": 1,
      "email": 1,
      "name": 1
    },
    "detections": [
      {
        "type": "idcard",
        "masked": "110105********002X"
      },
      {
        "type": "bankcard",
        "masked": "6222 **** **** 0123"
      },
      {
        "type": "phone",
        "masked": "138****8000"
      },
      {
        "type": "email",
        "masked": "zh******@example.com"
      },
      {
        "type": "name",
        "masked": "张**"
      }
    ],
    "types_applied": [
      "phone",
      "idcard",
      "bankcard",
      "email",
      "name"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

手机号脱敏

POSTFORM / QUERY / JSON·APPLICATION/JSON

types=phone。保留前 3 + 后 4,中间 ****。

https://v1.apizero.cn/api/desensitize?types=phone&text=%E5%AE%A2%E6%9C%8D%E7%83%AD%E7%BA%BF%E8%AF%B7%E6%8B%A8%E6%89%9313800138000%E6%88%9613912345678%E8%81%94%E7%B3%BB&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例客服热线请拨打13800138000或13912345678联系

typesstring选填

脱敏类型,此处固定 phone(也支持逗号组合)

例phone

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "phone",
  "text": "客服热线请拨打13800138000或13912345678联系",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

phonenumber

phone

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "客服热线请拨打138****8000或139****5678联系",
    "detection_count": 2,
    "summary": {
      "phone": 2
    },
    "detections": [
      {
        "type": "phone",
        "masked": "138****8000"
      },
      {
        "type": "phone",
        "masked": "139****5678"
      }
    ],
    "types_applied": [
      "phone"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

身份证脱敏

POSTFORM / QUERY / JSON·APPLICATION/JSON

types=idcard。18 位保留前 6 + 后 4;15 位保留前 6 + 后 3。

https://v1.apizero.cn/api/desensitize?types=idcard&text=%E8%BA%AB%E4%BB%BD%E8%AF%81%E4%BB%B6%E5%8F%B7%E7%A0%81%EF%BC%9A11010519491231002X%EF%BC%8C%E8%AF%B7%E6%A0%B8%E5%AF%B9%E5%90%8E%E6%8F%90%E4%BA%A4&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例身份证件号码:11010519491231002X,请核对后提交

typesstring选填

脱敏类型,此处固定 idcard(也支持逗号组合)

例idcard

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "idcard",
  "text": "身份证件号码:11010519491231002X,请核对后提交",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

idcardnumber

idcard

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "身份证件号码:110105********002X,请核对后提交",
    "detection_count": 1,
    "summary": {
      "idcard": 1
    },
    "detections": [
      {
        "type": "idcard",
        "masked": "110105********002X"
      }
    ],
    "types_applied": [
      "idcard"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

银行卡脱敏

POSTFORM / QUERY / JSON·APPLICATION/JSON

types=bankcard。形如 6222 **** **** 0123(16–19 位)。

https://v1.apizero.cn/api/desensitize?types=bankcard&text=%E8%AF%B7%E5%90%91%E5%8D%A1%E5%8F%B76222021234567890123%E8%BD%AC%E8%B4%A6%EF%BC%8C%E5%A4%87%E7%94%A8%E5%8D%A16217001234567890123&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例请向卡号6222021234567890123转账,备用卡6217001234567890123

typesstring选填

脱敏类型,此处固定 bankcard(也支持逗号组合)

例bankcard

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "bankcard",
  "text": "请向卡号6222021234567890123转账,备用卡6217001234567890123",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

bankcardnumber

bankcard

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "请向卡号6222 **** **** 0123转账,备用卡6217 **** **** 0123",
    "detection_count": 2,
    "summary": {
      "bankcard": 2
    },
    "detections": [
      {
        "type": "bankcard",
        "masked": "6222 **** **** 0123"
      },
      {
        "type": "bankcard",
        "masked": "6217 **** **** 0123"
      }
    ],
    "types_applied": [
      "bankcard"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

邮箱脱敏

POSTFORM / QUERY / JSON·APPLICATION/JSON

types=email。本地名部分掩码,域名保留。

https://v1.apizero.cn/api/desensitize?types=email&text=%E8%AF%B7%E5%8F%91%E9%80%81%E6%9D%90%E6%96%99%E8%87%B3zhangsan%40example.com%E6%88%96support%40apizero.cn&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例请发送材料至zhangsan@example.com或support@apizero.cn

typesstring选填

脱敏类型,此处固定 email(也支持逗号组合)

例email

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "email",
  "text": "请发送材料至zhangsan@example.com或support@apizero.cn",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

emailnumber

email

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "请发送材料至zh******@example.com或su*****@apizero.cn",
    "detection_count": 2,
    "summary": {
      "email": 2
    },
    "detections": [
      {
        "type": "email",
        "masked": "zh******@example.com"
      },
      {
        "type": "email",
        "masked": "su*****@apizero.cn"
      }
    ],
    "types_applied": [
      "email"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

姓名脱敏

POSTFORM / QUERY / JSON·APPLICATION/JSON

types=name。仅识别带「联系人/收件人/先生/女士」等上下文的中文姓名,降低误伤。

https://v1.apizero.cn/api/desensitize?types=name&text=%E8%81%94%E7%B3%BB%E4%BA%BA%EF%BC%9A%E5%BC%A0%E5%85%88%E7%94%9F%EF%BC%9B%E6%94%B6%E4%BB%B6%E4%BA%BA%EF%BC%9A%E6%9D%8E%E5%A5%B3%E5%A3%AB&with_original=false

text(文本)string必填

要脱敏的文本,最长 50000 字节

例联系人:张先生;收件人:李女士

typesstring选填

脱敏类型,此处固定 name(也支持逗号组合)

例name

with_originalbool选填

是否在 detections 中回显原文,默认 false

例false

{
  "types": "name",
  "text": "联系人:张先生;收件人:李女士",
  "with_original": "false"
}

返回结果

masked_textstring

脱敏后的完整文本

detection_countinteger

识别到的敏感信息数量(去重)

summaryobject

按类型分组的命中数量

namenumber

名称

detectionsarray

命中明细 {type, masked, [original]};默认不含 original

typestring

类型

maskedstring

masked

types_appliedarray

本次实际启用的脱敏类型

types_applied[]string

types_applied 的一项

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

{
  "code": 0,
  "msg": "成功",
  "data": {
    "masked_text": "联系人:张**;收件人:李**",
    "detection_count": 2,
    "summary": {
      "name": 2
    },
    "detections": [
      {
        "type": "name",
        "masked": "张**"
      },
      {
        "type": "name",
        "masked": "李**"
      }
    ],
    "types_applied": [
      "name"
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}

请求示例

示例都是服务端写法。Python / JavaScript 各有常规写法和官方库。

curl -sS -X POST "https://v1.apizero.cn/api/desensitize" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "text": "<text>"
}'

错误码

先看业务 code。HTTP 也可能不是 200。

0200

成功

4000400

参数错误

4011401

API Key 无效

4013403

API Key 已暂停

4014403

当前 IP 不在 Key 白名单

4015401

此接口需要 API Key

4022402

余额不足

4029429

调用过快(QPS)

4030429

今日免费额度已用完

4040503

接口已下线

4041404

接口不存在

5000500

服务器内部错误

5020502

上游暂时不可用

5021502

上游返回格式异常

5030502

暂无可用节点

调用限制

计费模式
完全免费
QPS 限制
QPS 3
登录免费额度
200 次(已认证)
匿名每日额度
50 次(无 API Key)
黄金会员
每天 50,000 次 · QPS 10
钻石会员
每天 100,000 次 · QPS 30
企业会员
每天 1,000,000 次 · QPS 120

购买套餐、看评价请走商城详情。 购买 / 调试

更新日志

  • 1.0.02026-05-07

    首次上线 · 5 类敏感信息识别