注释:该 API 仅用于预览用途并会随时更改。
设备数据收集
当与订单和交易详细信息相结合时,设备数据(IP 地址、设备 Id、地理位置信息等)会是欺诈的重要标志,或通过 GeoIP 查找创建基于位置的手动规则。利用具有 Access FraudSight 功能的设备数据需要两个步骤。第一步是收集设备数据。第二步是提交将使用设备数据进行评估的
ThreatMetrix Android SDK
ThreatMetrix Android SDK 为手机应用程序开发人员提供了特定于 Android 的库。它利用 ThreatMetrix 平台实时检测来自移动设备的欺诈和安全漏洞。
此说明适用于 ThreatMetrix SDK V6-2 版本。
实施概述
将 ThreatMetrix SDK 加入应用程序中。
调用
init()
方法,初始化 SDK。调用
profile()
方法,开始进行设备分析。ThreatMetrix SDK 会将收集到的属性和唯一 sessionId 传输到 ThreatMetrix 平台。在 FraudSight 评估请求中应用
sessionId
,使其成为风险评估的一部分。
如何获取 SDK
注释:该产品即将发布,此文档仅供预览
加入的模块
TMXProfiling:此模块负责以独有方式执行分析。它不会通过网络传输任何内容,因此模块本身不发送或接收数据。您必须将此模块与 TMXProfilingConnections 模块或自定义分析连接模块配对,以便向后端发送以及从后端接收数据,进而成功分析。
TMXProfilingConnections:它是 ThreatMetrix 提供的默认网络模块。此模块仅通过网络传输数据,而不会更改数据。
将 TMXProfiling 和 TMXProfilingConnections 模块的 AAR 文件加入 app/libs
文件夹中。然后将这些依赖项添加到您的应用级别 build.gradle
文件中。
implementation files('libs/TMXProfiling-6.2-107.aar')
implementation files('libs/TMXProfilingConnections-6.2-107.aar')
implementation files('libs/TMXProfiling-6.2-107.aar') implementation files('libs/TMXProfilingConnections-6.2-107.aar')
权限
强制权限
您必须在应用程序的清单文件中加入以下权限。
<uses-permission android:name="android.permission.INTERNET" \/>
<uses-permission android:name="android.permission.INTERNET" \/>
可选权限
注释:这些权限将在最终用户的手机上显示一个弹出窗口,用于授予访问权限。
<uses-permission android:name="android.permission.READ_PHONE_STATE"/\>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/\>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/\>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/\>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/\>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/\> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/\>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/\> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/\> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/\>
使用 ThreatMetrix SDK
分析
分析是 ThreatMetrix 通过网站或本机应用程序收集有关访问客户在线服务的设备信息的机制。
确定本机应用程序中为分析提供最佳机会的屏幕。大多数分析都是在短时间内完成的,收集全套分析属性可能需要 5 秒钟。
我们可以启动分析的常见屏幕为账户创建屏幕、付款屏幕和登录屏幕。
所需的详情
若要创建配置实例,请将以下详细信息传至 init() 方法。
占位符 | 描述 |
---|---|
ORG_ID |
|
FP_SERVER |
|
获取实例并初始化
ThreatMetrix SDK 在启动时通过调用使用 Config 对象配置的 init() 功能进行异步初始化。
您必须至少指定 Context
、Org ID
和 FP server/Profiling domain
。TMXProfiling 类的 getInstance()
方法用于返回 ThreatMetrix 对象的单例实例。该实例只需要初始化一次。
下方为示例,说明如何获取实例并初始化以进行分析。
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username: EditText = findViewById(R.id.editTextUsername)
val password: EditText = findViewById(R.id.editTextPassword)
/* Creating a config instance to be passed to the init() method. This instance must
include orgId and application context otherwise the init()method will fail. */
var config = TMXConfig()
//(REQUIRED) Organization ID
.setOrgId(ORG_ID)
// (REQUIRED) FPserver/Profiling domain
.setFPServer(FP_SERVER)
// (REQUIRED) Application Context
.setContext(applicationContext)
// (Optional) Register for location services
// Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
.setRegisterForLocationServices(true)
/*Getting instance of ThreatMatrix object by passing config object to it*/
TMXProfiling.getInstance().init(config)
/*Once the valid instance is created for further calls, fire a profile
request*/
doProfile()
}
}
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val username: EditText = findViewById(R.id.editTextUsername) val password: EditText = findViewById(R.id.editTextPassword) /* Creating a config instance to be passed to the init() method. This instance must include orgId and application context otherwise the init()method will fail. */ var config = TMXConfig() //(REQUIRED) Organization ID .setOrgId(ORG_ID) // (REQUIRED) FPserver/Profiling domain .setFPServer(FP_SERVER) // (REQUIRED) Application Context .setContext(applicationContext) // (Optional) Register for location services // Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission .setRegisterForLocationServices(true) /*Getting instance of ThreatMatrix object by passing config object to it*/ TMXProfiling.getInstance().init(config) /*Once the valid instance is created for further calls, fire a profile request*/ doProfile() } }
public class LoginActivity extends Activity
{
private EditText username;
private EditText password;
@Override
protected void onCreate(Bundle savedInstanceState)
{
username = findViewById(R.id.editTextUsername);
password = findViewById(R.id.editTextPassword);
/* Creating a config instance to be passed to the init() method. This instance
must include orgId and application context otherwise the init() method will
fail. */
TMXConfig config = new TMXConfig()
//(REQUIRED) Organization ID
.setOrgId(ORG_ID)
// (REQUIRED) FPserver/Profiling domain
.setFPServer(FP_SERVER)
// (REQUIRED) Application Context
.setContext(getApplicationContext())
// (Optional) Register for location services
// Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
.setRegisterForLocationServices(true);
/*Getting instance of ThreatMatrix object by passing config object to it*/
TMXProfiling.getInstance().init(config);
/*Once the valid instance is created , call your code which starts profiling */
doProfile();
}
}
public class LoginActivity extends Activity { private EditText username; private EditText password; @Override protected void onCreate(Bundle savedInstanceState) { username = findViewById(R.id.editTextUsername); password = findViewById(R.id.editTextPassword); /* Creating a config instance to be passed to the init() method. This instance must include orgId and application context otherwise the init() method will fail. */ TMXConfig config = new TMXConfig() //(REQUIRED) Organization ID .setOrgId(ORG_ID) // (REQUIRED) FPserver/Profiling domain .setFPServer(FP_SERVER) // (REQUIRED) Application Context .setContext(getApplicationContext()) // (Optional) Register for location services // Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission .setRegisterForLocationServices(true); /*Getting instance of ThreatMatrix object by passing config object to it*/ TMXProfiling.getInstance().init(config); /*Once the valid instance is created , call your code which starts profiling */ doProfile(); } }
开始分析
创建一个方法以开始分析,并发送一些附加属性以及分析信息。下方为开始分析的方法的代码示例。
fun doProfile(){
/*(OPTIONAL) Assign some custom attributes to be included along with the
profiling Information*/
val list = listOf("attribute 1", "attribute 2")
var options: TMXProfilingOptions = TMXProfilingOptions()
.setCustomAttributes(list)
//Start the profiling request
/*The instance of TMXEndNotifier must be passed to the profile() method, the
CompletionNotifier is an implementation of TMXEndNotifier which is explained
in obtaining profiling result section*/
TMXProfiling.getInstance()
.profile(options, CompletionNotifier())
}
fun doProfile(){ /*(OPTIONAL) Assign some custom attributes to be included along with the profiling Information*/ val list = listOf("attribute 1", "attribute 2") var options: TMXProfilingOptions = TMXProfilingOptions() .setCustomAttributes(list) //Start the profiling request /*The instance of TMXEndNotifier must be passed to the profile() method, the CompletionNotifier is an implementation of TMXEndNotifier which is explained in obtaining profiling result section*/ TMXProfiling.getInstance() .profile(options, CompletionNotifier()) }
void doProfile()
{
/*(OPTIONAL) Assign some custom attributes to be included along with the
profiling Information*/
List<String> list = Arrays.asList("attribute 1", "attribute 2");
TMXProfilingOptions options = new TMXProfilingOptions().setCustomAttributes(list);
//Start the profiling request
/*The instance of TMXEndNotifier must be passed to the profile() method, the
CompletionNotifier is an implementation of TMXEndNotifier which is explained
in obtaining profiling result section*/
TMXProfiling.getInstance()
.profile(options,new CompletionNotifier());
}
void doProfile() { /*(OPTIONAL) Assign some custom attributes to be included along with the profiling Information*/ List<String> list = Arrays.asList("attribute 1", "attribute 2"); TMXProfilingOptions options = new TMXProfilingOptions().setCustomAttributes(list); //Start the profiling request /*The instance of TMXEndNotifier must be passed to the profile() method, the CompletionNotifier is an implementation of TMXEndNotifier which is explained in obtaining profiling result section*/ TMXProfiling.getInstance() .profile(options,new CompletionNotifier()); }
获取分析结果和 sessionId
- 创建一个实施
TMXEndNotifier
界面的类别。 - 实施
complete()
方法。 - 如上所示,将该类的实例作为调用的一部分传至
profile()
方法。
分析完成后,将使用分析结果调用该实例的 complete()
方法。
使用 result.status/ result.getStatus()
方法了解分析状态。此方法在分析成功时会返回字符串 “Okay”。
下方为实施示例。
/* TMXEndNotifier implementation called when profiling is completed */
class CompletionNotifier: TMXEndNotifier {
/*This method gets called when the profiling has finished. Be careful here
because we are not going to be called on the UI thread, and if we want to
update UI elements we can only do it from the UI thread.*/
override fun complete(result: TMXProfilingHandle.Result) {
//Get the session id to use in API call (AKA session query)
val sessionID = result.sessionID
val status = result.status
}
}
/* TMXEndNotifier implementation called when profiling is completed */ class CompletionNotifier: TMXEndNotifier { /*This method gets called when the profiling has finished. Be careful here because we are not going to be called on the UI thread, and if we want to update UI elements we can only do it from the UI thread.*/ override fun complete(result: TMXProfilingHandle.Result) { //Get the session id to use in API call (AKA session query) val sessionID = result.sessionID val status = result.status } }
/* TMXEndNotifier implementation called when profiling is completed */
private class CompletionNotifier implements TMXEndNotifier
{
private String sessionID;
/*This method gets called when the profiling has finished. Be careful here
because we are not going to be called on the UI thread, and if we want to
update UI elements we can only do it from the UI thread.*/
@Override
public void complete(TMXProfilingHandle.Result result)
{
//Get the session id to use in API call (AKA session query)
sessionID = result.getSessionID();
result = result.getStatus();
}
}
/* TMXEndNotifier implementation called when profiling is completed */ private class CompletionNotifier implements TMXEndNotifier { private String sessionID; /*This method gets called when the profiling has finished. Be careful here because we are not going to be called on the UI thread, and if we want to update UI elements we can only do it from the UI thread.*/ @Override public void complete(TMXProfilingHandle.Result result) { //Get the session id to use in API call (AKA session query) sessionID = result.getSessionID(); result = result.getStatus(); } }
将设备数据与评估关联
在发送deviceData.collectionReference
。
后续步骤