chore: prepare anxinyan release
This commit is contained in:
@@ -8,6 +8,8 @@ use support\think\Db;
|
||||
|
||||
class SystemConfigsController
|
||||
{
|
||||
private const H5_OAUTH_REDIRECT_HASH_PATH = '/#/pages/auth/login';
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->bootstrapDefaults();
|
||||
@@ -23,6 +25,7 @@ class SystemConfigsController
|
||||
foreach ($configs as $item) {
|
||||
$configMap[$item['config_group'] . '.' . $item['config_key']] = $item['config_value'] ?? '';
|
||||
}
|
||||
$this->applyDerivedConfigValues($configMap);
|
||||
|
||||
$groups = [];
|
||||
foreach ($this->definitions() as $groupCode => $group) {
|
||||
@@ -38,6 +41,7 @@ class SystemConfigsController
|
||||
'placeholder' => $item['placeholder'],
|
||||
'remark' => $item['remark'],
|
||||
'is_secret' => (bool)$item['is_secret'],
|
||||
'read_only' => (bool)($item['read_only'] ?? false),
|
||||
'options' => $item['options'] ?? [],
|
||||
'visible_when' => $item['visible_when'] ?? null,
|
||||
'value' => $configMap[$groupCode . '.' . $item['config_key']] ?? '',
|
||||
@@ -74,6 +78,7 @@ class SystemConfigsController
|
||||
}
|
||||
}
|
||||
|
||||
$submittedConfigKeys = [];
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
@@ -87,6 +92,18 @@ class SystemConfigsController
|
||||
}
|
||||
|
||||
$configValueMap[$mapKey] = (string)($item['config_value'] ?? '');
|
||||
$submittedConfigKeys[$mapKey] = [
|
||||
'config_group' => $groupCode,
|
||||
'config_key' => $configKey,
|
||||
];
|
||||
}
|
||||
|
||||
$this->applyDerivedConfigValues($configValueMap);
|
||||
if (isset($submittedConfigKeys['h5.page_base_url']) || isset($submittedConfigKeys['h5.oauth_redirect_url'])) {
|
||||
$submittedConfigKeys['h5.oauth_redirect_url'] = [
|
||||
'config_group' => 'h5',
|
||||
'config_key' => 'oauth_redirect_url',
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -99,14 +116,10 @@ class SystemConfigsController
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$groupCode = trim((string)($item['config_group'] ?? ''));
|
||||
$configKey = trim((string)($item['config_key'] ?? ''));
|
||||
$configValue = (string)($item['config_value'] ?? '');
|
||||
foreach ($submittedConfigKeys as $mapKey => $configMeta) {
|
||||
$groupCode = $configMeta['config_group'];
|
||||
$configKey = $configMeta['config_key'];
|
||||
$configValue = (string)($configValueMap[$mapKey] ?? '');
|
||||
$mapKey = $groupCode . '.' . $configKey;
|
||||
|
||||
if ($groupCode === '' || $configKey === '' || !isset($allowedMap[$mapKey])) {
|
||||
@@ -405,8 +418,8 @@ class SystemConfigsController
|
||||
'items' => [
|
||||
['config_key' => 'app_id', 'title' => 'H5 AppID', 'field_type' => 'text', 'placeholder' => '请输入 H5 AppID', 'remark' => '用于 H5 登录与开放平台接入', 'is_secret' => false],
|
||||
['config_key' => 'app_secret', 'title' => 'H5 AppSecret', 'field_type' => 'password', 'placeholder' => '请输入 H5 AppSecret', 'remark' => '请妥善保管,仅后台可见', 'is_secret' => true],
|
||||
['config_key' => 'oauth_redirect_url', 'title' => '授权回调地址', 'field_type' => 'text', 'placeholder' => '请输入 H5 授权回调地址', 'remark' => '用于 H5 登录或支付回调', 'is_secret' => false],
|
||||
['config_key' => 'page_base_url', 'title' => 'H5 页面根地址', 'field_type' => 'text', 'placeholder' => '例如 https://m.anxinyan.com', 'remark' => '用于生成扫码查看报告和验真页的完整 H5 链接', 'is_secret' => false],
|
||||
['config_key' => 'oauth_redirect_url', 'title' => '授权回调地址', 'field_type' => 'text', 'placeholder' => '保存 H5 页面根地址后自动生成', 'remark' => '由 H5 页面根地址自动拼接,无需手动填写。', 'is_secret' => false, 'read_only' => true],
|
||||
['config_key' => 'page_base_url', 'title' => 'H5 页面根地址', 'field_type' => 'text', 'placeholder' => '例如 https://m.anxinjianyan.com', 'remark' => '用于生成扫码查看报告和验真页的完整 H5 链接', 'is_secret' => false],
|
||||
],
|
||||
],
|
||||
'payment' => [
|
||||
@@ -501,4 +514,38 @@ class SystemConfigsController
|
||||
throw new \RuntimeException('当前已切换为七牛云存储,请至少填写公开访问域名或七牛公网访问域名');
|
||||
}
|
||||
}
|
||||
|
||||
private function applyDerivedConfigValues(array &$configValueMap): void
|
||||
{
|
||||
$configValueMap['h5.oauth_redirect_url'] = $this->buildH5OAuthRedirectUrl((string)($configValueMap['h5.page_base_url'] ?? ''));
|
||||
}
|
||||
|
||||
private function buildH5OAuthRedirectUrl(string $pageBaseUrl): string
|
||||
{
|
||||
$baseUrl = $this->normalizeH5PageBaseUrl($pageBaseUrl);
|
||||
if ($baseUrl === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $baseUrl . self::H5_OAUTH_REDIRECT_HASH_PATH;
|
||||
}
|
||||
|
||||
private function normalizeH5PageBaseUrl(string $value): string
|
||||
{
|
||||
$baseUrl = trim($value);
|
||||
if ($baseUrl === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$hashPos = strpos($baseUrl, '#');
|
||||
if ($hashPos !== false) {
|
||||
$baseUrl = substr($baseUrl, 0, $hashPos);
|
||||
}
|
||||
|
||||
if (!preg_match('/^https?:\/\//i', $baseUrl)) {
|
||||
$baseUrl = 'https://' . ltrim($baseUrl, '/');
|
||||
}
|
||||
|
||||
return rtrim($baseUrl, '/');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user