choices[0]->message->content ) ) { $text = trim(str_replace( "\\n", "\n", $complete->choices[0]->message->content ),"\n"); } elseif( isset( $complete->error->message ) ) { $text = "服务器返回错误信息:".$complete->error->message; } else { $text = "服务器超时或返回异常消息。"; } echo json_encode( [ "message" => $text, "raw_message" => $text, "status" => "success", ] ); $content2 = $_SERVER["REMOTE_ADDR"]." | ".date("Y-m-d H:i:s")."\n"; $content2 .= "Q:".$_POST['message']."\nA:".$text."\n----------------\n"; $myfile = fopen(__DIR__ . "/chat.txt", "a") or die("Writing file failed."); fwrite($myfile, $content2); fclose($myfile); ?>