全部产品
Search
文档中心

风险识别:设备风险 SDK 抖音小程序接入

更新时间:Aug 26, 2026

本文档介绍了设备风险SDK (抖音小程序)的接入流程,在需要保护的应用中嵌入小程序 SDK。

背景信息

抖音小程序SDK是专为小程序环境设计的设备风险识别工具,通过嵌入SDK,开发者可以快速集成设备指纹能力,实时获取设备信息并联动风险识别服务。该SDK支持多种场景,如注册、登录、营销活动等,有效防范黑产攻击,提升业务安全性。

SDK集成指南

引入小程序 SDK

下载抖音小程序SDK,建议在小程序的首屏加载index页面引入SDK,并将AliyunFP对象全局挂载,方便别的页面调用。

import * as AliyunFP from './feilin.tiktok.xxxx.js';
const app = getApp();
app.AliyunFP = AliyunFP;

添加配置信息

在调用小程序SDK 接口前,需在对应的 ttml 中加入feilin-view节点:

<view>
  <view> 业务的 UI 布局 </view>
  
  <view id = "feilin-view" style="position:fixed;top:99999rpx;"> 
    <canvas id="feilin-canvas" type="2d" style="width:150px;height:150px;"></canvas> 
    <canvas id="feilin-webgl" type="webgl" style="width:150px;height:150px;"></canvas>
  </view>
</view>

初始化SDK

引入小程序 SDK之后,在页面加载onReady时初始化SDK。

App({
  onReady() {
    AliyunFP.init({
      appKey: '这里填写风险识别控制台申请的AppKey',
      appName: '这里填小程序应用名称,客户自定义',
      openId: '小程序用户ID,非必填,建议传入',
      endpoints: ['https://cloudauth-device.ap-southeast-1.aliyuncs.com']
    }, (initStatus, deviceToken) => {
      console.log("initStatus:" + initStatus + "  deviceToken:" + deviceToken);
    });
  }
});
重要

如果不指定服务地址,则endpoints会读取默认配置。请务必将endpoints的域名添加至小程序后台白名单,以确保相关功能正常运行。

endpoints可选服务地址:

地域

地址

新加坡(默认)

https://cloudauth-device.ap-southeast-1.aliyuncs.com

香港

https://cloudauth-device.cn-hongkong.aliyuncs.com

德国

https://cloudauth-device.eu-central-1.aliyuncs.com

美国

https://cloudauth-device.us-west-1.aliyuncs.com

获取deviceToken

获取 deviceToken,建议用 AliyunFP.init 接口回调返回的值,或者在发起业务行为(如注册、登录、订购等)时主动调用 AliyunFP.getToken 获取,AliyunFP.getToken 和 AliyunFP.init 之间至少预留1s左右的时间差。

AliyunFP.getToken()

//传入bizId,可以将本次 token 和业务唯一认证 ID 绑定。
AliyunFP.getToken(bizId)

接入示例

页面结构

<view>
  <view class="page-description"> {{ message }} </view>
  <button type="primary" onTap="onLogin">登录</button> 

  <view id = "feilin-view" style="position:fixed;top:99999rpx;"> 
    <canvas id="feilin-canvas" type="2d" style="width:150px;height:150px;"></canvas> 
    <canvas id="feilin-webgl" type="webgl" style="width:150px;height:150px;"></canvas>
  </view>
</view>

逻辑实现

import * as AliyunFP from './feilin.tiktok.xxxx.js';
const app = getApp();
app.AliyunFP = AliyunFP;

Page({
  onReady() {
    AliyunFP.init({
      appKey: '这里填写风险识别控制台申请的AppKey',
      appName: '这里填小程序应用名称,客户自定义',
      openId: '小程序用户ID,非必填,建议传入',
      endpoints: ['https://cloudauth-device.ap-southeast-1.aliyuncs.com']
    }, (initStatus, deviceToken) => {
      console.log("initStatus:" + initStatus + "  deviceToken:" + deviceToken);
    });
  },
  onLogin() {
    //某行为点击,这里举例为登录。
    console.info("onLogin!");
    const deviceToken = AliyunFP.getToken();
    //将deviceToken传入客户的服务后台
    const data = {
      "deviceToken": deviceToken,
      "其他业务参数": ""
    };
    //发送后台请求...后台通过deviceToken查询风险信息
  }
});

调用风险识别 API 接口

将 deviceToken 与其他参数,参考设备风险识别API接入说明,请求风险识别 API 接口进行识别。

常见问题

关于设备风控服务端接的常见问题,请参见 设备风控服务接入常见问题