yansongda / pay

可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了
http://pay.yansongda.cn
MIT License
5.01k stars 1.03k forks source link

执行中出现异常:器未找到: `getContainer()` 方法调用失败! #1020

Closed cesarcool closed 3 weeks ago

cesarcool commented 3 weeks ago

包版本号

1.7.0

问题描述

偶发性报错:器未找到: getContainer() 方法调用失败! 或许你应该先 `setContainer()

你的代码

public function queryH5Order(string $payType, string $outTradeNo): array
{
    try {
        Pay::clear();
        //清理对象中的容器配置
        Pay::config($this->getShopAlipayConfig($payType));

        $order = [
            'out_trade_no' => $outTradeNo,
            '_action' => 'h5', // 查询 H5 订单
        ];

        $queryResult = Pay::alipay()->query($order);

        return $queryResult->toArray();

    } catch (ServiceException $serviceException) {
        throw $serviceException;
    } catch (InvalidConfigException $configException) {
        throw new ServiceException(12007, $configException->getMessage());
    } catch (Throwable $throwable) {
        dump($throwable->getMessage());
        throw new ServiceException(12008, $throwable->getMessage());
    }
}

报错详情

容器未找到: getContainer() 方法调用失败! 或许你应该先 `setContainer()

^ "容器未找到: getContainer() 方法调用失败! 或许你应该先 setContainer()" [DEBUG] Event Hyperf\Database\Events\QueryExecuted handled by Hyperf\Tracer\Listener\DbQueryExecutedListener listener. ^ 9101 ^ array:24 [ [DEBUG] Event Hyperf\Database\Events\QueryExecuted handled by App\Listener\DbQueryExecutedListener listener. [DEBUG] Event Hyperf\Database\Model\Events\Retrieved handled by Hyperf\ModelListener\Listener\ModelHookEventListener listener. 0 => array:5 [ [DEBUG] Event Hyperf\Database\Model\Events\Retrieved handled by Hyperf\ModelListener\Listener\ModelEventListener listener. "file" => "/opt/www/alipay/vendor/yansongda/artful/src/Artful.php" "line" => 153 "function" => "getContainer" "class" => "Yansongda\Artful\Artful" "type" => "::" ] 1 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Pay.php" "line" => 96 "function" => "get" "class" => "Yansongda\Artful\Artful" "type" => "::" ] 2 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Plugin/Alipay/V2/StartPlugin.php" "line" => 120 "function" => "get" "class" => "Yansongda\Pay\Pay" "type" => "::" ] 3 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Plugin/Alipay/V2/StartPlugin.php" "line" => 62 "function" => "getAppCertSn" "class" => "Yansongda\Pay\Plugin\Alipay\V2\StartPlugin" "type" => "->" ] 4 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Plugin/Alipay/V2/StartPlugin.php" "line" => 33 "function" => "getPayload" "class" => "Yansongda\Pay\Plugin\Alipay\V2\StartPlugin" "type" => "->" ] 5 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/supports/src/Pipeline.php" "line" => 93 "function" => "assembly" "class" => "Yansongda\Pay\Plugin\Alipay\V2\StartPlugin" "type" => "->" ] 6 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/supports/src/Pipeline.php" "line" => 57 "function" => "Yansongda\Supports{closure}" "class" => "Yansongda\Supports\Pipeline" "type" => "->" ] 7 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/artful/src/Artful.php" "line" => 257 "function" => "then" "class" => "Yansongda\Supports\Pipeline" "type" => "->" ] 8 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/artful/src/Artful.php" "line" => 236 "function" => "artful" "class" => "Yansongda\Artful\Artful" "type" => "::" ] 9 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Provider/Alipay.php" "line" => 59 "function" => "shortcut" "class" => "Yansongda\Artful\Artful" "type" => "::" ] 10 => array:5 [ "file" => "/opt/www/alipay/vendor/yansongda/pay/src/Provider/Alipay.php" "line" => 80 "function" => "__call" "class" => "Yansongda\Pay\Provider\Alipay" "type" => "->" ] 11 => array:5 [ "file" => "/opt/www/alipay/runtime/container/proxy/App_Library_Service_PayService.proxy.php" "line" => 41 "function" => "query" "class" => "Yansongda\Pay\Provider\Alipay" "type" => "->" ] 12 => array:5 [ "file" => "/opt/www/alipay/runtime/container/proxy/App_Command_UpdateAlipayOrder.proxy.php" "line" => 106 "function" => "queryH5Order" "class" => "App\Library\Service\PayService" "type" => "->" ] 13 => array:5 [ "file" => "/opt/www/alipay/runtime/container/proxy/App_Command_UpdateAlipayOrder.proxy.php" "line" => 80 "function" => "updateOrder" "class" => "App\Command\UpdateAlipayOrder" "type" => "->" ] 14 => array:5 [ "file" => "/opt/www/alipay/vendor/hyperf/command/src/Command.php" "line" => 177 "function" => "handle" "class" => "App\Command\UpdateAlipayOrder" "type" => "->" ] 15 => array:5 [ "file" => "/opt/www/alipay/vendor/hyperf/command/src/Command.php" "line" => 206 "function" => "Hyperf\Command{closure}" "class" => "Hyperf\Command\Command" "type" => "->" ] 16 => array:5 [ "file" => "/opt/www/alipay/vendor/symfony/console/Command/Command.php" "line" => 326 "function" => "execute" "class" => "Hyperf\Command\Command" "type" => "->" ] 17 => array:5 [ "file" => "/opt/www/alipay/vendor/hyperf/command/src/Command.php" "line" => 107 "function" => "run" "class" => "Symfony\Component\Console\Command\Command" "type" => "->" ] 18 => array:5 [ "file" => "/opt/www/alipay/app/Library/Utils/HyperfCommand.php" "line" => 32 "function" => "run" "class" => "Hyperf\Command\Command" "type" => "->" ] 19 => array:5 [ "file" => "/opt/www/alipay/app/Job/AlipayUpdateOrder.php" "line" => 33 "function" => "call" "class" => "App\Library\Utils\HyperfCommand" "type" => "::" ] 20 => array:5 [ "file" => "/opt/www/alipay/vendor/hyperf/async-queue/src/Driver/Driver.php" "line" => 110 "function" => "handle" "class" => "App\Job\AlipayUpdateOrder" "type" => "->" ] 21 => array:5 [ "file" => "/opt/www/alipay/vendor/hyperf/coroutine/src/Concurrent.php" "line" => 75 "function" => "Hyperf\AsyncQueue\Driver{closure}" "class" => "Hyperf\AsyncQueue\Driver\Driver" "type" => "->" ] 22 => array:5 [ "file" => "/opt/www/alipay/runtime/container/proxy/Hyperf_Coroutine_Coroutine.proxy.php" "line" => 82 "function" => "Hyperf\Coroutine{closure}" "class" => "Hyperf\Coroutine\Concurrent" "type" => "->" ] 23 => array:3 [ "function" => "Hyperf\Coroutine{closure}" "class" => "Hyperf\Coroutine\Coroutine" "type" => "::" ] ]

sdk 日志

nginx/apache 日志

涉及到 异步通知、同步通知 的问题,请贴出来

yansongda commented 3 weeks ago

看报错应该用的 hyperf,既然都 hyperf 了,为啥要 Pay::clear(); 呢?

去掉试试吧

cesarcool commented 3 weeks ago

我有多个商家的配置,需要动态加载。如果没有Pay::clear(),Pay对象会一直加载第一次读取到的商家配置。

yansongda commented 3 weeks ago

不是有多租户模式么?直接用多租户模式是不是就行了?

cesarcool commented 3 weeks ago

我们商家配置都在数据库,这样就不能用配置文件了。嗯,我试试动态生成的多租户模式吧。

cesarcool commented 3 weeks ago

多租户模式解决了这个问题,需要配合_force参数进行强制覆盖。目前看起来没有问题。感谢您的解答

yansongda commented 3 weeks ago

多租户模式解决了这个问题,需要配合_force参数进行强制覆盖。目前看起来没有问题。感谢您的解答

_force 也一样会有问题,只不过可能会报另外的错误,比如验签失败啥的