'19884551721', 'password' => 'LX5bH76SJf9E' ]; // 初始化cURL $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应内容而不直接输出 curl_setopt($ch, CURLOPT_POST, true); // 使用POST方法 curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' // 设置JSON头 ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); // JSON编码数据 // 执行请求 $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); // 处理响应 if ($httpCode === 200) { $data = json_decode($response); if (isset($data->jwt)) { $jwt = $data->jwt; $file = 'jwt.txt'; // 将数据写入文件 file_put_contents($file, $jwt); } else { echo "响应中缺少JWT令牌"; } } else { echo "认证失败,错误信息:" . ($response ?: '无响应内容'); } // 错误处理 if ($error) { echo "cURL错误:" . $error; }