兑换
兑换申请
请求示例:
POST <base_path>/v2/exchange/index HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{"user_id":"28","source_coin":"eth","target_coin":"usdt","amount":"0.011","trade_id":"20200114202903274786","limit_price":"5","type":1,"max_time":5}
resp, err := client.Post("/v2/exchange/index", map[string]any{
"user_id": "28",
"source_coin": "eth",
"target_coin": "usdt",
"amount": "0.011",
"trade_id": "20200114202903274786",
"limit_price": "5",
"type": 1,
"max_time": 5,
})
$resp = $client->post('/v2/exchange/index', [
'user_id' => '28',
'source_coin' => 'eth',
'target_coin' => 'usdt',
'amount' => '0.011',
'trade_id' => '20200114202903274786',
'limit_price' => '5',
'type' => 1,
'max_time' => 5,
]);
const resp = await client.post('/v2/exchange/index', {
user_id: '28',
source_coin: 'eth',
target_coin: 'usdt',
amount: '0.011',
trade_id: '20200114202903274786',
limit_price: '5',
type: 1,
max_time: 5,
});
String resp = client.post("/v2/exchange/index", Map.of(
"user_id", "28",
"source_coin", "eth",
"target_coin", "usdt",
"amount", "0.011",
"trade_id", "20200114202903274786",
"limit_price", "5",
"type", 1,
"max_time", 5));
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status":200,
"msg":"请求成功",
"data":{
"trade_id":"2424sfshdrsfsf210"
},
"date_time":"2020-12-29 09:14:10",
"time_stamp":1609204450
}
商户发起兑换,请求此接口。
HTTP Request
POST /v2/exchange/index
请求参数
公共 Header 见签名规则,下表只列 body 中的业务参数。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| user_id | 否 | string | 商家用户id (开启风控的商家,为必填项) |
| source_coin | 是 | string | 兑换币 |
| target_coin | 是 | string | 兑换目标币 |
| amount | 是 | string | 兑换币兑换数量 |
| trade_id | 是 | string | 商户端交易唯一ID(长度最多支持 32个字符长度。建议格式:年月日时分秒+6位随机数案列:20200311202903000001) |
| limit_price | 否 | string | 限价(如果type=0,此字段必传)。兑换稳定币时的最低兑换价,或兑换虚拟币时的最高兑换价。 |
| type | 是 | integer | 兑换模式(1平仓模式/0一般兑换),默认1。一般兑换在满足最低价格情况下进行挂单,可能会存在部分成功部分失败的情况,在一定时间内未兑换成功,会做撤单处理。平仓模式是一定会挂单成功,不考虑滑点影响,会持续尝试在交易所挂单,不考虑价格。 |
| max_time | 否 | integer | 单位秒-最大兑换时间-超过会完成的兑换会停止兑换(一般模式才生效) |
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.trade_id | string | trade_id-商户给的 |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
- 该接口返回成功只是接收成功,不代表兑换成功,处理结果以通知接口返回数据为准
兑换账户充值
请求示例:
POST <base_path>/v2/exchange/transfer HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{"coin":"usdt_erc20","exchange_coin":"usdt","amount":"10"}
resp, err := client.Post("/v2/exchange/transfer", map[string]any{
"coin": "usdt_erc20",
"exchange_coin": "usdt",
"amount": "10",
})
$resp = $client->post('/v2/exchange/transfer', [
'coin' => 'usdt_erc20',
'exchange_coin' => 'usdt',
'amount' => '10',
]);
const resp = await client.post('/v2/exchange/transfer', {
coin: 'usdt_erc20',
exchange_coin: 'usdt',
amount: '10',
});
String resp = client.post("/v2/exchange/transfer", Map.of(
"coin", "usdt_erc20",
"exchange_coin", "usdt",
"amount", "10"));
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "请求成功",
"data": [],
"date_time": "2021-08-20 15:44:25",
"time_stamp": 1629445465
}
兑换账户充值的资金是由热钱包地址转出到兑换账户
HTTP Request
POST /v2/exchange/transfer
请求参数
公共 Header 见签名规则,下表只列 body 中的业务参数。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| coin | 是 | string | 热钱包币种,如:usdt_erc20、usdt_trc20 |
| exchange_coin | 是 | string | 兑换账户币种,如:usdt |
| amount | 是 | string | 充值金额 |
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
兑换汇率
请求示例:
POST <base_path>/v2/rate/exchange HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{"source_coin":"eth","target_coin":"usdt","amount":"10"}
resp, err := client.Post("/v2/rate/exchange", map[string]any{
"source_coin": "eth",
"target_coin": "usdt",
"amount": "10",
})
$resp = $client->post('/v2/rate/exchange', [
'source_coin' => 'eth',
'target_coin' => 'usdt',
'amount' => '10',
]);
const resp = await client.post('/v2/rate/exchange', {
source_coin: 'eth',
target_coin: 'usdt',
amount: '10',
});
String resp = client.post("/v2/rate/exchange", Map.of(
"source_coin", "eth",
"target_coin", "usdt",
"amount", "10"));
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "请求成功",
"data": {
"rate": "3233.688",
"max": "20",
"min": "15",
"source_unit": "4",
"base_coin": "usdt"
},
"date_time": "2021-08-20 15:44:25",
"time_stamp": 1629445465
}
兑换前 ,查询兑换汇率。
HTTP Request
POST /v2/rate/exchange
请求参数
公共 Header 见签名规则,下表只列 body 中的业务参数。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| source_coin | 是 | string | 兑换币 |
| target_coin | 是 | string | 兑换目标币 |
| amount | 是 | string | 兑换币兑换数量 |
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.rate | string | 其他币对应usdt的兑换汇率 |
| data.max | string | 兑换币最大支持单笔兑换数量 |
| data.min | string | 兑换币最小支持单笔兑换数量 |
| data.source_unit | integer | 支持兑换币小数位长度(值如4, 表示最多支持4个小数位) |
| data.base_coin | string | 基准币种,交易区支持公链作为交易价格的基准币种 |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
批量查询兑换汇率
请求示例:
POST <base_path>/v2/rate/exchangeBatch HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{}
resp, err := client.Post("/v2/rate/exchangeBatch", nil)
$resp = $client->post('/v2/rate/exchangeBatch');
const resp = await client.post('/v2/rate/exchangeBatch');
String resp = client.post("/v2/rate/exchangeBatch", Map.of());
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "请求成功",
"data": [
{
"source_coin": "eth",
"target_coin": "usdt",
"rate": 3198.707676,
"max": 0,
"min": 0,
"source_unit": 4,
"base_coin": "usdt"
},
{
"source_coin": "usdt",
"target_coin": "eth",
"rate": 3231.075,
"max": 20,
"min": 15,
"source_unit": 4,
"base_coin": "usdt"
}
],
"date_time": "2021-08-20 15:47:52",
"time_stamp": 1629445672
}
HTTP Request
POST /v2/rate/exchangeBatch
请求参数
本接口没有业务参数,请求 body 为 {}。公共 Header 见签名规则。
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.rate | string | 其他币对应usdt的兑换汇率 |
| data.max | string | 兑换币最大支持单笔兑换数量 |
| data.min | string | 兑换币最小支持单笔兑换数量 |
| data.source_unit | integer | 支持兑换币小数位长度(值如4, 表示最多支持4个小数位) |
| data.base_coin | string | 基准币种,交易区支持公链作为交易价格的基准币种 |
| data.source_coin | string | 兑换币 |
| data.target_coin | string | 目标币 |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
兑换余额查询
请求示例:
POST <base_path>/v2/balance/exchange HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{"coin":"eth"}
resp, err := client.Post("/v2/balance/exchange", map[string]any{
"coin": "eth",
})
$resp = $client->post('/v2/balance/exchange', [
'coin' => 'eth',
]);
const resp = await client.post('/v2/balance/exchange', {
coin: 'eth',
});
String resp = client.post("/v2/balance/exchange", Map.of("coin", "eth"));
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "请求成功",
"data": [{
"coin": "eth",
"amount": 0,
"freeze_amount": 0,
"total": 0
}],
"date_time": "2022-07-22 20:18:01",
"time_stamp": 1658492281
}
兑换账户余额查询接口,返回单个币种的兑换账户余额
HTTP Request
POST /v2/balance/exchange
请求参数
公共 Header 见签名规则,下表只列 body 中的业务参数。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| coin | 否 | string | 20个字符内币名,币名平台提供为准,若该参数为空则返回所有币种 |
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.amount | number | 可用余额 |
| data.freeze_amount | number | 冻结余额 |
| data.total | number | 冻结+可用余额 |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
兑换交易对查询
请求示例:
POST <base_path>/v2/exchange/coin HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{}
resp, err := client.Post("/v2/exchange/coin", nil)
$resp = $client->post('/v2/exchange/coin');
const resp = await client.post('/v2/exchange/coin');
String resp = client.post("/v2/exchange/coin", Map.of());
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "处理成功",
"data": [
{
"source_coin": "eth",
"target_coin": "usdt",
"source_min_amount": "0",
"source_max_amount": "0",
"source_unit": "4",
"target_unit": "2"
},
{
"source_coin": "usdt_trc20",
"target_coin": "usdt",
"source_min_amount": "0",
"source_max_amount": "0",
"source_unit": "2",
"target_unit": "6"
}
],
"date_time": "2021-08-10 09:32:26",
"time_stamp": 1628559146
}
查询支持的兑换币种
HTTP Request
POST /v2/exchange/coin
请求参数
本接口没有业务参数,请求 body 为 {}。公共 Header 见签名规则。
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.source_coin | string | 源币种 |
| data.target_coin | string | 目标币种 |
| data.source_min_amount | string | 兑换币最小支持单笔兑换数量 |
| data.source_max_amount | string | 兑换币最大支持单笔兑换数量 |
| data.source_unit | string | 支持兑换币小数位长度(值如4, 表示最多支持4个小数位) |
| data.target_unit | string | 支持目标币小数位长度(值如4, 表示最多支持4个小数位) |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
兑换列表查询
请求示例:
POST <base_path>/v2/exchange/list HTTP/1.1
Host: api.xxxx.com
Content-Type: application/json
X-Cbc-App-Id: hxgmau9imt86qky9
X-Cbc-Key-Version: admin
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 7c1e9a3b5d7f9b1d3f5a7c9e1b3d5f7a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{"source_coin":"eth","target_coin":"usdt","start_time":1587004987,"end_time":1599616679,"status":1,"page":1,"page_size":20}
resp, err := client.Post("/v2/exchange/list", map[string]any{
"source_coin": "eth",
"target_coin": "usdt",
"start_time": 1587004987,
"end_time": 1599616679,
"status": 1,
"page": 1,
"page_size": 20,
})
$resp = $client->post('/v2/exchange/list', [
'source_coin' => 'eth',
'target_coin' => 'usdt',
'start_time' => 1587004987,
'end_time' => 1599616679,
'status' => 1,
'page' => 1,
'page_size' => 20,
]);
const resp = await client.post('/v2/exchange/list', {
source_coin: 'eth',
target_coin: 'usdt',
start_time: 1587004987,
end_time: 1599616679,
status: 1,
page: 1,
page_size: 20,
});
String resp = client.post("/v2/exchange/list", Map.of(
"source_coin", "eth",
"target_coin", "usdt",
"start_time", 1587004987,
"end_time", 1599616679,
"status", 1,
"page", 1,
"page_size", 20));
返回结果示例:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Request-ID: 4bf92f3577b34da6a3ce929d0e0e4736
X-Cbc-Timestamp: 1792382461
X-Cbc-Nonce: 3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"status": 200,
"msg": "处理成功",
"data": {
"page": 1,
"max_page": 1,
"count": 4,
"list": [
{
"order_id": "20210811162504870081",
"trade_id": "2424sfshdrsfsf211wqe11",
"user_id": "1001",
"source_coin": "eth",
"target_coin": "usdt",
"source_amount": "0.1234",
"source_success_amount": "0",
"source_failed_amount": "0",
"target_amount": "0",
"limit_price": "3.4",
"type": "1",
"exchange_fee": "0",
"exchange_rate": "0",
"status": "2",
"time": "1629252807"
},
{
"order_id": "20210811162442276466",
"trade_id": "2424sfshdrsfsf211wqe1",
"user_id": "1002",
"source_coin": "eth",
"target_coin": "usdt",
"source_amount": "0.1234",
"source_success_amount": "0",
"source_failed_amount": "0",
"target_amount": "0",
"limit_price": "3.4",
"type": "1",
"exchange_fee": "0",
"exchange_rate": "0",
"status": "2",
"time": "1628670282"
}
]
},
"date_time": "2021-08-18 17:11:54",
"time_stamp": 1629277914
}
兑换账号余额查询
查处兑换单状态接口,支持多维度查询
HTTP Request
POST /v2/exchange/list
请求参数
公共 Header 见签名规则,下表只列 body 中的业务参数。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| trade_id | 否 | string | 如果传trade_id为精准查找,下面参数失效 |
| source_coin | 否 | string | 兑换币 |
| target_coin | 否 | string | 兑换目标币 |
| page | 否 | integer | 1<= N <=Max,对于超过Max的取Max,小于1或没有传参数的返回1 |
| status | 否 | integer | 0 待审核 1 兑换成功、5 审核通过、10 审核不通过、20 兑换失败 |
| start_time | 否 | integer | 开始时间(创建时间) 格式 :时间戳 |
| end_time | 否 | integer | 结束时间(创建时间) 格式 :时间戳 |
| page_size | 否 | integer | 每页数量 (20 ~500),默认 20 |
返回参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | integer | 状态码 |
| msg | string | 状态描述 |
| data | object | |
| data.page | integer | 第几页 |
| data.count | integer | 本页记录数 |
| data.list | array | 具体每条记录 |
| data.list.trade_id | string | 交易id |
| data.list.source_coin | string | 兑换币 |
| data.list.target_coin | string | 兑换目标币 |
| data.list.source_amount | string | 兑换币数量 |
| data.list.target_amount | string | 兑换目标币数量 |
| data.list.limit_price | string | 限价 |
| data.list.type | string | 兑换模式(0一般兑换/1平仓模式) |
| data.list.exchange_fee | string | 兑换手续费(单位:目标币) |
| data.list.status | string | 订单状态:0 待审核、1 兑换完成、2 待处理、5 审核通过、10 审核不通过、20 转账失败 |
| data.list.time | string | 状态时间,最终固定在status=1时候的时间 |
| data.list.order_id | string | 订单id |
| data.list.exchange_rate | string | 兑换汇率(平均成交价) |
| data.list.source_success_amount | string | 兑换币实际兑换金额 (一般兑换模式存在部分兑换) |
| data.list.source_failed_amount | string | 兑换币兑换失败金额(系统会自动退回至兑换账户) |
| data.list.user_id | string | 用户ID |
| date_time | string | 北京时间 |
| time_stamp | string | 响应时间单位秒 |
兑换回调通知
回调请求示例:
POST <商户提供的回调地址>
Content-Type: application/json
X-Cbc-Timestamp: 1792382460
X-Cbc-Nonce: 9f2c4e6a8b0d1f3e5a7c9e1b3d5f7a9c
X-Cbc-Sign-Alg: RSA-SHA256
X-Cbc-Signature: <base64>
{
"data": {
"trade_id": "20200114202903274786",
"order_id": "2020010211153423123456",
"user_id": "1",
"source_coin": "eth",
"target_coin": "usdt",
"source_amount": "10",
"source_success_amount": "10",
"source_failed_amount": "0",
"target_amount": "25000",
"exchange_rate": "2500",
"exchange_fee": "1",
"limit_price": "0",
"type": "1",
"status": 1,
"time": 1650011196
}
}
http.HandleFunc("/notify/exchange", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
if err := cbc.VerifyBody(r.Header, body, client.PlatformKey, true); err != nil {
http.Error(w, "invalid signature", http.StatusUnauthorized)
return
}
// 验签已通过:按 X-Cbc-Nonce 去重后再解析 body,处理 data
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"status":200,"data":{"success_data":"success"}}`))
})
$body = file_get_contents('php://input');
$headers = array_change_key_case(getallheaders(), CASE_LOWER);
try {
CbcClient::verifyBody($headers, $body, $platformPublicKeyPem, true);
} catch (RuntimeException $e) {
http_response_code(401);
exit;
}
// 验签已通过:按 X-Cbc-Nonce 去重后再解析 body,处理 data
$notify = json_decode($body, true);
header('Content-Type: application/json');
echo '{"status":200,"data":{"success_data":"success"}}';
app.post('/notify/exchange', express.raw({ type: 'application/json' }), (req, res) => {
try {
verifyBody((name) => req.get(name), req.body, platformPublicKeyPem, true);
} catch (e) {
return res.status(401).end();
}
// 验签已通过:按 X-Cbc-Nonce 去重后再解析 body,处理 data
const notify = JSON.parse(req.body);
res.type('application/json').send('{"status":200,"data":{"success_data":"success"}}');
});
@PostMapping(value = "/notify/exchange", produces = "application/json")
public ResponseEntity<String> notify(@RequestHeader HttpHeaders headers, @RequestBody byte[] body) {
Map<String, String> sig = new HashMap<>();
for (String name : new String[]{"X-Cbc-Timestamp", "X-Cbc-Nonce", "X-Cbc-Sign-Alg", "X-Cbc-Signature"}) {
sig.put(name, headers.getFirst(name));
}
try {
CbcClient.verifyBody(sig, body, platformKey, true);
} catch (Exception e) {
return ResponseEntity.status(401).build();
}
// 验签已通过:按 X-Cbc-Nonce 去重后再解析 body,处理 data
return ResponseEntity.ok("{\"status\":200,\"data\":{\"success_data\":\"success\"}}");
}
商户应答示例:
{
"status": 200,
"data": {
"success_data": "success"
}
}
兑换结果通知(成功/失败),有平台发起请求,商户响应
HTTP Request
POST: 具体回调地址,由商户提供给平台方
请求参数
请求 Header 与接收端校验步骤见回调与复核签名。先用平台公钥验签,通过后再解析 body;下表为 body 中的字段。
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| data | 否 | string | 回调通知携带数据结构 |
| data.trade_id | 是 | string | 商家交易订单号 |
| data.order_id | 是 | string | 平台兑换订单号 |
| data.source_coin | 是 | string | 兑换币 |
| data.target_coin | 是 | string | 兑换目标币 |
| data.source_amount | 是 | string | 实际兑换币数量 |
| data.target_amount | 是 | string | 兑换获得目标币金额 |
| data.exchange_rate | 是 | string | 汇率(平均成交价) |
| data.exchange_fee | 是 | string | 兑换手续费(单位为目标币) |
| data.limit_price | 是 | string | 限价 |
| data.type | 是 | string | 兑换模式(0一般兑换/1平仓模式) |
| data.status | 是 | string | 订单状态:0 待审核、1 兑换完成、2 待处理、5 审核通过、10 审核不通过、20 转账失败 |
| data.time | 是 | integer | 发生时间(时间戳) |
| data.source_success_amount | 是 | string | 兑换币实际兑换金额 (一般兑换模式存在部分兑换) |
| data.source_failed_amount | 是 | string | 兑换币兑换失败金额(系统会自动退回至兑换账户) |
| data.user_id | 是 | string | 用户ID |
返回参数说明
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| status | 是 | integer | 状态码 |
| data | 是 | object | 返回数据对象 |
| data.success_data | 是 | string | success 接收成功 |