Skip to content

货币兑换

接口说明

  • 路径: /client/member/exchange-currency
  • 方法: POST
  • 说明: 允许会员自行将余额中的一种货币兑换为另一种货币。兑换率参考系统汇率设置。

请求参数

参数名类型必填说明
fromCurrencyString原货币代码 (例如 USD)
toCurrencyString目标货币代码 (例如 CNY)
amountNumber欲兑换的原货币金额

请求示例

POST /client/member/exchange-currency

json
{
  "fromCurrency": "USD",
  "toCurrency": "CNY",
  "amount": 100
}

返回参数

参数名类型说明
codeNumber状态码,0 表示成功
msgString提示信息
dataObject兑换结果
data.exchangedAmountNumber获得的最终目标货币金额
data.rateNumber本次兑换所使用的汇率

返回示例

json
{
  "code": 0,
  "msg": "兑换成功",
  "data": {
    "exchangedAmount": 720,
    "rate": 7.2
  }
}

常见错误状态及说明

code != 0 时,表示请求失败,以下为常见的报错 msg 提示及其原因:

错误 msg 提示原因分析
参数错误缺少必填参数,或 amount 格式不正确(必须为数字类型),或提交的数据格式不支持(已支持 JSON 和 Form-Data)。
失败: fromCurrency 或 toCurrency 没有 主货币兑换货币中必须包含系统的“主货币”(Base Currency)。不允许两种非主货币直接交叉兑换。
失败: 需要转换的 amount 数值大于 wallet amount用户的原货币 (fromCurrency) 钱包余额不足,无法完成本次兑换扣款。
验证失败: unauthorized
验证失败: invalid base token
未携带有效凭证。请检查 Request Header 中是否正确携带了 Authorization: Bearer <Your_Member_Token>
失败: cannot_convert_same_currencyfromCurrencytoCurrency 相同,不允许同币种兑换。
失败: amount_must_be_positive传入的 amount 必须大于 0。
失败: rate_not_found_for_xxx系统找不到对应货币的汇率配置,可能是输入了不支持的货币代码。