优化Token验证接口
This commit is contained in:
@@ -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-Signature;Body 对齐对端必填 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');
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 用户关联到商城用户',
|
||||
|
||||
@@ -12,7 +12,7 @@ use Webman\Http\Response;
|
||||
* 加载控制器语言包中间件(Webman 迁移版,等价 ThinkPHP LoadLangPack)
|
||||
* 根据当前路由加载对应控制器的语言包到 Translator
|
||||
*
|
||||
* 对外 api/:优先请求头 lang(zh / zh-cn → zh-cn,en → en,ms → 马来语包),未传则 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 未设置时仍可生效)
|
||||
|
||||
Reference in New Issue
Block a user