All Products
Search
Document Center

Fraud Detection:WeChat Mini Program SDK Integration

Last Updated:Aug 26, 2026

This document describes the integration process for the Device Risk SDK (WeChat mini program), embedding the mini program SDK into applications that need protection.

Background information

The WeChat mini program SDK is a device risk identification tool designed for the mini program environment. By embedding the SDK, developers can quickly integrate device fingerprinting capabilities, obtain device information in real time, and use the risk identification service. The SDK supports multiple scenarios such as registration, login, and marketing campaigns, effectively defending against fraudulent activities and improving business security.

SDK integration guide

Download and import the mini program SDK

Download the WeChat mini program SDK. It is recommended to import the SDK on the index page that loads first, and mount the AliyunFP object globally for use by other pages.

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

Add configuration

Before calling mini program SDK interfaces, add the feilin-view node to the corresponding axml 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 it in the onReady page lifecycle.

Page({
 onReady() {
   AliyunFP.init(
     {
       appKey: 'Enter the AppKey applied for in the Fraud Detection console',
       appName: 'Enter the mini program name, defined by the customer',
       openId: 'WeChat mini program user ID, optional but recommended',
       endpoints: ['https://cloudauth-device.ap-southeast-1.aliyuncs.com']
     },(initStatus, deviceToken) => {
       console.log("initStatus:" + initStatus + "  deviceToken:" + deviceToken);
     }
   );
 }
});
Important

If you do not specify a service address, the endpoints parameter uses the default configuration. Make sure to add the endpoints domain name to the mini program backend whitelist to ensure proper functionality.

Optional service addresses for endpoints:

Region

Service address

Singapore (default)

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

Hong Kong

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

Germany

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

United States

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

Obtain the deviceToken

To obtain the deviceToken, use the value returned by the AliyunFP.init callback, or call AliyunFP.getToken when a business action starts (such as registration, login, or purchase). Allow at least 1 second between AliyunFP.getToken and AliyunFP.init.

AliyunFP.getToken()

//Pass bizId to bind this token to a unique business ID.
AliyunFP.getToken(bizId)

Integration example

Page structure

<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

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

Page({
 onReady() {
   // Page load complete
   console.info("onReady");
   AliyunFP.init({
     appKey: 'Enter the AppKey applied for in the Fraud Detection console',
     appName: 'Enter the mini program name, defined by the customer',
     openId: 'WeChat 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() {
   // A business action click, login is used as the example here.
   console.info("onLogin!");
   const deviceToken = AliyunFP.getToken();
   // Pass the deviceToken to the customer's business server
   const data = {
     "deviceToken": deviceToken,
     "otherBusinessParams": ""
   };
   // Send backend request... The server queries risk information using the deviceToken
 }
});

Call the Fraud Detection API

Pass the deviceToken and other parameters, refer to Server-side API integration, and call the Fraud Detection API for risk identification.

FAQ

For common questions about Device Fraud Detection integration, see FAQ.