快速开始
只需三步即可完成订单风控 API 的接入:注册账号获取 API Key、调用订单风险检测接口、处理返回结果。以下是各语言的快速上手示例。
curl 示例
bash
curl -X POST https://api.fengkong.cloud/v1/order/risk-check \
-H "Content-Type: application/json" \
-H "X-Api-Key: your_api_key" \
-H "X-Timestamp: 1709971200" \
-H "X-Signature: hmac_sha256_signature" \
-d '{
"flow_id": "order_risk_v1",
"request_id": "req_20240309_001",
"data": {
"order_id": "ORD20240309001",
"buyer_id": "B123456",
"amount": 299.00,
"item_count": 3,
"shipping_address": "浙江省杭州市钱塘区白杨街道",
"buyer_phone": "138****1234",
"platform": "taobao",
"payment_method": "alipay"
}
}'
Python 示例
python
import requests
import hmac
import hashlib
import time
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.fengkong.cloud/v1"
def make_signature(timestamp, body):
message = f"{timestamp}{body}"
return hmac.new(
API_SECRET.encode(),
message.encode(),
hashlib.sha256
).hexdigest()
timestamp = str(int(time.time()))
payload = {
"flow_id": "order_risk_v1",
"request_id": "req_20240309_001",
"data": {
"order_id": "ORD20240309001",
"buyer_id": "B123456",
"amount": 299.00,
"item_count": 3,
"shipping_address": "浙江省杭州市钱塘区白杨街道",
"buyer_phone": "138****1234",
"platform": "taobao",
"payment_method": "alipay"
}
}
import json
body = json.dumps(payload)
signature = make_signature(timestamp, body)
response = requests.post(
f"{BASE_URL}/order/risk-check",
json=payload,
headers={
"X-Api-Key": API_KEY,
"X-Timestamp": timestamp,
"X-Signature": signature
}
)
result = response.json()
print(f"风控决策: {result['data']['decision']}")
print(f"风险评分: {result['data']['risk_score']}")
print(f"命中规则: {result['data']['hit_rules']}")
Java 示例
java
import java.net.http.*;
import java.net.URI;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class FengkongClient {
private static final String API_KEY = "your_api_key";
private static final String API_SECRET = "your_api_secret";
private static final String BASE_URL = "https://api.fengkong.cloud/v1";
public static void main(String[] args) throws Exception {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String body = """
{
"flow_id": "order_risk_v1",
"request_id": "req_20240309_001",
"data": {
"order_id": "ORD20240309001",
"buyer_id": "B123456",
"amount": 299.00,
"item_count": 3,
"shipping_address": "浙江省杭州市钱塘区白杨街道",
"buyer_phone": "138****1234",
"platform": "taobao",
"payment_method": "alipay"
}
}
""";
String signature = hmacSha256(API_SECRET, timestamp + body);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/order/risk-check"))
.header("Content-Type", "application/json")
.header("X-Api-Key", API_KEY)
.header("X-Timestamp", timestamp)
.header("X-Signature", signature)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString()
);
System.out.println("Response: " + response.body());
}
private static String hmacSha256(String key, String data)
throws Exception {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(key.getBytes(), "HmacSHA256"));
byte[] hash = mac.doFinal(data.getBytes());
StringBuilder hex = new StringBuilder();
for (byte b : hash) {
hex.append(String.format("%02x", b));
}
return hex.toString();
}
}
API 概览
风控云订单风控引擎提供三大类核心 API 接口,覆盖电商订单风险检测的完整流程。
| API 类别 | 接口地址 | 方法 | 说明 |
|---|---|---|---|
| 订单风控 API | /v1/order/risk-check |
POST | 订单风险检测,返回风险评分与处置建议 |
/v1/order/batch-check |
POST | 批量订单检测(最多100条/次) | |
/v1/order/result/{id} |
GET | 查询历史订单检测结果 | |
| 名单查询 API | /v1/list/check |
POST | 查询黑/白/灰名单命中情况(买家/地址/手机号) |
/v1/list/add |
POST | 添加名单条目 | |
/v1/list/remove |
POST | 移除名单条目 | |
| 评分模型 API | /v1/model/score |
POST | 调用买家信誉评分模型,返回计算评分 |
/v1/model/explain |
POST | 返回评分原因(可解释性) |
认证方式
所有 API 请求必须携带以下认证信息:
API Key + HMAC-SHA256 签名
| Header | 说明 | 示例 |
|---|---|---|
X-Api-Key |
您的 API Key(控制台获取) | fk_live_aBcDeFgHiJkL |
X-Timestamp |
Unix 时间戳(秒),误差不超过5分钟 | 1709971200 |
X-Signature |
HMAC-SHA256(secret, timestamp + body) | a1b2c3d4e5... |
签名算法:
text
signature = HMAC-SHA256(api_secret, timestamp + request_body)
其中:
- api_secret: 您的 API Secret(控制台获取,请妥善保管)
- timestamp: X-Timestamp 的值(字符串)
- request_body: 请求体的原始 JSON 字符串
- 输出为十六进制小写字符串
调用限制
不同版本的 API 调用限制如下:
| 版本 | 月检测量 | QPS 上限 | 批量接口 |
|---|---|---|---|
| 免费版 | 1,000 单/月 | 5 QPS | 不支持 |
| 标准版 | 10,000 单/月 | 50 QPS | 20 条/次 |
| 专业版 | 100,000 单/月 | 200 QPS | 50 条/次 |
| 企业版 | 不限 | 自定义 | 100 条/次 |
超出限制时,API 将返回 429 Too Many Requests 错误。建议实现指数退避重试策略。
响应格式
所有 API 响应均为 JSON 格式,包含统一的结构:
成功响应
json
{
"code": 0,
"message": "success",
"request_id": "req_20240309_001",
"data": {
"decision": "REVIEW",
"risk_score": 72,
"risk_level": "MEDIUM",
"hit_rules": [
{"rule_id": "R001", "rule_name": "同一地址24小时内多单", "detail": "该地址24小时内已下3单"},
{"rule_id": "R015", "rule_name": "新注册账号高额订单", "detail": "账号注册不足7天,订单金额超过200元"}
],
"execution_time_ms": 3,
"details": {
"buyer_risk_score": 45,
"address_risk_score": 68,
"order_pattern": "suspicious_multi_order"
}
}
}
风控决策枚举
| 值 | 含义 | 建议动作 |
|---|---|---|
PASS |
放行 | 正常处理订单 |
REJECT |
拦截 | 自动拦截高风险订单 |
REVIEW |
人工审核 | 转交审核台人工复核 |
错误码
当请求失败时,API 返回统一的错误格式:
json
{
"code": 40101,
"message": "Invalid API key",
"request_id": "req_20240309_002"
}
| 错误码 | HTTP 状态 | 说明 | 处理建议 |
|---|---|---|---|
40001 |
400 | 请求参数错误 | 检查请求体 JSON 格式与必填字段 |
40002 |
400 | 风控流不存在 | 检查 flow_id 是否正确 |
40101 |
401 | API Key 无效 | 检查 API Key 是否正确 |
40102 |
401 | 签名验证失败 | 检查签名算法与 Secret |
40103 |
401 | 时间戳过期 | 确保时间戳与服务器时间误差小于5分钟 |
40301 |
403 | 权限不足 | 确认当前版本是否支持该接口 |
42901 |
429 | 调用频率超限 | 降低请求频率或升级版本 |
42902 |
429 | 月调用量超限 | 升级版本或联系销售 |
50001 |
500 | 服务内部错误 | 重试请求,若持续出现请联系技术支持 |
50301 |
503 | 服务暂时不可用 | 稍后重试,关注系统状态页 |