用了octane加速后支付就一直回调失败

1. 运行环境

1). 当前使用的 Laravel 版本?

2). 当前使用的 php/php-fpm 版本?

PHP 版本:8.0

php-fpm 版本:8.0

3). 当前系统 centos 8

4). 业务环境 开发

5). 相关软件版本

2. 问题描述?

用了octane后回调就开始报错

 production.ERROR: INVALID_ARGUMENT: Convert To Array Error! Invalid Xml! {"exception":"[object] (Yansongda\\Pay\\Exceptions\\InvalidArgumentException(code: 3): INVALID_ARGUMENT: Convert To Array Error! Invalid Xml!

用的”yansongda/pay”: “2.*”进行支付
“laravel/octane”: “^1.5”,

3. 您期望得到的结果?

4. 您实际得到的结果?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
myttyy
最佳答案

octane 下要这样用

<?php
 use Yansongda\Pay\Pay;

 $xmls = app('request')->getContent(); 
 $data = Pay::wechat()->verify($xmls);
7个月前 评论
raybon 6个月前
讨论数量: 16

去掉 Octane 可以吗?

7个月前 评论
王大牛 (楼主) 7个月前

github.com/yansongda/pay/issues/31... 兄弟看一下这个issue

7个月前 评论
王大牛 (楼主) 7个月前

看代码应该不会是octane的问题。

 protected function getResult($path, $cert = false)
    {
        $this->config['sign'] = $this->getSign($this->config);

        if ($cert) {
            $data = $this->fromXml($this->post(
                $this->endpoint.$path,
                $this->toXml($this->config),
                [
                    'cert'    => $this->user_config->get('cert_client', ''),
                    'ssl_key' => $this->user_config->get('cert_key', ''),
                ]
            ));
        } else {
            $data = $this->fromXml($this->post($this->endpoint.$path, $this->toXml($this->config)));
        }

        if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
            $error = 'getResult error:'.$data['return_msg'];
            $error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
        }

        if (!isset($error) && $this->getSign($data) !== $data['sign']) {
            $error = 'getResult error: return data sign error';
        }

        if (isset($error)) {
            throw new GatewayException(
                $error,
                20000,
                $data);
        }

        return $data;
    }
    protected function fromXml($xml)
    {
        if (!$xml) {
            throw new InvalidArgumentException('convert to array error !invalid xml');
        }

        libxml_disable_entity_loader(true);

        return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
    }
7个月前 评论
王大牛 (楼主) 7个月前
springlee (作者) 7个月前
springlee (作者) 7个月前
王大牛 (楼主) 7个月前
  1. 改成octane 之后,内部是一个go 二进制启动的服务,你的每一次请求确保不同线程使用数据是安全的绑定方式
    $this->app->singleton(Service::class, function (Application $app) {
    return new Service(fn () => $app['request']);
    });
    可以尝试打印一下你拿到的请求对象,是走的 nginx 进来,还是走的octane进来的,你这个是看着像是参数对象为空,没拿到请求的内容
7个月前 评论

production.ERROR: INVALID_ARGUMENT: Convert To Array Error! Invalid Xml! {“exception”:”[object] (Yansongda\Pay\Exceptions\InvalidArgumentException(code: 3): INVALID_ARGUMENT: Convert To Array Error! Invalid Xml!

我觉得你应该开启日志,日志调试看看接收到的xml是个啥,甚至xml 都没接收到吗?swoole request 和 fpm 不一样,毕竟swoole 自己实现的http协议。你说的这个Yansongda\Pay包开发者很可能没考虑octane swoole httpserver,你完全可以给包作者提交个issue让他考虑兼容下。
毕竟一直以来都是打算给PHP-FPM使用的,明白了?

7个月前 评论

主要是我不用这个 不然我就一步步帮你去调试了 你可以在底层报错位置打印一下参数是否正常

7个月前 评论

octane 和nginx php版本一样吗 ,两种方式接收到参数一步一步打日志看是哪一步参数不一样了 就行了

7个月前 评论
myttyy

octane 下要这样用

<?php
 use Yansongda\Pay\Pay;

 $xmls = app('request')->getContent(); 
 $data = Pay::wechat()->verify($xmls);
7个月前 评论
raybon 6个月前
"yansongda/laravel-pay": "^3.5",
"laravel/octane": "^2.0",

可以在 octane 下正常运行的示例如下

public function foo(Request $request) {
  $result = Pay::wechat()->callback($request->all());
}
3个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!