应用设置优化

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
@@ -37,7 +37,14 @@ class PaymentController extends BaseMiniController
return $value;
};
// 支付方式开关(Checkbox 配置自动转数组;未配置时默认全部启用)
$payMethods = site_config('pay.pay_methods');
if (! is_array($payMethods)) {
$payMethods = ['wechat_qrcode', 'alipay_qrcode', 'bank', 'online'];
}
return $this->success([
'pay_methods' => array_values($payMethods),
'wechat_qrcode' => $resolve(site_config('pay.wechat_qrcode', '')),
'alipay_qrcode' => $resolve(site_config('pay.alipay_qrcode', '')),
'bank_info' => (string) site_config('pay.bank_info', ''),
+3 -3
View File
@@ -395,12 +395,12 @@ class OnlinePaymentService
*/
protected function subAppid(): string
{
$subAppid = (string) site_config('pay.wangpu_sub_appid', '');
$subAppid = (string) site_config('wangpu.sub_appid', '');
if ($subAppid === '') {
$subAppid = (string) config('services.wangpu.sub_appid', '');
}
if ($subAppid === '') {
$subAppid = (string) config('services.wechat.mini.appid', '');
$subAppid = $this->wechat->appid();
}
return trim($subAppid);
}
@@ -410,7 +410,7 @@ class OnlinePaymentService
*/
protected function wxpayMchId(): string
{
$mchId = (string) site_config('pay.wxpay_mch_id', '');
$mchId = (string) site_config('wxpay.mch_id', '');
if ($mchId === '') {
$mchId = (string) config('services.wxpay.mch_id', '');
}
+2 -2
View File
@@ -16,7 +16,7 @@ use Illuminate\Support\Str;
* - 整体以 JSON 信封 POST{serialNo, version, timestamp, data, signature, extras, organizNo}
* - 应答/通知反向解密:商户私钥解 signature 得 AES 密钥,再用其解 data 得业务报文。
*
* 配置优先级:后台「系统设置 → 支付配置」(site_config pay.wangpu_*) > config/services.phpenv
* 配置优先级:后台「系统设置 → 旺铺支付」(site_config wangpu.*) > config/services.phpenv
*/
class WangpuPayService
{
@@ -279,7 +279,7 @@ class WangpuPayService
*/
protected function config(string $key): string
{
$value = site_config('pay.wangpu_' . $key, '');
$value = site_config('wangpu.' . $key, '');
if ($value === null || $value === '') {
$value = config('services.wangpu.' . $key, '');
}
+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);
}
}
+5 -2
View File
@@ -15,7 +15,7 @@ use Throwable;
* - 交易查询:GET /v3/pay/transactions/out-trade-no/{商户订单号}
* - 支付通知:Wechatpay-Signature 验签(配置平台证书/公钥时)+ APIv3 密钥 AES-256-GCM 解密报文
*
* 配置优先级:后台「系统设置 → 支付配置」(site_config pay.wxpay_*) > config/services.phpenv
* 配置优先级:后台「系统设置 → 微信官方支付」(site_config wxpay.*) > config/services.phpenv
*/
class WechatPayService
{
@@ -212,6 +212,9 @@ class WechatPayService
protected function appid(): string
{
$appid = $this->config('appid');
if ($appid === '') {
$appid = (string) site_config('wechat.mini_appid', '');
}
if ($appid === '') {
$appid = (string) config('services.wechat.mini.appid', '');
}
@@ -246,7 +249,7 @@ class WechatPayService
*/
protected function config(string $key): string
{
$value = site_config('pay.wxpay_' . $key, '');
$value = site_config('wxpay.' . $key, '');
if ($value === null || $value === '') {
$value = config('services.wxpay.' . $key, '');
}