table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)->first(); if (!$query) return 'fail'; // 订单不存在 $service = new WiwiPay(); $config = $service->config; // 构建提现请求参数 $params = [ "mchNo" => $service->mchNo, "mchOrderNo" => $OrderId, "amount" => intval($amount), "currency" => $config['currency'] ?? "usd", "accountName" => $accountName, "accountNo" => $phone, // 根据实际情况调整 "notifyUrl" => $config['cashNotify'] ?? $config['notify'] ?? '', "timestamp" => round(microtime(true) * 1000), "signType" => $config['signType'] ?? "MD5" ]; // 签名 $signedParams = $service->sign($params); $url = $config['cash_url'] ?? $service->apiUrl; Log::info('WiwiPay 提现参数:', $signedParams); try { $result = $service->curlPost($url, $signedParams); } catch (\Exception $exception) { Log::info('WiwiPay 提现请求异常:', [$exception->getMessage()]); return 'fail'; } Log::info('WiwiPay 提现结果:', [$result ?? "no result"]); try { $data = \GuzzleHttp\json_decode($result, true); } catch (\Exception $e) { Util::WriteLog("WiwiPay_error", [$result, $e->getMessage(), $e->getTraceAsString()]); return 'fail'; } if (isset($data['status'])) { return $data; } else { if ($query->State == 5) { // 同步失败,发送邮件给玩家,退还金币 $msg = 'Liquidation failure'; $WithDraw = $query->WithDraw + $query->ServiceFee; $bonus = '30000,' . $WithDraw; PrivateMail::failMail($query->UserID, $OrderId, $WithDraw, $msg, $bonus); $data = [ 'updated_at' => date('Y-m-d H:i:s'), 'State' => 5, ]; DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)->update($data); } return 'fail'; } } public function notify($post) { $OrderId = $post['mchOrderNo'] ?? ''; Util::WriteLog('WiwiPay', 'WiwiPay 提现回调:' . json_encode($post)); // 查询订单号 $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->first(); if (!$query) { return 'fail'; // 订单不存在 } $orderStatus = $post['status'] ?? $post['orderStatus'] ?? ''; if ($orderStatus == 'SUCCESS' || $orderStatus == 'PAID' || $orderStatus == 2) { // 订单成功 $data = [ 'updated_at' => date('Y-m-d H:i:s'), 'State' => 2, ]; DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->update($data); Util::WriteLog('WiwiPay', 'WiwiPay 提现成功:' . $OrderId); return 'SUCCESS'; } else if ($orderStatus == 'REJECTED' || $orderStatus == 'FAILED' || $orderStatus == 3) { // 订单失败,退还金币 $msg = 'Liquidation failure'; $WithDraw = $query->WithDraw + $query->ServiceFee; $bonus = '30000,' . $WithDraw; PrivateMail::failMail($query->UserID, $OrderId, $WithDraw, $msg, $bonus); $data = [ 'updated_at' => date('Y-m-d H:i:s'), 'State' => 5, ]; DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->update($data); Util::WriteLog('WiwiPay', 'WiwiPay 提现失败:' . $OrderId); return 'SUCCESS'; } else { // 处理中 Util::WriteLog('WiwiPay', 'WiwiPay 提现处理中:' . $OrderId . ' status:' . $orderStatus); return 'SUCCESS'; } } }