Call the Fraud Detection server-side API to detect device risks such as emulators, root access, and multi-instance environments during critical business operations. This topic covers the request parameters, response parameters, error codes, and SDK integration for the device risk identification service (Basic Edition and Enhanced Edition). Applicable scenarios include campaign anti-fraud, account security protection during registration and logon, and coupon collection.
Editions
Device risk identification is available in two editions to meet the risk control requirements of different industries and business stages. The following table compares the Basic Edition and Enhanced Edition.
Feature | Basic Edition | Enhanced Edition |
Real-time computing | Supported | Supported |
Service response | Risk tags | Risk tags and unique device ID |
Simple Log Service (SLS) delivery | Not supported | Supported. You can authorize log delivery with free storage for one year. |
Select an edition
Basic Edition: Suitable for scenarios that require only risk tag determination, such as identifying whether a device is an emulator, rooted, or running in a multi-instance environment.
Enhanced Edition: Suitable for scenarios that require a unique device ID for cross-session tracking, or log delivery to SLS for in-depth analysis.
Prerequisites
Before you begin, ensure that the following prerequisites are met:
The device risk identification service is activated.
An AccessKey ID and an AccessKey secret are obtained. Use a RAM user for API access instead of the AccessKey pair of your Alibaba Cloud account.
The client SDK is integrated. For more information, see SDK for Android.
Technical workflow
After integrating the device SDK, call the server-side API of the Fraud Detection device risk identification service during critical business operations to obtain risk detection results. A single risk detection workflow consists of the following steps:
Initialize the SDK: Asynchronously initialize the SDK when the app starts to collect and report basic device fields. Depending on the system and device model, this process typically takes 2 to 5 seconds.
Obtain the device token: Call the SDK local method to obtain the deviceToken.
Call the server-side API: Pass the deviceToken and other business fields (refer to the specific event definition). The cloud detection model computes and returns the detection result in real time.

