cookie('id', 'blank'); $key=$request->cookie('key', 'blank'); $path=$request->uri(); if($path==''||$path=='/'){ $path='/?signAll=1&ts=1657'; } $url='http://'.getenv('Zlibrary').$path; $auth=array('remix_userid'=>"$id",'remix_userkey'=>"$key",'siteLanguageV2'=>'zh','selectedSiteMode'=>'books'); $return = Http::withProxy('socks5h://'.getenv('proxy'))->withCookies($auth,getenv('Zlibrary'))->withCookies($auth,getenv('ZlibraryLogin'))->get($url); $response->withHeaders($return->headers()); /** * if($return->header('Content-Type')[0]=='image/svg+xml'){ *} */ $response->withBody($return->body()); return $response; } public function login(Request $request) { return view('login'); } public function check(Request $request) { $username=$request->post('name','blank'); $password=$request->post('password','blank'); $code=$request->post('code','blank'); if($username=='blank' || $password=='blank' || $code=='blank'){ return json(['code'=>500, 'msg'=>'缺少参数']); } try { $V=v::Email()->setName('用户名')->check($username); } catch (ValidationException $exception) { return json(['code'=>500, 'msg'=>$exception->getMessage()]); } try { $V=v::stringType()->setName('密码')->noWhitespace()->check($password); } catch (ValidationException $exception) { return json(['code'=>500, 'msg'=>$exception->getMessage()]); } try { $V=v::stringType()->length(5, 5)->setName('验证码')->noWhitespace()->check($code); } catch (ValidationException $exception) { return json(['code'=>500, 'msg'=>$exception->getMessage()]); } if (strtolower($code) !== $request->session()->get('captcha')) { return json(['code' => 400, 'msg' => '输入的验证码不正确']); } $url='http://'.getenv('ZlibraryLogin').'/rpc.php'; $response = Http::withProxy('socks5h://'.getenv('proxy'))->post("$url", ['isModal' => true,'email'=>"$username",'password'=>"$password",'site_mode'=>'books','action'=>'login','redirectUrl'=>'','isSinglelogin'=>'1','isTorVersion'=>'1','gg_json_mode'=>'1']); if(!$response->successful()){ return json(['code' => 501, 'msg' => '登陆失败,服务端错误']); } $return=$response->body(); $return=json_decode($return); if(isset($return->response->validationError)){ return json(['code' => 502, 'msg' => 'Zlib登陆失败:'.$return->response->message]); } $url=parse_url($return->response->params)['query']; $queryParts = explode('&', $url); $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); $params[$item[0]] = $item[1]; } return json(['code'=>200,'msg'=>'登陆成功','userid'=>$params['remix_userid']])->cookie('id', $params['remix_userid'],43200,'/')->cookie('key', $params['remix_userkey'],43200,'/'); } public function code(Request $request) { // 初始化验证码类 $builder = new CaptchaBuilder; // 生成验证码 $builder->build(); // 将验证码的值存储到session中 $request->session()->set('captcha', strtolower($builder->getPhrase())); // 获得验证码图片二进制数据 $img_content = $builder->get(); // 输出验证码二进制数据 return response($img_content, 200, ['Content-Type' => 'image/jpeg']); } public function json(Request $request) { return json(['code' => 0, 'msg' => 'ok']); } }