Skip to content

错误码

Coinepay OpenAPI 错误响应同时包含:

  • code:与 HTTP 状态码相同(200/400/401/404/409/429/500)
  • message:根据请求头 Accept-Language 返回中文或英文
  • message_key:稳定的英文 key,程序判断用这个
json
{
  "code": 400,
  "message": "Idempotency-Key 冲突",
  "message_key": "openapi_idempotency_key_conflict",
  "data": null
}

HTTP 状态码语义

HTTP含义
200成功(含"幂等返回"和"已入队")
400参数错 / 业务规则不满足(看 message_key 区分)
401鉴权失败(一律 openapi_invalid_credentials,不区分原因)
403鉴权通过但所请求的特性受限(如敏感卡信息的二次验证缺失/未通过、卡未激活)
404资源不存在 / 不属于当前账号
409幂等键冲突(同 key 不同 body)
429限流
500服务端异常

完整 message_key 字典

鉴权与凭证

message_keyzh-CNen-USHTTP
openapi_invalid_credentials无效的 OpenAPI 凭证Invalid OpenAPI credentials401

ID 校验

message_keyzh-CNen-USHTTP
openapi_invalid_header_idheader_id 不合法(缺前缀 / 错前缀 / 不存在)Invalid header_id400
openapi_invalid_package_idpackage_id 不合法Invalid package_id400
openapi_invalid_card_idcard_id 不合法Invalid card_id400

幂等

message_keyzh-CNen-USHTTP
openapi_idempotency_key_required缺少 Idempotency-Key 请求头Missing Idempotency-Key header400
openapi_idempotency_key_too_longIdempotency-Key 超长(最大 128 字符)Idempotency-Key too long400
openapi_idempotency_key_invalid_charsIdempotency-Key 含非法字符Invalid characters400
openapi_idempotency_key_conflictIdempotency-Key 冲突Idempotency-Key conflict409

业务规则

message_keyzh-CNen-USHTTP
openapi_card_type_not_supported暂不支持该卡类型,仅虚拟卡Not supported (virtual cards only)400
account_manager_bind_required该卡头需绑定客户经理后才能开通Account-manager-controlled header; bind an account manager first400
account_manager_unavailable绑定的客户经理已失效,请联系客服Your account manager is no longer active; contact support400
account_manager_open_disabled您的客户经理尚未对该账号开放此卡头 / 套餐Header / package not opened for your account by your account manager400
amount_requiredamount 为必填amount is required400
card_not_found卡片不存在 / 不属于当前账号Card not found404
insufficient_balance余额不足Insufficient balance400
kyc_required请先完成实名认证Please complete identity verification first400
kyc_not_approvedKYC 未通过KYC not approved400
virtual_g_name_invalid(G 卡)持卡人姓名不满足 ASCII 字母 / 单空格 / ≤40 字符规则(G card) cardholder name fails the rule400
virtual_g_required_fields_missing(G 卡)开卡资料不完整(G card) apply payload incomplete400
virtual_a_required_fields_missing(A 卡)first_name / last_name 缺失或为空白,或开卡资料不完整(A card) name missing/blank or apply payload incomplete400

首充(自定义金额)

/card/apply(作为 message_key,HTTP 400)与 /card/first_deposit/preview(作为 200 响应体内的 invalid_reason)返回,表示自定义 first_deposit_amount 不可受理。

message_keyzh-CNen-USHTTP
invalid_first_deposit_amountfirst_deposit_amount 必须是非负整数first_deposit_amount must be a non-negative integer400
first_recharge_below_base首充低于配置底额First deposit below the config base400
first_recharge_exceeds_max超额超过最大充值Excess exceeds max recharge400
first_recharge_limit_exceeded超额超过充值限额Excess exceeds the recharge limit400
first_recharge_asset_mismatch开卡费资产与充值资产不一致Open-fee asset differs from recharge asset400
first_recharge_excess_too_small超额扣费取整后过小Excess too small after fee + rounding400

敏感卡片信息

下列错误码由 /openapi/card/infowith_sensitive=true 前提不满足时)与 /openapi/card/sensitive/send_code 返回。敏感字段要求卡处于 status=2 (active),并通过用户二次验证或凭证免验证特权二者之一。

