log->event( LogLabel::WX_NOTIFY_REFUND, '进入回调' ); $config = config('wxpay'); $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; $get = $this->request->getQueryParams(); $post = $this->request->getParsedBody(); $cookie = $this->request->getCookieParams(); $files = $this->request->getUploadedFiles(); $server = $this->request->getServerParams(); $xml = $this->request->getBody()->getContents(); $app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml); /* 通知回调,进行业务处理 */ $response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { $this->log->event( LogLabel::WX_NOTIFY_REFUND, $message ); try { /* --- 退款失败 --- */ if ( empty($message) || !isset($message['result_code']) || $message['result_code'] != 'SUCCESS' ) { // 错误日志 $this->log->event( LogLabel::WX_NOTIFY_REFUND, $message ); $fail('Unknown error but FAIL'); return false; } /* --- 退款成功 --- */ $orderMain = OrderMain::select('id','global_order_id','money','user_id') ->where('global_order_id',$message['out_trade_no']) ->where('state',OrderMain::ORDER_STATE_REFUNDED) ->where(Db::raw('refund_time is null')) ->first(); if(!empty($orderMain)){ // 添加退款时间 $orderMain->refund_time = time(); $orderMain->save(); // 退款返还优惠券 $this->couponService->orderRefundCoupons($orderMain->global_order_id); // 删除特价商品缓存 $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); // 添加用户的流水 $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } } catch (\Exception $e) { $this->log->event( LogLabel::WX_NOTIFY_REFUND, ['exception_fail' => $e->getMessage()] ); $fail('Exception'); } }); return $this->response ->withHeader('Content-Type', 'text/xml') ->withStatus(200) ->withBody(new SwooleStream($response->getContent())); } }