All Products
Search
Document Center

Fraud Detection:Device fraud detection SDK for Alipay mini program

Last Updated:Nov 05, 2025

This topic provides detailed information about the integration process and technical specifications of the device fraud detection SDK (Alipay mini program version) in Fraud Detection. It helps developers quickly integrate device risk identification capabilities to effectively prevent device spoofing, batch registration, malicious logon, and other risky behaviors.

Background information

The SDK for Alipay mini program is a device risk identification tool specifically designed for the mini program environment. By embedding the SDK, developers can quickly integrate device fingerprinting capabilities, obtain device information in real time, and connect with Fraud Detection services. This SDK supports various scenarios such as registration, logon, marketing campaigns, and effectively prevents attacks from fraudulent operations while improving business security. For more information, see Alipay mini program.

SDK integration guide

  1. Download and import the mini program SDK

    Download the Alipay mini program SDK. We recommend importing the SDK in the first screen loading index page of the mini program and mounting the AliyunFP object globally for other pages to call.

    import * as AliyunFP from './feilin.alipay.xxx.js';
    const app = getApp();
    app.AliyunFP = AliyunFP;
  2. Add configuration information

    Before calling the mini program SDK interface, you need to add the feilin-view node in the corresponding axml:

    <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>
  3. Initialize the SDK

    After importing the mini program SDK, initialize the SDK when the page loads in onReady.

    Page({
      onReady() {
        AliyunFP.init(
          {
            appKey: 'Fill in the AppKey applied from the Fraud Detection console',
            appName: 'Fill in the mini program application name, customized by the customer',
            openId: 'Alipay mini program user ID, optional but recommended',
            endpoints: [
              'https://cloudauth-device.aliyuncs.com',
              'https://cn-shanghai.device.saf.aliyuncs.com'
            ],
          },
          (initStatus, deviceToken) => {
            console.log("initStatus:" + initStatus + "  deviceToken:" + deviceToken);
          }
        );
      }
    });
    Important

    If the service address is not specified, endpoints will read the default configurations. Make sure to add the endpoints domains to the mini program backend whitelist to ensure the related features work properly.

    Default endpoints addresses:

    • The Chinese mainland (default) endpoints: https://cloudauth-device.aliyuncs.com, https://cn-shanghai.device.saf.aliyuncs.com

    • International/Hong Kong (China) endpoints: https://cloudauth-device.ap-southeast-1.aliyuncs.com, https://ap-southeast-1.device.saf.aliyuncs.com

  4. Get deviceToken

    To obtain the deviceToken, we recommend using the value returned by the AliyunFP.init interface callback, or calling it once when initiating business behaviors (such as registration, logon, ordering). Allow at least 1 second time difference between AliyunFP.getToken and AliyunFP.init.

    AliyunFP.getToken()

Integration example

Page structure (axml)

<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.alipay.xxx.js';
const app = getApp();
app.AliyunFP = AliyunFP;


Page({
  onReady() {   
    AliyunFP.init({
      appKey: 'Fill in the AppKey applied from the Fraud Detection console',
      appName: 'Fill in the mini program application name, customized by the customer',
      openId: 'Alipay mini program user ID, optional but recommended',
      endpoints: ['https://cloudauth-device.aliyuncs.com', 'https://cn-shanghai.device.saf.aliyuncs.com']
    }, (initStatus, deviceToken) => {
      console.log("initStatus:" + initStatus + "  deviceToken:" + deviceToken);
    });
  },
  
  onLogin() {
    // Behavior click, login as an example here.
    console.info("onLogin!");
    const deviceToken = AliyunFP.getToken();
    // Pass deviceToken to the customer's service backend
    const data = {
      "deviceToken": deviceToken,
      "Other business parameters": ""
    };
    // Send backend request... backend queries risk information through deviceToken
  }
});

Notes

  1. Security: Developers should ensure that the data transmitted when calling the Fraud Detection API operations is secure to prevent data breach or tampering.

  2. Compatibility: The Alipay mini program device risk control SDK may have compatibility issues in different versions of Alipay mini programs. Developers need to pay attention to the update dynamics of Alipay mini programs and make corresponding adaptations.

  3. Performance: Since the device risk control function needs to collect and calculate data on the device, it may have an impact on the performance of the application. Developers need to conduct Performance Testing and optimization in actual applications to ensure the low definition and user experience of the application.

Call Fraud Detection API operations

According to the event parameter documentation of the Fraud Detection service, combine the deviceToken with other necessary parameters to call the Fraud Detection API operations for device risk detection. For more information, see: