应用设置优化
This commit is contained in:
@@ -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.php(env)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user