Created
July 23, 2018 09:33
-
-
Save 4iTeam/a2e1c12841914e0dfbae8a251a24e504 to your computer and use it in GitHub Desktop.
Get Linksvip Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Api\Services\LinksVipService; | |
use Illuminate\Http\Request; | |
class LinksVipController extends Controller | |
{ | |
protected $linksvip; | |
function __construct(LinksVipService $service) | |
{ | |
$this->linksvip=$service; | |
$this->linksvip->maybeLogin(); | |
} | |
function index(){ | |
return $this->linksvip->checkLogin(); | |
} | |
function getLink(Request $request){ | |
return $this->linksvip->getLink($request->input('link')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Api\Services; | |
use GuzzleHttp\Client; | |
use GuzzleHttp\Cookie\FileCookieJar; | |
use GuzzleHttp\Exception\TransferException; | |
use Illuminate\Support\Facades\Cache; | |
use Illuminate\Support\Facades\Storage; | |
use Illuminate\Support\Str; | |
class LinksVipService{ | |
protected $user=''; | |
protected $pass=''; | |
protected $loginEndpoint=''; | |
protected $getLinkEndpoint='https://linksvip.net/GetLinkFs'; | |
function __construct() | |
{ | |
} | |
function getClient(){ | |
if(!Storage::exists('cookies/linksvip.json')){ | |
Storage::put('cookies/linksvip.json',''); | |
} | |
$file=Storage::path('cookies/linksvip.json'); | |
$cookie=new FileCookieJar($file,true); | |
$client=new Client([ | |
'cookies'=>$cookie, | |
'headers'=>[ | |
'User-Agent'=>'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36', | |
], | |
]); | |
return $client; | |
} | |
function getLink($link,$pass='undefined'){ | |
$data=[ | |
'link'=>$link, | |
'pass'=>$pass, | |
'hash'=>Str::random(32), | |
'captcha'=>'', | |
]; | |
$response=$this->getClient()->post($this->getLinkEndpoint,[ | |
'form_params'=>$data, | |
'headers'=>[ | |
'X-Requested-With'=>'XMLHttpRequest', | |
'Origin'=>'https://linksvip.net', | |
'Referer'=>'https://linksvip.net/get-link.html', | |
], | |
//'debug'=>'true', | |
]); | |
return json_decode($response->getBody(),true); | |
} | |
function hash($length){ | |
$code='LinksVIP.Net2014eCrVtByNgMfSvDhFjGiHoJpKlLiEuRyTtYtUbInOj9u4y81r5o26q4a0v'; | |
$max=strlen($code); | |
$str='';$i=0; | |
while($i<$length){ | |
$i++; | |
$str.=$code[random_int(0,$max)]; | |
} | |
return $str; | |
} | |
function maybeLogin(){ | |
if(!$this->checkLogin()){ | |
$client=$this->getClient(); | |
$client->post('https://linksvip.net/login/',[ | |
'form_params'=>[ | |
'u'=>$this->user, | |
'p'=>$this->pass, | |
'auto_login'=>'checked', | |
], | |
]); | |
Cache::delete('linksvip_is_logged_in'); | |
} | |
} | |
function checkLogin(){ | |
return Cache::remember('linksvip_is_logged_in',60*48,function(){ | |
$client=$this->getClient(); | |
$response=[]; | |
try { | |
$res = $client->get('https://linksvip.net/login/logined.php'); | |
$body = $res->getBody(); | |
if(strpos($body,$this->user)){ | |
$response['logged_in']=true; | |
} | |
}catch (TransferException $exception){ | |
} | |
return $response; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job!