swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

swoft2.0.4使用easywechat的支付通知 #919

Closed etoup closed 5 years ago

etoup commented 5 years ago
Q A
Swoft version 2.0.4
Swoole version 4.4.2
PHP version 7.2.18
Runtime environment Mac/Docker etc.

Details

无法使用easywechat闭包操作

public function payback() {
        print_r('ok');
        $response = $this->app->handlePaidNotify(function($message, $fail) {
            print_r('in');
            $order = $this->dao->info($message['out_trade_no']);
            if (!$order || $order->status === 20) {
                return true;
            }
//            $info = $this->app->order->queryByOutTradeNumber($message['out_trade_no']);
            if ($message['return_code'] === 'SUCCESS') {
                if ($message['result_code'] === 'SUCCESS') {
                    $order->update(['status' => 20]);
                } elseif ($message['result_code'] === 'FAIL') {
                    $order->update(['status' => -20]);
                }
            } else {
                return $fail('通信失败,请稍后再通知我');
            }

            return true;
        });
        print_r('res');
        $response->send();
    }

只能打印出来"ok",无法进去闭包体打印"in",无法进行订单状态调整,请教如何处理,谢谢!

stelin commented 5 years ago

你首先要定位下具体是什么问题,这样提出问题,我们不知道怎么解决。

etoup commented 5 years ago

我这边自己处理好了,反正不能使用easywechat 4.1.的$this->app->handlePaidNotify闭包,好像是easywechat不支持 PSR-7 的 HTTP 消息实现,easywechat 预计在5.版本会加入相关支持。

lijiuhui commented 5 years ago

我这边自己处理好了,反正不能使用easywechat 4.1.的$this->app->handlePaidNotify闭包,好像是easywechat不支持 PSR-7 的 HTTP 消息实现,easywechat 预计在5.版本会加入相关支持。

rebind一下request就好了 $app->rebind('request', $request);

etoup commented 5 years ago

@lijiuhui 请问具体如何使用?

etoup commented 5 years ago

@lijiuhui 之前代码无法进去闭包打印‘in’

lijiuhui commented 5 years ago

@lijiuhui 之前代码无法进去闭包打印‘in’ 不好意思哦,忙项目没有看到,这个可以解决。 https://github.com/swoft-cloud/swoft/issues/518