PHP模拟网易云音乐登录并实现PC与手机签到

/ 0评 / 0

PHP模拟网易云音乐登录并实现PC与手机签到。

<?php /** * Created by PhpStorm. * User: Gsan * */
$username = "手机账号"; $pwd = "密码"; 
$pwd = md5($pwd); 
$url='http://music.163.com/weapi/login/cellphone?csrf_token='; 
$datas=array(
    'phone'=>$username,
    'rememberLogin'=>true,
    'password'=>$pwd
);
$data = prepare($datas);
$result = curl($url,$data);
$result = str_replace("\r\n","",$result);
preg_match('/\/Set-Cookie:(.*?);/',$result,$cookie); //模拟登录取得Cookie
$cookies = implode(" ",$cookie);
$url = "http://music.163.com/weapi/point/dailyTask";
$datas=array(
    'type'=>"0"
);
$data = prepare($datas);
$result = curl($url,$data,$cookies);
echo $result;
$datas=array(
    'type'=>"1"
);
$data = prepare($datas);
$result = curl($url,$data,$cookies);
echo $result;
function prepare($datas){
    $data['params']=aes_encode(json_encode($datas),'0CoJUm6Qyw8W8jud');
    $data['params']=aes_encode($data['params'],'TA3YiYCfY2dDJQgg');
    $data['encSecKey']='84ca47bca10bad09a6b04c5c927ef077d9b9f1e37098aa3eac6ea70eb59df0aa28b691b7e75e4f1f9831754919ea784c8f74fbfadf2898b0be17849fd656060162857830e241aba44991601f137624094c114ea8d17bce815b0cd4e5b8e2fbaba978c6d1d14dc3d1faf852bdd28818031ccdaaa13a6018e1024e2aae98844210';
    return $data;
}
function aes_encode($secretData,$secret){
    return openssl_encrypt($secretData,'aes-128-cbc',$secret,false,'0102030405060708');
}
function curl($url,$data,$cookie='os=pc; osver=Microsoft-Windows-10-Professional-build-10586-64bit; appver=2.0.3.131777; channel=netease; __remember_me=true'){
    $curl=curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    $data=http_build_query($data);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
    curl_setopt($curl,CURLOPT_POST,1);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl,CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($curl,CURLOPT_REFERER,'http://music.163.com/');
    curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.157 Safari/537.36');
    curl_setopt($curl,CURLOPT_COOKIE,$cookie);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    $result=curl_exec($curl);
    curl_close($curl);
    return $result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *