diff --git a/plugin/think-plugs-wechat/src/service/PaymentService.php b/plugin/think-plugs-wechat/src/service/PaymentService.php index c99efc1ad..ee6a59860 100644 --- a/plugin/think-plugs-wechat/src/service/PaymentService.php +++ b/plugin/think-plugs-wechat/src/service/PaymentService.php @@ -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)); } /** diff --git a/plugin/think-plugs-wechat/src/service/WechatService.php b/plugin/think-plugs-wechat/src/service/WechatService.php index 873d2e42a..b9ac86fc7 100644 --- a/plugin/think-plugs-wechat/src/service/WechatService.php +++ b/plugin/think-plugs-wechat/src/service/WechatService.php @@ -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();