The Fraud Detection SDK handles signature verification and request formatting automatically, letting you call API operations without building those from scratch. SDKs are available for Java, Python, PHP, C#, and Go.
Before you begin
Make sure you have:
An Alibaba Cloud account with Fraud Detection activated
An AccessKey ID and AccessKey secret stored in the
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables
For production workloads, use Security Token Service (STS) to generate short-lived credentials instead of long-term AccessKey pairs.
Operations
Each SDK call follows the same pattern: initialize a client with your AccessKey credentials and an endpoint, configure the API parameters, set operation-specific query parameters, and call the API.
The two main operations are:
| Operation | Purpose |
|---|---|
RequestDecision | Calls the decision engine to evaluate a risk signal |
ExecuteRequestSG | Applies scenario-specific risk control, such as account abuse detection |
Endpoints
| Region | Endpoint |
|---|---|
| Singapore | saf.ap-southeast-1.aliyuncs.com |
| Malaysia | saf.ap-southeast-3.aliyuncs.com |
| Indonesia | saf.ap-southeast-5.aliyuncs.com |
SDK for Java
Install
Add the SAF SDK to your Maven pom.xml:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-saf</artifactId>
<version>3.0.1</version>
</dependency>Click Address to access the Java Maven repository.
Also add the following dependencies:
<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>Browse available versions in the Java Maven repository.
Java SDK source code:
Call the decision engine (RequestDecision)
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
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);
// Endpoint reference: https://api.alibabacloud.com/product/saf
// SINGAPORE: ap-southeast-1 | MALAYSIA: ap-southeast-3 | INDONESIA: ap-southeast-5
config.endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {
com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
.setAction("RequestDecision")
.setVersion("2019-05-21")
.setProtocol("HTTPS")
.setMethod("POST")
.setAuthType("AK")
.setStyle("RPC")
.setPathname("/")
.setReqBodyType("json")
.setBodyType("json");
return params;
}
public static void main(String[] args_) throws Exception {
// Read credentials from environment variables to avoid exposing secrets in code.
// For production, use STS to generate short-lived credentials.
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();
// Set query parameters for the RequestDecision operation.
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_*****");
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));
// The response is a Map containing the response body, headers, and HTTP status code.
client.callApi(params, request, runtime);
}
}Apply scenario-specific risk control (ExecuteRequestSG)
#!/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)SDK for Python
Install
Download the Python SDK source code, then install the dependencies.
Step 1. Install the Alibaba Cloud SDK core library.
Python 2.x:
pip install aliyun-python-sdk-corePython 3.x:
pip install aliyun-python-sdk-core-v3
Step 2. Install the SAF SDK:
pip install aliyun-python-sdk-safPython example:
Call the decision engine (RequestDecision)
# -*- 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:
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
)
# Endpoint reference: 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:
params = open_api_models.Params(
action='RequestDecision',
version='2019-05-21',
protocol='HTTPS',
method='POST',
auth_type='AK',
style='RPC',
pathname=f'/',
req_body_type='json',
body_type='json'
)
return params
@staticmethod
def main(args: List[str]) -> None:
# Read credentials from environment variables to avoid exposing secrets in code.
# For production, use STS to generate short-lived credentials.
client = Sample.create_client(
os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
params = Sample.create_api_info()
# Set query parameters for the RequestDecision operation.
queries = {}
queries['ServiceParameters'] = '{"email":"example@alibabacloud.com","ip":"x.x.x.x","deviceToken":"******"}'
queries['EventCode'] = 'de_*****'
runtime = util_models.RuntimeOptions()
request = open_api_models.OpenApiRequest(
query=OpenApiUtilClient.query(queries)
)
# The response is a Map containing the response body, headers, and HTTP status code.
client.call_api(params, request, runtime)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Apply scenario-specific risk control (ExecuteRequestSG)
# -*- 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:
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
config.endpoint = f'saf.ap-southeast-1.aliyuncs.com'
return OpenApiClient(config)
@staticmethod
def create_api_info() -> open_api_models.Params:
params = open_api_models.Params(
action='ExecuteRequestSG',
version='2019-05-21',
protocol='HTTPS',
method='POST',
auth_type='AK',
style='RPC',
pathname=f'/',
req_body_type='json',
body_type='json'
)
return params
@staticmethod
def main(args: List[str]) -> None:
client = Sample.create_client(
os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
params = Sample.create_api_info()
queries = {}
queries['ServiceParameters'] = '{"email":"example@alibabacloud.com","ip":"x.x.x.x","deviceToken":"******"}'
queries['Service'] = 'account_abuse_intl_pro'
runtime = util_models.RuntimeOptions()
request = open_api_models.OpenApiRequest(
query=OpenApiUtilClient.query(queries)
)
client.call_api(params, request, runtime)
if __name__ == '__main__':
Sample.main(sys.argv[1:])SDK for PHP
Download the PHP SDK source code.here
PHP example:
Call the decision engine (RequestDecision)
<?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 {
public static function createClient($accessKeyId, $accessKeySecret){
$config = new Config([
// Required. Specify your AccessKey ID.
"accessKeyId" => $accessKeyId,
// Required. Specify your AccessKey secret.
"accessKeySecret" => $accessKeySecret
]);
// Endpoint reference: https://api.aliyun.com/product/saf
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
public static function createApiInfo(){
$params = new Params([
"action" => "RequestDecision",
"version" => "2019-05-21",
"protocol" => "HTTPS",
"method" => "POST",
"authType" => "AK",
"style" => "RPC",
"pathname" => "/",
"reqBodyType" => "json",
"bodyType" => "json"
]);
return $params;
}
public static function main($args){
// Read credentials from environment variables to avoid exposing secrets in code.
// For production, use STS to generate short-lived credentials.
$client = self::createClient(
getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')
);
$params = self::createApiInfo();
// Set query parameters for the RequestDecision operation.
$queries = [];
$queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
$queries["EventCode"] = "de_*****";
$runtime = new RuntimeOptions([]);
$request = new OpenApiRequest([
"query" => OpenApiUtilClient::query($queries)
]);
// The response is a Map containing the response body, headers, 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));Apply scenario-specific risk control (ExecuteRequestSG)
<?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 {
public static function createClient($accessKeyId, $accessKeySecret){
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
public static function createApiInfo(){
$params = new Params([
"action" => "ExecuteRequestSG",
"version" => "2019-05-21",
"protocol" => "HTTPS",
"method" => "POST",
"authType" => "AK",
"style" => "RPC",
"pathname" => "/",
"reqBodyType" => "json",
"bodyType" => "json"
]);
return $params;
}
public static function main($args){
$client = self::createClient(
getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')
);
$params = self::createApiInfo();
$queries = [];
$queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
$queries["Service"] = "account_abuse_intl_pro";
$runtime = new RuntimeOptions([]);
$request = new OpenApiRequest([
"query" => OpenApiUtilClient::query($queries)
]);
$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));SDK for C#
Download the C# SDK source code.
Call the decision engine (RequestDecision)
using System;
using System.Collections.Generic;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
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,
};
// Endpoint reference: https://api.aliyun.com/product/saf
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
Action = "RequestDecision",
Version = "2019-05-21",
Protocol = "HTTPS",
Method = "POST",
AuthType = "AK",
Style = "RPC",
Pathname = "/",
ReqBodyType = "json",
BodyType = "json",
};
return params_;
}
public static void Main(string[] args)
{
// Read credentials from environment variables to avoid exposing secrets in code.
// For production, use STS to generate short-lived credentials.
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();
// Set query parameters for the RequestDecision operation.
Dictionary<string, object> queries = new Dictionary<string, object>(){};
queries["ServiceParameters"] = "{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}";
queries["EventCode"] = "de_*****";
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),
};
// The response is a Map containing the response body, headers, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}Apply scenario-specific risk control (ExecuteRequestSG)
using System;
using System.Collections.Generic;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
public static AlibabaCloud.OpenApiClient.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
AccessKeyId = accessKeyId,
AccessKeySecret = accessKeySecret,
};
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
Action = "ExecuteRequestSG",
Version = "2019-05-21",
Protocol = "HTTPS",
Method = "POST",
AuthType = "AK",
Style = "RPC",
Pathname = "/",
ReqBodyType = "json",
BodyType = "json",
};
return params_;
}
public static void Main(string[] args)
{
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();
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";
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),
};
client.CallApi(params_, request, runtime);
}
}
}If you 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 an AccessKey pair to initialize the 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. Your AccessKey ID.
AccessKeyId = accessKeyId,
// Required. Your AccessKey secret.
AccessKeySecret = accessKeySecret,
};
// For more information about the endpoint, see https://api.aliyun.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* API-related information.
* @param path params
* @return OpenApi.Params
*/
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
// The name of the API operation.
Action = "RequestDecision",
// The version of the API.
Version = "2019-05-21",
// The protocol of the API.
Protocol = "HTTPS",
// The HTTP method of the API.
Method = "POST",
AuthType = "AK",
Style = "RPC",
// The path of the API.
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 set.
// Leaking the project code may cause the AccessKey pair to be leaked and threaten the security of all resources in your account. The following sample code shows how to obtain an AccessKey pair from environment variables for API calls. This is for reference only. We recommend that you use a more secure method, such as Security Token Service (STS).
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),
};
// If you copy the code to run, print the return value of the API call.
// The return value is of the Map type. You can obtain three types of data from the map: the response body, response headers, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}In a risk control scenario:
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 an AccessKey pair to initialize the 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. Your AccessKey ID.
AccessKeyId = accessKeyId,
// Required. Your AccessKey secret.
AccessKeySecret = accessKeySecret,
};
// For more information about the endpoint, see https://api.aliyun.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* API-related information.
* @param path params
* @return OpenApi.Params
*/
public static AlibabaCloud.OpenApiClient.Models.Params CreateApiInfo()
{
AlibabaCloud.OpenApiClient.Models.Params params_ = new AlibabaCloud.OpenApiClient.Models.Params
{
// The name of the API operation.
Action = "ExecuteRequest",
// The version of the API.
Version = "2019-05-21",
// The protocol of the API.
Protocol = "HTTPS",
// The HTTP method of the API.
Method = "POST",
AuthType = "AK",
Style = "RPC",
// The path of the API.
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 set.
// Leaking the project code may cause the AccessKey pair to be leaked and threaten the security of all resources in your account. The following sample code shows how to obtain an AccessKey pair from environment variables for API calls. This is for reference only. We recommend that you use a more secure method, such as Security Token Service (STS).
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),
};
// If you copy the code to run, print the return value of the API call.
// The return value is of the Map type. You can obtain three types of data from the map: the response body, response headers, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}SDK for Go
Download the Go SDK source code.
Go example:
Call the decision engine (RequestDecision)
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"
)
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,
}
// Endpoint reference: https://api.aliyun.com/product/saf
// SINGAPORE: ap-southeast-1 | MALAYSIA: ap-southeast-3 | INDONESIA: ap-southeast-5
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
func CreateApiInfo() (_result *openapi.Params) {
params := &openapi.Params{
Action: tea.String("RequestDecision"),
Version: tea.String("2019-05-21"),
Protocol: tea.String("HTTPS"),
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
Pathname: tea.String("/"),
ReqBodyType: tea.String("json"),
BodyType: tea.String("json"),
}
_result = params
return _result
}
func _main(args []*string) (_err error) {
// Read credentials from environment variables to avoid exposing secrets in code.
// For production, use STS to generate short-lived credentials.
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()
// Set query parameters for the RequestDecision operation.
queries := map[string]interface{}{}
queries["ServiceParameters"] = tea.String("{\"email\":\"example@alibabacloud.com\",\"ip\":\"x.x.x.x\",\"deviceToken\":\"******\"}")
queries["EventCode"] = tea.String("de_*****")
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// The response is a Map containing the response body, headers, 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)
}
}Apply scenario-specific risk control (ExecuteRequestSG)
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"
)
func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *openapi.Client, _err error) {
config := &openapi.Config{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
}
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
func CreateApiInfo() (_result *openapi.Params) {
params := &openapi.Params{
Action: tea.String("ExecuteRequestSG"),
Version: tea.String("2019-05-21"),
Protocol: tea.String("HTTPS"),
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
Pathname: tea.String("/"),
ReqBodyType: tea.String("json"),
BodyType: tea.String("json"),
}
_result = params
return _result
}
func _main(args []*string) (_err error) {
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()
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 := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
_, _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)
}
}