This topic describes how to use an SDK to call Fraud Detection. This is a simple and convenient method to call API operations.
Use Fraud Detection SDK
When you use Fraud Detection SDK, you do not need to focus on complex processing such as signature verification and body format construction. We recommend that you use Fraud Detection SDK. Fraud Detection SDK supports Java, Python, PHP, C#, and Go.
Fraud Detection SDK for Java
Java Maven dependency:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-saf</artifactId>
<version>3.0.1</version>
</dependency>
Recommended Java Maven dependency manager:
<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>
Click URL 1 or URL 2 to download the Java Maven repository.
Source code:
Use the decision engine.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static com.aliyun.teaopenapi.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Specify your AccessKey ID.
.setAccessKeyId(accessKeyId)
// Required. Specify your AccessKey secret.
.setAccessKeySecret(accessKeySecret);
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.endpoint = "saf.ap-southeast-1.aliyuncs.com";
//SINGAPORE:ap-southeast-1,MALAYSIA:ap-southeast-3,INDONESIA:ap-southeast-5
return new com.aliyun.teaopenapi.Client(config);
}
/**
* API-related parameters
* @param path params
* @return OpenApi.Params
*/
public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {
com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
// The operation that you want to perform.
.setAction("RequestDecision")
// The version number of the operation.
.setVersion("2019-05-21")
// The protocol of the operation.
.setProtocol("HTTPS")
// The HTTP method of the operation.
.setMethod("POST")
.setAuthType("AK")
.setStyle("RPC")
// The URL of the operation.
.setPathname("/")
// The format of the request body.
.setReqBodyType("json")
// The format of the response body.
.setBodyType("json");
return params;
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be leaked and security issues may occur on all resources of your account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use Security Token Service (STS), which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378657.html.
com.aliyun.teaopenapi.Client client = Sample.createClient(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo();
// query params
java.util.Map<String, Object> queries = new java.util.HashMap<>();
queries.put("ServiceParameters", "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}");
queries.put("EventCode", "de_*****");
// runtime options
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
.setQuery(com.aliyun.openapiutil.Client.query(queries));
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
client.callApi(params, request, runtime);
}
}
Use scenario-specific risk control such as registration fraud detection and marketing fraud detection.
#!/usr/bin/env xcrun swift
import Cocoa
import Foundation
import Tea
import AlibabacloudOpenApi
import AlibabaCloudOpenApiUtil
import TeaUtils
open class Client {
public static func createClient(_ accessKeyId: String?, _ accessKeySecret: String?) throws -> AlibabacloudOpenApi.Client {
var config: AlibabacloudOpenApi.Config = AlibabacloudOpenApi.Config([
"accessKeyId": accessKeyId as! String,
"accessKeySecret": accessKeySecret as! String
])
config.endpoint = "saf.ap-southeast-1.aliyuncs.com"
return AlibabacloudOpenApi.Client(config)
}
public static func createApiInfo() -> AlibabacloudOpenApi.Params {
var params: AlibabacloudOpenApi.Params = AlibabacloudOpenApi.Params([
"action": "ExecuteRequestSG",
"version": "2019-05-21",
"protocol": "HTTPS",
"method": "POST",
"authType": "AK",
"style": "RPC",
"pathname": "/",
"reqBodyType": "json",
"bodyType": "json"
])
return params as! AlibabacloudOpenApi.Params
}
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public static func main(_ args: [String]?) async throws -> Void {
var client: AlibabacloudOpenApi.Client = try Client.createClient(ProcessInfo.processInfo.environment["ALIBABA_CLOUD_ACCESS_KEY_ID"], ProcessInfo.processInfo.environment["ALIBABA_CLOUD_ACCESS_KEY_SECRET"])
var params: AlibabacloudOpenApi.Params = Client.createApiInfo()
var queries: [String: Any] = [:]
queries["ServiceParameters"] = "{"email":"example@alibabacloud.com","ip":"x.x.x.x","deviceToken":"******"}";
queries["Service"] = "account_abuse_intl_pro";
var runtime: TeaUtils.RuntimeOptions = TeaUtils.RuntimeOptions([:])
var request: AlibabacloudOpenApi.OpenApiRequest = AlibabacloudOpenApi.OpenApiRequest([
"query": AlibabaCloudOpenApiUtil.Client.query(queries)
])
try await client.callApi(params as! AlibabacloudOpenApi.Params, request as! AlibabacloudOpenApi.OpenApiRequest, runtime as! TeaUtils.RuntimeOptions)
}
}
Client.main(CommandLine.arguments)
Fraud Detection SDK for Python
Download the source code of Fraud Detection SDK for Python.
Install the core library of Alibaba Cloud SDK for Python.
If you use Python 2.x, run the following commands to install the Alibaba Cloud SDK core library:
pip install aliyun-python-sdk-core
If you use Python 3.x, run the following commands to install the Alibaba Cloud SDK core library:
pip install aliyun-python-sdk-core-v3
Install Alibaba Cloud SDK for Python.
pip install aliyun-python-sdk-saf
Test case of Fraud Detection SDK for Python:
Use the decision engine.
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_tea_openapi.client import Client as OpenApiClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_openapi_util.client import Client as OpenApiUtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> OpenApiClient:
"""
Use your AccessKey ID and AccessKey secret to create a client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Specify your AccessKey ID.
access_key_id=access_key_id,
# Required. Specify your AccessKey secret.
access_key_secret=access_key_secret
)
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.endpoint = f'saf.ap-southeast-1.aliyuncs.com'
return OpenApiClient(config)
@staticmethod
def create_api_info() -> open_api_models.Params:
"""
API-related parameters
@param path: params
@return: OpenApi.Params
"""
params = open_api_models.Params(
# The operation that you want to perform.
action='RequestDecision',
# The version number of the operation.
version='2019-05-21',
# The protocol of the operation.
protocol='HTTPS',
# The HTTP method of the operation.
method='POST',
auth_type='AK',
style='RPC',
# The URL of the operation.
pathname=f'/',
# The format of the request body.
req_body_type='json',
# The format of the response body.
body_type='json'
)
return params
@staticmethod
def main(
args: List[str],
) -> None:
# Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
# If the project code is leaked, the AccessKey pair may be leaked and the security of resources within your account may be compromised. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378659.html.
client = Sample.create_client(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
params = Sample.create_api_info()
# query params
queries = {}
queries['ServiceParameters'] = '{"email":"example@alibabacloud.com","ip":"x.x.x.x","deviceToken":"******"}'
queries['EventCode'] = 'de_*****'
# runtime options
runtime = util_models.RuntimeOptions()
request = open_api_models.OpenApiRequest(
query=OpenApiUtilClient.query(queries)
)
# After you copy and run the sample code, use the following object to query the response data of the request:
# The return value is of the Map type, which can provide three types of data: response body, response header, and HTTP status code.
client.call_api(params, request, runtime)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Use scenario-specific risk control.
# -*- coding: utf-8 -*-
import os
import sys
from typing import List
from alibabacloud_tea_openapi.client import Client as OpenApiClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_openapi_util.client import Client as OpenApiUtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> OpenApiClient:
"""
Use your AccessKey ID and AccessKey secret to create a client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Specify your AccessKey ID.
access_key_id=access_key_id,
# Required. Specify your AccessKey secret.
access_key_secret=access_key_secret
)
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.endpoint = f'saf.ap-southeast-1.aliyuncs.com'
return OpenApiClient(config)
@staticmethod
def create_api_info() -> open_api_models.Params:
"""
API-related parameters
@param path: params
@return: OpenApi.Params
"""
params = open_api_models.Params(
# The operation that you want to perform.
action='ExecuteRequestSG',
# The version number of the operation.
version='2019-05-21',
# The protocol of the operation.
protocol='HTTPS',
# The HTTP method of the operation.
method='POST',
auth_type='AK',
style='RPC',
# The URL of the operation.
pathname=f'/',
# The format of the request body.
req_body_type='json',
# The format of the response body.
body_type='json'
)
return params
@staticmethod
def main(
args: List[str],
) -> None:
# Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
# If the project code is leaked, the AccessKey pair may be leaked and the security of resources within your account may be compromised. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378659.html.
client = Sample.create_client(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
params = Sample.create_api_info()
# query params
queries = {}
queries['ServiceParameters'] = '{"email":"example@alibabacloud.com","ip":"x.x.x.x","deviceToken":"******"}'
queries['Service'] = 'account_abuse_intl_pro'
# runtime options
runtime = util_models.RuntimeOptions()
request = open_api_models.OpenApiRequest(
query=OpenApiUtilClient.query(queries)
)
# After you copy and run the sample code, use the following object to query the response data of the request:
# The return value is of the Map type. You can obtain the following types of data from the Map: response body, response header, and HTTP status code statusCode.
client.call_api(params, request, runtime)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Fraud Detection SDK for PHP
Download the source code of Fraud Detection SDK for PHP.
Test case of Fraud Detection SDK for PHP:
Use the decision engine.
<?php
namespace AlibabaCloud\SDK\Sample;
use Darabonba\OpenApi\OpenApiClient;
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\Params;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\OpenApiRequest;
class Sample {
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return OpenApiClient Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
$config = new Config([
// Required. Specify your AccessKey ID.
"accessKeyId" => $accessKeyId,
// Required. Specify your AccessKey secret.
"accessKeySecret" => $accessKeySecret
]);
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
/**
* API-related parameters
* @return Params OpenApi.Params
*/
public static function createApiInfo(){
$params = new Params([
// The operation that you want to perform.
"action" => "RequestDecision",
// The version number of the operation.
"version" => "2019-05-21",
// The protocol of the operation.
"protocol" => "HTTPS",
// The HTTP method of the operation.
"method" => "POST",
"authType" => "AK",
"style" => "RPC",
// The URL of the operation.
"pathname" => "/",
// The format of the request body.
"reqBodyType" => "json",
// The format of the response body.
"bodyType" => "json"
]);
return $params;
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/311677.html.
$client = self::createClient(getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
$params = self::createApiInfo();
// query params
$queries = [];
$queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
$queries["EventCode"] = "de_*****";
// runtime options
$runtime = new RuntimeOptions([]);
$request = new OpenApiRequest([
"query" => OpenApiUtilClient::query($queries)
]);
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
$client->callApi($params, $request, $runtime);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Use scenario-specific risk control.
<?php
namespace AlibabaCloud\SDK\Sample;
use Darabonba\OpenApi\OpenApiClient;
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\Params;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\OpenApiRequest;
class Sample {
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return OpenApiClient Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
$config = new Config([
// Required. Specify your AccessKey ID.
"accessKeyId" => $accessKeyId,
// Required. Specify your AccessKey secret.
"accessKeySecret" => $accessKeySecret
]);
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
/**
* API-related parameters
* @return Params OpenApi.Params
*/
public static function createApiInfo(){
$params = new Params([
// The operation that you want to perform.
"action" => "ExecuteRequestSG",
// The version number of the operation.
"version" => "2019-05-21",
// The protocol of the operation.
"protocol" => "HTTPS",
// The HTTP method of the operation.
"method" => "POST",
"authType" => "AK",
"style" => "RPC",
// The URL of the operation.
"pathname" => "/",
// The format of the request body.
"reqBodyType" => "json",
// The format of the response body.
"bodyType" => "json"
]);
return $params;
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/311677.html.
$client = self::createClient(getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
$params = self::createApiInfo();
// query params
$queries = [];
$queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
$queries["Service"] = "account_abuse_intl_pro";
// runtime options
$runtime = new RuntimeOptions([]);
$request = new OpenApiRequest([
"query" => OpenApiUtilClient::query($queries)
]);
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
$client->callApi($params, $request, $runtime);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Fraud Detection SDK for C#
Download the source code of Fraud Detection SDK for C#.
Test case of Fraud Detection SDK for C#:
Use the decision engine.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.OpenApiClient.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// Required. Specify your AccessKey ID.
AccessKeyId = accessKeyId,
// Required. Specify your AccessKey secret.
AccessKeySecret = accessKeySecret,
};
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* API-related parameters
* @param path params
* @return OpenApi.Params
*/
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
// The operation that you want to perform.
Action = "RequestDecision",
// The version number of the operation.
Version = "2019-05-21",
// The protocol of the operation.
Protocol = "HTTPS",
// The HTTP method of the operation.
Method = "POST",
AuthType = "AK",
Style = "RPC",
// The URL of the operation.
Pathname = "/",
// The format of the request body.
ReqBodyType = "json",
// The format of the response body.
BodyType = "json",
};
return params_;
}
public static void Main(string[] args)
{
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378671.html.
AlibabaCloud.OpenApiClient.Client client = CreateClient(Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.OpenApiClient.Models.Params params_ = CreateApiInfo();
// query params
Dictionary<string, object> queries = new Dictionary<string, object>(){};
queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
queries["EventCode"] = "de_*****";
// runtime options
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
AlibabaCloud.OpenApiClient.Models.OpenApiRequest request = new AlibabaCloud.OpenApiClient.Models.OpenApiRequest
{
Query = AlibabaCloud.OpenApiUtil.Client.Query(queries),
};
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}
Use scenario-specific risk control.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.OpenApiClient.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// Required. Specify your AccessKey ID.
AccessKeyId = accessKeyId,
// Required. Specify your AccessKey secret.
AccessKeySecret = accessKeySecret,
};
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* API-related parameters
* @param path params
* @return OpenApi.Params
*/
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
// The operation that you want to perform.
Action = "ExecuteRequestSG",
// The version number of the operation.
Version = "2019-05-21",
// The protocol of the operation.
Protocol = "HTTPS",
// The HTTP method of the operation.
Method = "POST",
AuthType = "AK",
Style = "RPC",
// The URL of the operation.
Pathname = "/",
// The format of the request body.
ReqBodyType = "json",
// The format of the response body.
BodyType = "json",
};
return params_;
}
public static void Main(string[] args)
{
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378671.html.
AlibabaCloud.OpenApiClient.Client client = CreateClient(Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.OpenApiClient.Models.Params params_ = CreateApiInfo();
// query params
Dictionary<string, object> queries = new Dictionary<string, object>(){};
queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
queries["Service"] = "account_abuse_intl_pro";
// runtime options
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
AlibabaCloud.OpenApiClient.Models.OpenApiRequest request = new AlibabaCloud.OpenApiClient.Models.OpenApiRequest
{
Query = AlibabaCloud.OpenApiUtil.Client.Query(queries),
};
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}
Fraud Detection SDK for Go
Download the source code of Fraud Detection SDK for Go.
Test case of Fraud Detection SDK for Go:
Use the decision engine:
package main
import (
"os"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
)
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func CreateClient (accessKeyId *string, accessKeySecret *string) (_result *openapi.Client, _err error) {
config := &openapi.Config{
// Required. Specify your AccessKey ID.
AccessKeyId: accessKeyId,
// Required. Specify your AccessKey secret.
AccessKeySecret: accessKeySecret,
}
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
/**
* API-related parameters
* @param path params
* @return OpenApi.Params
*/
func CreateApiInfo () (_result *openapi.Params) {
params := &openapi.Params{
// The operation that you want to perform.
Action: tea.String("RequestDecision"),
// The version number of the operation.
Version: tea.String("2019-05-21"),
// The protocol of the operation.
Protocol: tea.String("HTTPS"),
// The HTTP method of the operation.
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
// The URL of the operation.
Pathname: tea.String("/"),
// The format of the request body.
ReqBodyType: tea.String("json"),
// The format of the response body.
BodyType: tea.String("json"),
}
_result = params
return _result
}
func _main (args []*string) (_err error) {
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378661.html.
client, _err := CreateClient(tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")), tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")))
if _err != nil {
return _err
}
params := CreateApiInfo()
// query params
queries := map[string]interface{}{}
queries["ServiceParameters"] = tea.String("{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}")
queries["EventCode"] = tea.String("de_*****")
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
_, _err = client.CallApi(params, request, runtime)
if _err != nil {
return _err
}
return _err
}
func main() {
err := _main(tea.StringSlice(os.Args[1:]))
if err != nil {
panic(err)
}
}
Use scenario-specific risk control.
package main
import (
"os"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
)
/**
* Use your AccessKey ID and AccessKey secret to create a client.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func CreateClient (accessKeyId *string, accessKeySecret *string) (_result *openapi.Client, _err error) {
config := &openapi.Config{
// Required. Specify your AccessKey ID.
AccessKeyId: accessKeyId,
// Required. Specify your AccessKey secret.
AccessKeySecret: accessKeySecret,
}
// Specify an endpoint. For more information, visit https://api.aliyun.com/product/saf.
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
/**
* API-related parameters
* @param path params
* @return OpenApi.Params
*/
func CreateApiInfo () (_result *openapi.Params) {
params := &openapi.Params{
// The operation that you want to perform.
Action: tea.String("ExecuteRequestSG"),
// The version number of the operation.
Version: tea.String("2019-05-21"),
// The protocol of the operation.
Protocol: tea.String("HTTPS"),
// The HTTP method of the operation.
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
// The URL of the operation.
Pathname: tea.String("/"),
// The format of the request body.
ReqBodyType: tea.String("json"),
// The format of the response body.
BodyType: tea.String("json"),
}
_result = params
return _result
}
func _main (args []*string) (_err error) {
// Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured in the code runtime environment.
// If the project code is leaked, the AccessKey pair may be disclosed and security issues may occur in all resources that belong to your Alibaba Cloud account. The following sample code shows how to use environment variables to obtain an AccessKey pair and use the AccessKey pair to call API operations. The sample code is for reference only. We recommend that you use STS, which provides higher security. For more information, see authentication methods at https://help.aliyun.com/document_detail/378661.html.
client, _err := CreateClient(tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")), tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")))
if _err != nil {
return _err
}
params := CreateApiInfo()
// query params
queries := map[string]interface{}{}
queries["ServiceParameters"] = tea.String("{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}")
queries["Service"] = tea.String("account_abuse_intl_pro")
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// After you copy and run the sample code, obtain the return value of the operation.
// The returned value is of the Map type. It contains the following three types of data: response body, response header, and HTTP status code.
_, _err = client.CallApi(params, request, runtime)
if _err != nil {
return _err
}
return _err
}
func main() {
err := _main(tea.StringSlice(os.Args[1:]))
if err != nil {
panic(err)
}
}