获取会员详情
按自定义 ID 查询当前租户下未删除的会员,以及最近已保存的游戏数据。
POST
/v1/member/detail请求与响应均使用 JSON,字符编码为 UTF-8。通过 XXYZ_API_BASE_URL 设置 API 地址。16 服务器的内网接口地址为 http://10.10.200.16:20255。
会员不存在或已删除时返回失败。蜡烛、钞票和魂石以最近已保存的游戏钱包为准,不预测蜡烛恢复。
认证方式
以租户 app_secret 的 UTF-8 字节作为 HMAC 密钥。将 appId、timestamp、nonce 和计算得到的 sign 放入请求头。
签名公式
sign = HEX_LOWER(HMAC_SHA256(key=app_secret, message=签名原文))
租户须处于正常状态且未到期。会员在已认证租户范围内查找。完整规则见 请求签名。
请求参数
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | application/json |
appId | 是 | 非 0 开头的 10 位数字。 |
timestamp | 是 | 十进制 Unix 毫秒时间戳,允许时钟偏差 5 分钟。 |
nonce | 是 | 16 字节安全随机值编码成 32 位小写十六进制。每次调用生成新值。 |
sign | 是 | HMAC-SHA256 签名,64 位小写十六进制。 |
每个签名请求头填写一次。
JSON 正文
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
customId | string | 是 | 会员自定义 ID,1 至 32 个 Unicode 字符,区分大小写。首尾不得有空白,不得包含控制字符。 |
正文仅含 customId,不接受 null 或其他字段。正文上限 16 KiB。
以下固定时间戳和随机数仅用于核对签名。示例密钥见 请求签名。
请求示例
POST /v1/member/detail
Content-Type: application/json
appId: 1234567890
timestamp: 1794283200000
nonce: 00112233445566778899aabbccddeeff
sign: a43379f78660a768897ad80f4fd35f15b6c1ca95e3d5d060c8381adb7c70e92a
{
"customId": "user_10001"
}响应结构
| 字段 | 类型 | 说明 |
|---|---|---|
code | integer | 0 表示成功;非 0 表示失败。 |
message | string | 结果说明。业务判断以 code 为准。 |
data | object | null | 成功时为业务对象,失败时为 null。 |
requestId | string | 请求标识,与响应头 X-Request-ID 一致,用于排障。 |
timestamp | integer | 响应生成时间,Unix 毫秒时间戳。 |
成功数据 data
| 字段 | 类型 | 说明 |
|---|---|---|
customId | string | 当前租户下的会员自定义 ID。 |
nickname | string | 会员昵称。创建时省略或留空,保存为“玩家”。 |
stamina | integer | null | 最近已保存的蜡烛值;没有游戏钱包存档时为 null,不推算蜡烛恢复。 |
gold | string | null | 最近已保存的钞票值,以精确十进制字符串返回;没有游戏钱包存档时为 null。不要转换为浮点数。 |
diamonds | string | null | 最近已保存的魂石值;没有游戏钱包存档时为 null。 |
createTime | integer | 会员创建时间,Unix 毫秒时间戳。 |
updateTime | integer | 会员资料更新时间,Unix 毫秒时间戳。 |
创建会员与获取会员详情返回相同字段。没有游戏钱包存档时,stamina、gold、diamonds 均为 null。
成功响应
{
"code": 0,
"message": "成功",
"data": {
"customId": "user_10001",
"nickname": "小小猎手",
"stamina": 80,
"gold": "9007199254740993",
"diamonds": "50",
"createTime": 1794283200000,
"updateTime": 1794283200000
},
"requestId": "c651eab4c8ad4f8aa18994f108e89460c",
"timestamp": 1794283200000
}调用示例
通过环境变量配置 XXYZ_API_BASE_URL、XXYZ_APP_ID 和 XXYZ_APP_SECRET。自定义 ID 取自当前用户的账号映射。cURL 示例使用 Python 3 计算签名。
同一来源 IP 默认每分钟最多请求 120 次。业务码为 1005 时,按响应头 Retry-After 等待。
python3 - <<'PY'
import hashlib
import hmac
import json
import os
import secrets
import subprocess
import time
path = "/v1/member/detail"
app_id = os.environ["XXYZ_APP_ID"]
app_secret = os.environ["XXYZ_APP_SECRET"]
custom_id = "user_10001"
timestamp = str(time.time_ns() // 1_000_000)
nonce = secrets.token_hex(16)
signature_input = "\n".join([
"POST",
path,
f"appId={app_id}",
f"customId={custom_id}",
f"timestamp={timestamp}",
f"nonce={nonce}",
])
sign = hmac.new(
app_secret.encode("utf-8"),
signature_input.encode("utf-8"),
hashlib.sha256,
).hexdigest()
headers = "\n".join([
"Content-Type: application/json",
f"appId: {app_id}",
f"timestamp: {timestamp}",
f"nonce: {nonce}",
f"sign: {sign}",
]) + "\n"
subprocess.run([
"curl", "--request", "POST", os.environ["XXYZ_API_BASE_URL"].rstrip("/") + path,
"--header", "@-", "--max-time", "10",
"--data-binary", json.dumps({"customId": custom_id}, ensure_ascii=False),
], input=headers, text=True, check=True)
PYimport { createHmac, randomBytes } from 'node:crypto'
export async function getMemberDetail(customId) {
const path = '/v1/member/detail'
const appId = process.env.XXYZ_APP_ID
const appSecret = process.env.XXYZ_APP_SECRET
const timestamp = String(Date.now())
const nonce = randomBytes(16).toString('hex')
const signatureInput = [
'POST',
path,
'appId=' + appId,
'customId=' + customId,
'timestamp=' + timestamp,
'nonce=' + nonce
].join('\n')
const sign = createHmac('sha256', appSecret)
.update(signatureInput, 'utf8')
.digest('hex')
const response = await fetch(new URL(path, process.env.XXYZ_API_BASE_URL), {
method: 'POST',
headers: { 'Content-Type': 'application/json', appId, timestamp, nonce, sign },
body: JSON.stringify({ customId }),
signal: AbortSignal.timeout(10000)
})
const result = await response.json()
if (result.code !== 0) {
throw new Error('XXYZ API ' + result.code + ': ' + result.message +
' (requestId=' + result.requestId + ')')
}
return result.data
}<?php
function getMemberDetail(string $customId): array {
$path = '/v1/member/detail';
$appId = getenv('XXYZ_APP_ID');
$appSecret = getenv('XXYZ_APP_SECRET');
$timestamp = (string) (int) floor(microtime(true) * 1000);
$nonce = bin2hex(random_bytes(16));
$signatureInput = implode("\n", [
'POST',
$path,
'appId=' . $appId,
'customId=' . $customId,
'timestamp=' . $timestamp,
'nonce=' . $nonce,
]);
$sign = hash_hmac('sha256', $signatureInput, $appSecret);
$handle = curl_init(rtrim(getenv('XXYZ_API_BASE_URL'), '/') . $path);
curl_setopt_array($handle, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 3,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'appId: ' . $appId,
'timestamp: ' . $timestamp,
'nonce: ' . $nonce,
'sign: ' . $sign,
],
CURLOPT_POSTFIELDS => json_encode(['customId' => $customId], JSON_THROW_ON_ERROR),
]);
$body = curl_exec($handle);
curl_close($handle);
if ($body === false) {
throw new RuntimeException('XXYZ API 网络请求失败');
}
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if ($result['code'] !== 0) {
throw new RuntimeException(sprintf(
'XXYZ API %d: %s (requestId=%s)',
$result['code'], $result['message'], $result['requestId']
));
}
return $result['data'];
}错误码
错误码与处理方式见 完整错误码。业务判断以响应中的 code 为准。