应用设置优化

This commit is contained in:
liu
2026-09-04 20:37:34 +08:00
parent c986c86ed5
commit 52e339cdd3
10 changed files with 127 additions and 33 deletions
+26 -2
View File
@@ -22,8 +22,8 @@ class WechatMiniService
*/
public function code2session(string $code): string
{
$appid = trim((string) config('services.wechat.mini.appid'));
$secret = trim((string) config('services.wechat.mini.secret'));
$appid = $this->appid();
$secret = $this->config('mini_secret');
if ($appid === '' || $secret === '') {
throw new RepositoryException('微信小程序未配置 AppID/Secret,请联系管理员');
}
@@ -45,4 +45,28 @@ class WechatMiniService
return $openid;
}
/**
* 小程序 AppID(在线支付下单 appid 兜底等场景复用)
*/
public function appid(): string
{
return $this->config('mini_appid');
}
/**
* 读取应用配置:后台站点配置(微信应用配置分组)优先,为空回退 config/services.phpenv
*/
protected function config(string $key): string
{
$value = site_config('wechat.' . $key, '');
if ($value === null || $value === '') {
$value = match ($key) {
'mini_appid' => config('services.wechat.mini.appid', ''),
'mini_secret' => config('services.wechat.mini.secret', ''),
default => '',
};
}
return trim((string) $value);
}
}