fix: 修改微信配置

This commit is contained in:
邹景立 2025-03-19 10:48:41 +08:00
parent c860a90b2c
commit 58859b98cc
2 changed files with 11 additions and 6 deletions

View File

@ -82,7 +82,7 @@ class PaymentService
if ($oPayed + $pAmount > floatval($oAmount)) {
return ['code' => 0, 'info' => '支付总额超出!', 'data' => [], 'params' => []];
}
$config = WechatService::getConfig();
$config = WechatService::getConfig('', true);
do $pCode = CodeExtend::uniqidNumber(16, 'P');
while (WechatPaymentRecord::mk()->master()->where(['code' => $pCode])->findOrEmpty()->isExists());
$data = [
@ -328,7 +328,7 @@ class PaymentService
*/
protected static function withPayment(?array $config = null): Order
{
return Order::instance($config ?: WechatService::getConfig());
return Order::instance($config ?: WechatService::getConfig('', true));
}
/**

View File

@ -178,19 +178,21 @@ class WechatService extends Service
/**
* 获取公众号配置参数
* @param string $appid
* @param string $appid 指定公众号
* @param boolean $ispay 获取支付参数
* @return array
* @throws \think\admin\Exception
*/
public static function getConfig(string $appid = ''): array
public static function getConfig(string $appid = '', bool $ispay = false): array
{
return static::withWxpayCert([
$config = [
'appid' => $appid ?: static::getAppid(),
'token' => sysconf('wechat.token'),
'appsecret' => sysconf('wechat.appsecret'),
'encodingaeskey' => sysconf('wechat.encodingaeskey'),
'cache_path' => syspath('runtime/wechat'),
]);
];
return $ispay ? $config : static::withWxpayCert($config);
}
/**
@ -220,6 +222,9 @@ class WechatService extends Service
{
// 文本模式主要是为了解决分布式部署
$data = sysdata('plugin.wechat.payment');
if (empty($data['mch_id'])) {
throw new Exception('无效的支付配置!');
}
$name1 = sprintf("wxpay/%s_%s_cer.pem", $data['mch_id'], md5($data['ssl_cer_text']));
$name2 = sprintf("wxpay/%s_%s_key.pem", $data['mch_id'], md5($data['ssl_key_text']));
$local = LocalStorage::instance();