The Device Fraud Detection SDK is used to collect device fingerprints and generate a device risk identifier (deviceToken) in TikTok Mini Programs. This topic describes how to download the SDK, complete the initialization configuration, obtain the deviceToken, and call the Fraud Detection API. The SDK is applicable to business scenarios such as registration, login, and marketing campaigns.
Background
The TikTok Mini Program SDK is a device risk detection tool designed specifically for the mini program environment. By embedding the SDK, developers can quickly integrate device fingerprinting capabilities, obtain real-time device information, and connect with the Fraud Detection service. The SDK supports multiple scenarios such as registration, login, and marketing campaigns to effectively prevent fraudulent activities and enhance business security.
SDK integration guide
-
Download and import the Mini Program SDK
Download the TikTok Mini Program SDK. We recommend that you import the SDK on the index page (the first-screen loading page of the mini program) and mount the AliyunFP object globally so that other pages can access it.
import * as AliyunFP from './feilin.tiktok.xxxx.js'; const app = getApp(); app.AliyunFP = AliyunFP; -
Add configuration information
Before calling the Mini Program SDK interfaces, add the feilin-view node to the corresponding TTML file:
<view> <view> Business UI layout </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> -
Initialize the SDK
After importing the Mini Program SDK, initialize the SDK in the onReady lifecycle of the page.
appKeyidentifies your application. You can obtain it from Device App Management in the Alibaba Cloud console.App({ onReady() { AliyunFP.init({ appKey: 'Identifies your application. Obtain from Device App Management in the console', appName: 'Your mini program name', openId: 'Mini program user ID, optional but recommended', endpoints: ['https://cloudauth-device.ap-southeast-1.aliyuncs.com'], }, (initStatus, deviceToken) => { console.log("initStatus:" + initStatus + " deviceToken:" + deviceToken); }); } });ImportantIf the service address is not specified, endpoints uses the default configuration. Make sure to add the domain names in endpoints to the request allowlist in the TikTok Mini Program backend. Otherwise, the SDK cannot send requests to the server.
Default endpoint addresses:
Region
Default endpoint
Singapore
China (Hong Kong)
Germany (Frankfurt)
US (Silicon Valley)
-
Obtain the deviceToken
To obtain the deviceToken, we recommend that you use the value returned by the
AliyunFP.initcallback. You can also callAliyunFP.getTokenwhen a user triggers a business action such as registration, login, or placing an order.AliyunFP.getTokenandAliyunFP.initmust have at least a 1-second interval between them.AliyunFP.getToken() // Pass bizId to bind this token to a unique business identifier AliyunFP.getToken(bizId)
Integration example
Page structure (TTML)
<view>
<view class="page-description"> {{ message }} </view>
<button type="primary" onTap="onLogin">Log on</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>
Logic implementation (js)
import * as AliyunFP from './feilin.tiktok.xxxx.js';
const app = getApp();
app.AliyunFP = AliyunFP;
Page({
onReady() {
AliyunFP.init({
appKey: 'Identifies your application. Obtain from Device App Management in the console',
appName: 'Your mini program name',
openId: 'Mini program user ID, optional but recommended',
endpoints: ['https://cloudauth-device.ap-southeast-1.aliyuncs.com'],
}, (initStatus, deviceToken) => {
console.log("initStatus:" + initStatus + " deviceToken:" + deviceToken);
});
},
onLogin() {
// Triggered on login tap
console.info("onLogin!");
const deviceToken = AliyunFP.getToken();
// Pass the deviceToken to your backend
const data = {
"deviceToken": deviceToken,
"Other business parameters": ""
};
// Send the backend request. The backend uses the deviceToken to query risk information.
}
});
Call the Fraud Detection API
After you obtain the deviceToken, submit the deviceToken along with other business parameters to the Fraud Detection API based on API integration.