通过使用阿里云风险识别SDK,调用方无需关注签名验证以及Body格式构建等繁琐的事情,推荐您使用风险识别SDK。目前支持JAVA、Python、PHP、C#、Golang、Node.js、Ruby共7种SDK。

JAVA SDK

单击此处下载JAVA SDK源码。

JAVA SDK的环境准备、安装使用请参见阿里云SDK开发指南

JAVA Maven依赖:

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-saf</artifactId>
    <version>1.0.2</version>
</dependency>

JAVA Maven推荐依赖仲裁:

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <optional>true</optional>
    <version>4.5.1</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.60</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency>
<dependency>        
    <groupId>org.apache.httpcomponents</groupId>        
    <artifactId>httpclient</artifactId>        
    <version>4.5.3</version>    
</dependency>    
<dependency>       
    <groupId>io.opentracing</groupId>       
    <artifactId>opentracing-util</artifactId>        
    <version>0.31.0</version>    
</dependency>

单击此处查看JAVA用例。

单击地址1地址2访问JAVA Maven仓库。

Python SDK

单击此处下载Python SDK源码。

Python SDK的环境准备、安装使用请参见阿里云SDK开发指南
  1. 安装SDK核心库。
    • 如果您使用Python 2.x,执行以下命令,安装阿里云SDK核心库:
      pip install aliyun-python-sdk-core
    • 如果您使用Python 3.x,执行以下命令,安装阿里云SDK核心库:
      pip install aliyun-python-sdk-core-v3
  2. 安装云产品SAF SDK。
    pip install aliyun-python-sdk-saf
Python用例:
from aliyunsdkcore import client
from aliyunsdksaf.request.v20190521 import ExecuteRequestRequest

clt = client.AcsClient('<your-access-key-id>','<your-access-key-secret>','cn-shanghai')
					
# 设置参数
request = ExecuteRequestRequest.ExecuteRequestRequest()
request.set_accept_format('json')
# 产品Service请参考[公共参数]文档中的Service字段描述
request.add_query_param('Service', '购买的产品Service')
request.add_query_param('ServiceParameters', '入参json字符串')
					
# 发起请求
response = clt.do_action_with_exception(request)
print(response)
				

PHP SDK

单击此处下载PHP SDK源码。

PHP SDK的环境准备、安装使用请参见阿里云SDK开发指南

PHP用例:
<?php
include_once 'aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config.php';
use saf\Request\V20190521 as saf;
					
// 初始化
$iClientProfile = DefaultProfile::getProfile("cn-shanghai", "<your-access-key-id>", "<your-access-key-secret>");
$client = new DefaultAcsClient($iClientProfile);
					
//设置参数
$request = new saf\ExecuteRequestRequest();
// 产品Service请参考[公共参数]文档中的Service字段描述
$request->setService('购买的产品Service');
$request->setServiceParameters('入参json字符串');
					
// 发起请求
$response = $client->getAcsResponse($request);
print_r("<br>");
print_r("test");
print_r("\r\n");
print_r($response);
print_r($client);
?>

C# SDK

单击此处下载C# SDK源码。

C# SDK的环境准备、安装使用请参见阿里云SDK开发指南

Golang SDK

单击此处下载Golang SDK源码。

Golang SDK的环境准备、安装使用请参见阿里云SDK开发指南

Golang用例:
package main
					
import (
    "fmt"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/saf"
)
					
func main() {
    client, err := saf.NewClientWithAccessKey("cn-shanghai", "<your-access-key-id>", "<your-access-key-secret>")
    request := saf.CreateExecuteRequestRequest()
    endpoints.AddEndpointMapping("cn-shanghai", "saf", "saf.cn-shanghai.aliyuncs.com")
    // 产品Service请参考[公共参数]文档中的Service字段描述
    request.Service = "购买的产品Service"
    request.ServiceParameters = "入参json字符串"
    request.Scheme = "https"
    response, err := client.ExecuteRequest(request)
    if err != nil {
        fmt.Print(err.Error())
    }
    fmt.Printf("response code is %#v\n", response.Code)
    fmt.Printf("response date is %#v\n", response.Data)
    fmt.Printf("response message is %#v\n", response.Message)
    fmt.Printf("response requestId is %#v\n", response.RequestId)
}

六、Node.js SDK

单击此处下载Node.js SDK源码。

Node.js SDK的环境准备、安装使用请参见阿里云SDK开发指南

执行以下命令安装@alicloud/pop-core模块。命令中的--save会将模块写入应用的package.json文件中,作为依赖模块。
$ npm install @alicloud/pop-core --save
Node.js用例:
const Core = require('@alicloud/pop-core');
				
var client = new Core({
  accessKeyId: '<your-access-key-id>',
  accessKeySecret: '<your-access-key-secret>',
  endpoint: 'https://saf.cn-shanghai.aliyuncs.com',
  apiVersion: '2019-01-28'
});
				
var params = {
  "RegionId": "cn-shanghai",
  // 产品Service请参考[公共参数]文档中的Service字段描述
  "Service": "购买的产品Service",
  "ServiceParameters": "入参json字符串"
}
				
var requestOption = {
  method: 'POST'
};
				
client.request('ExecuteRequest', params, requestOption).then((result) => {
  console.log(JSON.stringify(result));
}, (ex) => {
  console.log(ex);
})

七、Ruby SDK

单击此处下载Ruby SDK源码。

Ruby SDK的环境准备、安装使用请参见阿里云SDK开发指南

执行以下命令安装 Alibaba Cloud Core SDK for Ruby:
$ gem install aliyunsdkcore
Ruby用例:
require 'aliyunsdkcore'

client = RPCClient.new(
  access_key_id:     '<your-access-key-id>',
  access_key_secret: '<your-access-key-secret>',
  endpoint: 'https://saf.cn-shanghai.aliyuncs.com',
  api_version: '2019-01-28'
)

response = client.request(
  action: 'ExecuteRequest',
  params: {
    "RegionId": "cn-shanghai",
    # 产品Service请参考[公共参数]文档中的Service字段描述
    "Service": "购买的产品Service",
    "ServiceParameters": "入参json字符串"
  },
  opts: {
    method: 'POST'
  }
)

print response