优化Token验证接口

This commit is contained in:
2026-05-06 10:18:26 +08:00
parent 05f2d6f084
commit 04680408e6
11 changed files with 59 additions and 31 deletions

View File

@@ -449,10 +449,10 @@ class Playx extends Api
return $this->error(__('PlayX API not configured'));
}
// 与 angpow-imports 一致HMAC-SHA1 → Base64密钥 hex/base64 兼容;仅 X-Request-Signature
$reportDate = strval(time());
// 与 angpow-imports 同源HMAC-SHA1 → Base64仅 X-Request-SignatureBody 对齐对端必填 request_date + PlayX 文档 request_id/token
$requestDate = strval(time());
$signatureInput = 'merchant_code=' . $merchantCode
. '&report_date=' . $reportDate
. '&request_date=' . $requestDate
. '&request_id=' . $requestId
. '&token=' . $token;
$signature = $this->buildPlayxTokenVerifySignature($signatureInput, $authKey);
@@ -461,14 +461,13 @@ class Playx extends Api
}
$headers = [
'Content-Type' => 'application/json',
'X-Request-Signature' => $signature,
'Content-Type' => 'application/json',
'X-Request-Signature' => $signature,
];
$payload = [
'merchant_code' => $merchantCode,
'report_date' => $reportDate,
'request_id' => $requestId,
'token' => $token,
'request_id' => $requestId,
'request_date' => $requestDate,
'token' => $token,
];
$res = $client->post($targetVerifyUrl, [
'headers' => $headers,
@@ -527,7 +526,7 @@ class Playx extends Api
}
}
if ($remoteMsg === '' || str_contains(strtolower($remoteMsg), '<html')) {
$remoteMsg = 'PlayX verify-token failed: HTTP ' . strval($code) . ' at ' . $targetVerifyUrl;
$remoteMsg = __('PlayX verify upstream failed', [strval($code), $targetVerifyUrl]);
}
$msg = $remoteMsg !== '' ? $remoteMsg : __('Token expiration');

View File

@@ -60,6 +60,7 @@ return [
'nicknameChsDash' => 'Username may only contain letters, numbers, underscores and dashes',
'Invalid token' => 'Invalid or expired token',
'PlayX API not configured' => 'PlayX API is not configured',
'PlayX verify upstream failed' => 'Upstream token verification failed (HTTP %s): %s',
'Duplicate input' => 'Duplicate submission',
'Ok' => 'OK',
'Failed to map playx user to mall user' => 'Failed to map PlayX user to mall user',

View File

@@ -61,6 +61,7 @@ return [
'nicknameChsDash' => 'Nama pengguna hanya huruf, nombor, garis bawah dan sempang',
'Invalid token' => 'Token tidak sah atau tamat tempoh',
'PlayX API not configured' => 'API PlayX tidak dikonfigurasi',
'PlayX verify upstream failed' => 'Pengesahan token hulu gagal (HTTP %s): %s',
'Duplicate input' => 'Penghantaran pendua',
'Ok' => 'OK',
'Failed to map playx user to mall user' => 'Gagal memetakan pengguna PlayX ke pengguna mall',

View File

@@ -62,6 +62,7 @@ return [
// PlayX API v1 /api/v1/*
'Invalid token' => '令牌无效或已过期',
'PlayX API not configured' => '未配置 PlayX 接口地址',
'PlayX verify upstream failed' => '上游 Token 校验失败HTTP %s%s',
'Duplicate input' => '重复提交',
'Ok' => '成功',
'Failed to map playx user to mall user' => '无法将 PlayX 用户关联到商城用户',

View File

@@ -12,7 +12,7 @@ use Webman\Http\Response;
* 加载控制器语言包中间件Webman 迁移版,等价 ThinkPHP LoadLangPack
* 根据当前路由加载对应控制器的语言包到 Translator
*
* 对外 api/优先请求头 langzh / zh-cn → zh-cnen → enms → 马来语包),未传则 think-lang再默认 zh-cn不根据浏览器 Accept-Language
* 对外 api/语言优先级为 请求头 lang → GET/POST 参数 lang支持 zh/ZH、en/EN 等)→ think-lang再默认 zh-cn不根据浏览器 Accept-Language
* admin/think-lang → Accept-Language → 配置默认
*/
class LoadLangPack implements MiddlewareInterface
@@ -45,6 +45,16 @@ class LoadLangPack implements MiddlewareInterface
if ($langHeader !== '') {
$langSet = $this->normalizeLangHeader($langHeader, $allowLangList);
}
if ($langSet === null) {
$langParam = strval($request->get('lang', ''));
if ($langParam === '') {
$langParam = strval($request->post('lang', ''));
}
$langParam = trim($langParam);
if ($langParam !== '') {
$langSet = $this->normalizeLangHeader($langParam, $allowLangList);
}
}
}
// 与后台 Vue 一致的 think-lang对外 API 在 lang 未设置时仍可生效)