Input parameters
Service parameter
The Service parameter specifies the service edition. Different editions use the following Service parameter values.
Edition | Service Parameter Value | Feature |
Basic Edition | device_risk | Supports risk tags |
Enhanced Edition | device_risk_pro | Supports unique device ID, risk tags, and log delivery |
ServiceParameters
ServiceParameters contains the business request parameters in JSON format, corresponding to the ServiceParameters field in Common parameters. The following table describes the request parameters for the device risk identification service (both Basic Edition and Enhanced Edition).
Field | Description | Data Type | Example | Required | Remarks |
deviceToken | The deviceToken obtained from SDK for Android | String | Tk9SSUQuMS*********************ZDNmNWY5NzQxOW1oLTE2MjI2NDIyNjc4MzAtZGZWFhdDgzMTBLUlVSU0VoWWVNcW82ZkZlZWmp3PT0= | Yes | Under normal conditions, the token length is approximately 600 bytes. In poor network conditions, the token length may exceed 2.5 KB. |
deviceTokenBizId | The business-specific unique ID. | String | aes9ad0356da4df8c1f18bc349296d60 | No | Pass this bizId when obtaining the deviceToken from the client SDK to bind the deviceToken to the business-specific unique ID. When querying results on the server side, pass both values together. Ensure that the bizId from the client matches the ID from the server to prevent deviceToken replacement. |
Response parameters
The response parameters of the device risk identification service include the device ID and device risk tags.
{
"code": 200,
"message": "OK",
"data": {
"extend": "71d4ac517192c5309400548bf0d5357b",
"tags": "is_rooted,is_emulator"
},
"requestId": "AF17EC99-22AB-311E-1397-BCF37EC78C81"
}Device ID
The extend field in the Data object contains the unique device ID. Only the Enhanced Edition returns this field.
Device risk tags
The tags field in the Data object contains the risk detection results. If multiple tags are returned, they are separated by commas. The following table lists some common tags.
Value | Description |
is_emulator | The device is suspected to be an emulator. |
is_rooted | The device is suspected to be rooted. |
is_virtual | The device is suspected to be running in a multi-instance environment. |
... | Log on to the Fraud Detection console to view more device tag descriptions. |
For more information, see Common response parameters.
Error codes
Code | Description |
200 | The request is successful. |
400 | The ServiceParameters (event parameters) value is invalid. |
402 | The QPS exceeds the purchased quota. The request is throttled. |
403 | Insufficient permissions. The service is not activated or has expired. |
404 | The Service (service parameter) value is invalid. |
500 | An internal server error occurred. |
SDK integration
For the complete integration demo, see SDK for Android. The following example uses the Java SDK.
Maven dependencies
Add the following Java Maven dependency:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-saf</artifactId>
<version>3.0.1</version>
</dependency>Recommended dependency arbitration:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<optional>true</optional>
<version>4.5.25</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.68.noneautotype</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<version>0.31.0</version>
</dependency>Java SDK source code
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations.
// Use a RAM user for API access and daily O&M.
// Do not save the AccessKey ID and AccessKey secret in your project code to prevent AccessKey leakage,
// which may compromise the security of all resources under your account.
// This example uses environment variables to read the RAM user AccessKey for API authentication.
// Before running this code, make sure the following environment variables are configured:
// ALIBABA_CLOUD_ACCESS_KEY_ID, ALIBABA_CLOUD_ACCESS_KEY_SECRET.
// Create and initialize a DefaultAcsClient instance. Initialize only once.
DefaultProfile profile = DefaultProfile.getProfile(
"cn-shanghai", // Region ID. cn-shanghai is recommended for the China site. Must match the client SDK reporting domain.
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), // RAM user AccessKey ID
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") // RAM user AccessKey secret
);
// HTTP connection pool configuration
HttpClientConfig clientConfig = HttpClientConfig.getDefault();
clientConfig.setMaxRequestsPerHost(6);
clientConfig.setMaxIdleConnections(20);
// HTTP timeout configuration
clientConfig.setReadTimeoutMillis(10000);
clientConfig.setConnectionTimeoutMillis(3000);
profile.setHttpClientConfig(clientConfig);
IAcsClient client = new DefaultAcsClient(profile);
// Send the request
ExecuteRequestRequest executeRequestRequest = new ExecuteRequestRequest();
// To specify a custom version number, modify it here. Default: 2019-05-21
executeRequestRequest.setVersion("2019-05-21");
// Specify the request method
executeRequestRequest.setSysMethod(MethodType.POST);
// Specify the protocol. Currently, only HTTPS is supported.
executeRequestRequest.setSysProtocol(ProtocolType.HTTPS);
// Product code for the device risk identification service: device_risk or device_risk_pro.
// See the Service parameter row in the "Editions" table.
String service = "device_risk_pro";
executeRequestRequest.setService(service);
// Business parameters. Set only the parameters you need.
Map<String, Object> serviceParams = new HashMap<String, Object>();
// deviceToken is required.
serviceParams.put("deviceToken", "TK******************");
executeRequestRequest.setServiceParameters(JSONObject.toJSONString(serviceParams));
executeRequestRequest.setAcceptFormat(FormatType.JSON);
try {
ExecuteRequestResponse httpResponse = client.getAcsResponse(executeRequestRequest);
System.out.println("httpResponse:" + JSONObject.toJSONString(httpResponse));
} catch (Exception e) {
e.printStackTrace();
}Verify the call result
After sending a request through the SDK, verify the integration by checking the following:
A response with
Code=200indicates that the request is successful.The
Dataobject contains thetagsfield, which confirms that the device risk detection result is returned.
If a large number of long tokens (longer than 2.5 KB) are generated, first check whether the client network is stable, then ensure that the interval between calling the SDK init and getSession methods is greater than 2 seconds.
Supported regions
The REGION-ID parameter must match the device risk SDK reporting domain.
Region | Description |
cn-shanghai | China (Shanghai). Default for China site. |