Cette rubrique explique comment utiliser le SDK de détection de fraude, qui offre une méthode simple et pratique pour appeler des opérations d'API.
Présentation des méthodes d'appel du SDK
Lorsque vous utilisez le SDK de détection de fraude, vous n'avez pas besoin de vous soucier de traitements complexes tels que la vérification des signatures ou la construction du format du corps de la requête. Nous vous recommandons d'utiliser ce SDK. Il prend actuellement en charge Java, Python, PHP, C# et Go (5 SDK au total).
SDK pour Java
Dépendance Maven Java :
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-saf</artifactId>
<version>3.0.1</version>
</dependency>
Gestionnaire de dépendances Maven Java recommandé :
<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>
Cliquez ici pour accéder au référentiel Maven Java.
Code source :
Utilisez le moteur de décision :
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* Use your AccessKey ID and AccessKey secret to initialize 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.alibabacloud.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);
}
/**
* Configure 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 name of the operation.
.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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use Security Token Service (STS), which provides higher security.
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));
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following types of data: response body, response header, and HTTP status code.
client.callApi(params, request, runtime);
}
}
Utilisez la gestion des risques spécifique aux scénarios, telle que la détection de fraude à l'inscription et la détection de fraude marketing :
#!/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 pour Python
Cliquez ici pour télécharger le code source du SDK de détection de fraude pour Python.
-
Installez la bibliothèque principale du SDK.
-
Si vous utilisez Python 2.x, exécutez la commande suivante pour installer la bibliothèque principale du SDK Alibaba Cloud :
pip install aliyun-python-sdk-core -
Si vous utilisez Python 3.x, exécutez la commande suivante pour installer la bibliothèque principale du SDK Alibaba Cloud :
pip install aliyun-python-sdk-core-v3
-
-
Installez le SDK SAF pour les produits cloud.
pip install aliyun-python-sdk-saf
Cas d'utilisation Python :
Utilisez le moteur de décision :
# -*- 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 initialize 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.alibabacloud.com/product/saf.
config.endpoint = f'saf.ap-southeast-1.aliyuncs.com'
return OpenApiClient(config)
@staticmethod
def create_api_info() -> open_api_models.Params:
"""
Configure API-related parameters.
@param path: params
@return: OpenApi.Params
"""
params = open_api_models.Params(
# The name of the operation.
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 path to 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.
# If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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)
)
# Write your code to print the response of the API operation based on your business requirements.
# 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:])
Utilisez la gestion des risques spécifique aux scénarios :
# -*- 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 initialize 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.alibabacloud.com/product/saf.
config.endpoint = f'saf.ap-southeast-1.aliyuncs.com'
return OpenApiClient(config)
@staticmethod
def create_api_info() -> open_api_models.Params:
"""
Configure API-related parameters.
@param path: params
@return: OpenApi.Params
"""
params = open_api_models.Params(
# The name of the operation.
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 path to 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.
# If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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)
)
# Write your code to print the response of the API operation based on your business requirements.
# 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:])
SDK pour PHP
Cliquez ici pour télécharger le code source du SDK de détection de fraude pour PHP.
Cas d'utilisation PHP :
Utilisez le moteur de décision :
<?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 initialize 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.alibabacloud.com/product/saf.
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
/**
* Configure API-related parameters.
* @return Params OpenApi.Params
*/
public static function createApiInfo(){
$params = new Params([
// The name of the operation.
"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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
$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)
]);
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following 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));
Utilisez la gestion des risques spécifique aux scénarios :
<?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 initialize 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.alibabacloud.com/product/saf.
$config->endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new OpenApiClient($config);
}
/**
* Configure API-related parameters.
* @return Params OpenApi.Params
*/
public static function createApiInfo(){
$params = new Params([
// The name of the operation.
"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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
$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)
]);
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following 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));
SDK pour C#
Cliquez ici pour télécharger le code source du SDK de détection de fraude pour C#.
Cas d'utilisation C#
using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Auth;
namespace CommonRequestDemo
{
class Program
{
static void Main(string[] args)
{
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
AlibabaCloudCredentialsProvider provider = new AccessKeyCredentialProvider(
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
/* use STS Token
AlibabaCloudCredentialsProvider provider = new StsCredentialProvider(
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_SECURITY_TOKEN"));
*/
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", provider);
DefaultAcsClient client = new DefaultAcsClient(profile, provider);
CommonRequest request = new CommonRequest();
request.Method = MethodType.POST;
request.Domain = "saf.cn-hangzhou.aliyuncs.com";
request.Version = "2019-05-21";
request.Action = "ExecuteRequestSG";
// request.Protocol = ProtocolType.HTTP;
try {
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}
Utilisez le moteur de décision :
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 initialize 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.alibabacloud.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* Configure 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 name of the operation.
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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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),
};
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following types of data: response body, response header, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}
Utilisez la gestion des risques spécifique aux scénarios :
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 initialize 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.alibabacloud.com/product/saf.
config.Endpoint = "saf.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.OpenApiClient.Client(config);
}
/**
* Configure 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 name of the operation.
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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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),
};
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following types of data: response body, response header, and HTTP status code.
client.CallApi(params_, request, runtime);
}
}
}
SDK pour Go
Cliquez ici pour télécharger le code source du SDK de détection de fraude pour Go.
Cas d'utilisation Golang :
Utilisez le moteur de décision :
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 initialize 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.alibabacloud.com/product/saf.
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
/**
* Configure API-related parameters.
* @param path params
* @return OpenApi.Params
*/
func CreateApiInfo () (_result *openapi.Params) {
params := &openapi.Params{
// The name of the operation.
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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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),
}
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following 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)
}
}
Utilisez la gestion des risques spécifique aux scénarios :
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 initialize 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.alibabacloud.com/product/saf.
config.Endpoint = tea.String("saf.ap-southeast-1.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
/**
* Configure API-related parameters.
* @param path params
* @return OpenApi.Params
*/
func CreateApiInfo () (_result *openapi.Params) {
params := &openapi.Params{
// The name of the operation.
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 path to 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.
// If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
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),
}
// Write your code to print the response of the API operation based on your business requirements.
// The return value is of the Map type. It contains the following 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)
}
}