all(); echo getDateFull()."===自研应用回调WebHook===\n"; echo json_encode($data)."\n"; if (isset($data['event']) && $data['event'] == "verify_webhook") { return json(['challenge' => $data['content']['challenge']]); } if (empty($data['content'])) return error("无传值数据"); $content = json_decode($data['content'],true); if (isset($content['action'])) { switch ($content['action']) { case "refund_success": // 退款 $orderData = $content['certificate']; if (empty($orderData)) return error("order.error"); $order = (new HxOrderLife)->where("order_id",$orderData['order_id'])->findOrEmpty(); if ($order->isEmpty()) return error("order.error"); $order->status = 2; $order->order_status = '交易关闭'; $order->refund_at = getDateFull(); $order->save(); break; case "pay_success": // 支付成功 $orderData = $content['order']; if (empty($orderData)) return error("order.error"); $order = (new HxOrderLife)->where("order_id",$orderData['order_id'])->findOrEmpty(); if ($order->isEmpty()) { $agent = (new HxAgent)->where("account",$orderData['account_id'])->findOrEmpty(); $orderData['agent_id'] = $agent['agent_id']??''; $orderData['pay_at'] = date("Y-m-d H:i:s",$orderData['pay_time']); $orderData['create_at'] = date("Y-m-d H:i:s",$orderData['create_time']); // 订单创建时间 $order->strict(false)->insertGetId($orderData); } break; case "verify_cancel": // 撤销核销 $orderData = $content['certificate']; if (empty($orderData)) return error("order.error"); $order = (new HxOrderLife)->where("order_id",$orderData['order_id'])->findOrEmpty(); if ($order->isEmpty()) return error("order.error"); if ($order['status'] <> 4) return error("order.error"); $order->status = 1; $order->order_status = '履约中'; $order->save(); break; default: break; } } if ($data['event'] == 'life_hermes_akte_after_sale_audit') { // 核销后申请售后 $order = (new HxOrderLife)->where("order_id",$content['order_id'])->findOrEmpty(); if (!$order->isEmpty()) { $order->status = 3; $order->order_status = '退款审核中'; $order->refund_apply_at = getDateFull(); $order->save(); } } return success('ok',$data); } catch (\Throwable $throwable) { echo getDateFull()."==webhook-error\n"; echo $throwable->getMessage()."\n"; echo $throwable->getFile()."【".$throwable->getLine()."】\n"; return error($throwable->getMessage()); } } public function getSpiData(Request $request): Response { try { $data = $request->all(); echo getDateFull()."===自研应用回调SPI===\n"; echo json_encode($data)."\n"; return response(json_encode($data)); } catch (\Throwable $th) { return response($th->getMessage()); } } public function getToken(Request $request): Response { try { $param = v_valid([ "agent.require" => "订单信息错误" ]); if (!is_array($param)) return error($param); $config = (new HxAgent)->where("account",$param['agent'])->findOrEmpty(); $config['version'] = "res"; $token = (new BasicLife)->config($config->toArray())->token()->getAccessToken(); return success('ok',compact('token')); } catch (\Throwable $th) { return response($th->getMessage()); } } }