message_keyzh-CNen-USHTTP
email_code_required请输入邮箱验证码Please enter email verification code403
sms_code_required请输入短信验证码Please enter SMS verification code403
pin_required请输入 PIN 码Please enter PIN403
2fa_code_required请输入 2FA 验证码Please enter 2FA code403
invalid_email_code邮箱验证码错误Invalid email verification code403
invalid_sms_code短信验证码错误Invalid SMS verification code403
invalid_pinPIN 码错误Invalid PIN403
invalid_2fa_code2FA 验证码错误Invalid 2FA code403
email_not_verified邮箱未验证Email not verified403
phone_not_verified手机号未验证Phone not verified403
no_usable_auth_method无可用的认证方式No usable authentication method403
card_sensitive_access_banned通过 API 获取敏感卡片信息的权限已被管理员关闭Sensitive card info access via API has been disabled by the administrator403
openapi_sensitive_card_only_active仅激活状态的卡片可获取敏感信息Sensitive card info is only available for active cards.403
too_many_requests请求过于频繁(验证锁定 / 发码冷却,遵循 Retry-AfterToo many requests (verification locked / send cooldown; honor Retry-After)429
send_code_failed验证码发送失败(冷却已释放,可立即重试)Failed to send verification code (cooldown released, retry allowed)500

openapi_sensitive_card_info_disabled(403)不再返回:未开通免验证特权的凭证现在会落入用户二次验证路径,而不是被直接拒绝。

卡列表过滤

message_keyzh-CNen-USHTTP
openapi_conflicting_card_filtersusable_only 与 statuses 不能同时传usable_only and statuses cannot be used together400
openapi_invalid_status_valuestatuses 含非法状态值(仅允许 1-6)statuses contains an invalid value (only 1-6 allowed)400
invalid_min_balance最小余额必须是合法非负数字(如 0 或 10.5)min_balance must be a valid non-negative number400
invalid_max_balance最大余额必须是合法非负数字max_balance must be a valid non-negative number400
min_balance_exceeds_max_balance最小余额不能大于最大余额min_balance must not exceed max_balance400
invalid_date_format日期格式必须是 YYYY-MM-DDdate must be in YYYY-MM-DD format400

交易明细过滤

/transactions/list/card/transactions/list 返回。

message_keyzh-CNen-USHTTP
invalid_date_format交易时间格式必须为 YYYY-MM-DD HH:MM:SStransaction_time_from/to must be YYYY-MM-DD HH:MM:SS400
invalid_params参数无效(如金额格式错误)Invalid parameters (e.g. bad amount format)400

冻结 / 解冻

/card/freeze/card/unfreeze 返回。

message_keyzh-CNen-USHTTP
card_already_frozen卡片已被冻结Card is already frozen400
card_status_cannot_freeze当前卡状态不可冻结Current card status does not allow freezing400
card_not_frozen卡片未被冻结Card is not frozen400
card_type_mismatch卡类型与配置不匹配Card type does not match400
operation_not_supported该操作不支持Operation not supported for this card type400
recharge_unfreeze_disabled该卡不允许通过充值自动解冻Recharge-based unfreeze is not available400
unauthorized_unfreeze_admin该卡片被管理员冻结,用户无法自行解冻Frozen by admin — cannot self-unfreeze403
unauthorized_unfreeze_risk该卡片被风控冻结Frozen by risk control — cannot self-unfreeze403
unauthorized_unfreeze_system该卡片被系统冻结Frozen by system — cannot self-unfreeze403

销卡

/card/close 返回(v1.3 —— 端点自 v1.2 起已上线但此前未收录文档)。

message_keyzh-CNen-USHTTP
card_is_closing卡片正在注销中Card is being closed400
card_already_closed卡片已注销Card is already closed400
card_frozen_cannot_close卡片已冻结,无法注销Card is frozen and cannot be cancelled400
card_status_cannot_close当前卡状态不可注销Current card status does not allow cancellation400
close_not_accepted_by_upstream销卡未被上游受理,卡片已恢复为可用状态,请稍后重试Closure not accepted by the provider; card restored to active — retry later400
card_upstream_closed_pending_reconcile该卡已被上游直接注销,正在等待人工对账退款Card already closed by the provider; awaiting manual refund reconciliation400
card_config_not_found卡配置不存在Card configuration not found400
openapi_close_card_failed销卡失败Failed to close card500

服务端异常

message_keyzh-CNen-USHTTP
openapi_internal_errorOpenAPI 内部错误OpenAPI internal error500
openapi_list_card_headers_failed查询卡头列表失败Failed to list card headers500
openapi_list_card_configs_failed查询卡配置列表失败Failed to list card configs500
openapi_apply_card_failed申请虚拟卡失败Failed to apply virtual card500
openapi_first_deposit_preview_failed首充预览失败Failed to preview first deposit500
openapi_recharge_failed充值失败Failed to recharge500
openapi_get_card_info_failed获取卡片信息失败Failed to get card info500
openapi_list_cards_failed查询卡列表失败Failed to list cards500
openapi_list_webhook_events_failed查询 Webhook 事件历史失败Failed to list webhook events500
openapi_list_transactions_failed查询交易明细失败Failed to list transactions500
openapi_freeze_card_failed冻结卡片失败Failed to freeze card500
openapi_unfreeze_card_failed解冻卡片失败Failed to unfreeze card500

程序处理建议

python
def handle_response(resp):
    code = resp.get('code', 500)
    key = resp.get('message_key', '')

    if code == 200:
        return resp['data']
    if code == 401:
        # 永远是 openapi_invalid_credentials
        raise AuthError("凭证无效或已过期,请检查 AppID/Secret/时钟")
    if code == 403:
        # 鉴权通过但所请求的特性受限
        if key.endswith('_required'):
            raise PermissionError(f"缺少二次验证凭据({key})—— "
                                  "先调用 /openapi/card/sensitive/send_code 再重试")
        if key.startswith('invalid_'):
            raise PermissionError(f"二次验证未通过: {key}")
        if key == 'openapi_sensitive_card_only_active':
            raise RuntimeError("卡未激活,不能请求敏感字段")
        raise PermissionError(f"特性受限: {key}")
    if key == 'insufficient_balance':
        raise BalanceError("余额不足")
    if key == 'kyc_not_approved' or key == 'kyc_required':
        raise KYCError("KYC 未通过")
    if key.startswith('openapi_invalid_') and key.endswith('_id'):
        raise ValueError(f"ID 格式错或不存在: {key}")
    if key == 'openapi_idempotency_key_conflict':
        # 不应自动重试 —— 业务侧需检查 body
        raise IdempotencyConflict()
    if code == 429:
        raise RateLimited()
    if code >= 500:
        raise ServerError(resp.get('message', '内部错误'))

    raise ApiError(code, key, resp.get('message'))

多语言

通过请求头 Accept-Language 控制 message 的语言:

http
Accept-Language: en-US
取值行为
不传默认中文
zh-CN / zh中文
en-US / en英文
其他回退到默认

message_key 不受 Accept-Language 影响,永远稳定。

采用 MIT 等价条款发布