wechat->callback(Request()->post()); if ($result && $result->event_type == 'TRANSACTION.SUCCESS') { $ciphertext = $result->resource['ciphertext']; if ($ciphertext['trade_state'] === 'SUCCESS') { $attach = $ciphertext['attach']; switch ($attach) { case 'recharge': PayNotifyLogic::handle('recharge', $ciphertext['out_trade_no'], $ciphertext); $app->wechat->success(); break; case 'wechat_common': PayNotifyLogic::handle('wechat_common', $ciphertext['out_trade_no'], $ciphertext); $app->wechat->success(); break; default: Log::error('支付回调失败,订单号:' . $ciphertext['out_trade_no'], $ciphertext); break; } } } else { if ($result && $result->event_type == 'REFUND.SUCCESS') { $ciphertext = $result->resource['ciphertext']; Cache::set('7logC' . time(), json_encode($ciphertext)); if ($ciphertext['refund_status'] === 'SUCCESS') { //处理订单 -1判断是退的一单还是拆分的订单 $out_trade_no = $ciphertext['out_trade_no'] . '-1'; $check = StoreOrder::where('order_id', $out_trade_no)->count(); if ($check) { $ciphertext['out_trade_no'] = $out_trade_no; } PayNotifyLogic::handle('refund', $ciphertext['out_trade_no'], $ciphertext); $app->wechat->success(); } } } } /** * @notes 查询订单支付状态 */ public function wechatQuery() { $order_no = $this->request->get('order_no'); $order = [ 'out_trade_no' => $order_no, ]; $app = new PayService(0); try { $res = $app->wechat->query($order); } catch (\Exception $e) { return $this->fail($e->extra['message'] ?? $e->getMessage()); } if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { $attach = $res['attach']; switch ($attach) { case 'recharge': PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); $app->wechat->success(); break; case 'wechat_common': PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); $app->wechat->success(); break; default: Log::error('支付回调失败,订单号:' . $res['out_trade_no'], $res); break; } return $this->success('支付成功'); } else { return $this->fail('订单支付中'); } } /** * 支付宝同步回调地址 */ public function alipay_return() { $app = new PayService(); $result = $app->alipay->callback(Request()->post()); if ($result) { $data = $result->toArray(); if ($data['trade_status'] === 'TRADE_SUCCESS') { $attach = $data['extend_params']['attach'] ?? ''; switch ($attach) { case 'alipay_cashier': PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data); $app->alipay->success(); break; } } } } /** * 支付宝异步回调地址 */ public function alipay_notify() { $app = new PayService(); $result = $app->alipay->callback(Request()->post()); if ($result) { $data = $result->toArray(); if ($data['trade_status'] === 'TRADE_SUCCESS') { $attach = $data['extend_params']['attach'] ?? ''; switch ($attach) { case 'alipay_cashier': PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data); $app->alipay->success(); break; } } } } }