function check_share($id, $link, $name, $cookie) { global $ua, $mysql; if (!$link || $link == '/s/fakelink') { $url = ''; $ret['conn_valid'] = true; $ret['user_valid'] = true; $ret['valid'] = false; } else { $url = 'http://pan.baidu.com' . $link; $check = request($url, $ua, $cookie); if (strpos($check['body'], '你所访问的页面不存在了。')) { $ret['conn_valid'] = false; } else { if (strpos($check['body'], '涉及侵权、色情、反动、低俗') === false && strpos($check['body'], '分享的文件已经被') === false && $link) { $ret['conn_valid'] = true; $ret['user_valid'] = true; $ret['valid'] = true; $context = json_decode(findBetween($check['body'], 'var _context = ', ';'), true); $current_path = $context['file_list']['list'][0]['path']; if ($current_path != $name && $context) { //自动修复错误的路径 $mysql->prepare('update watchlist set name=? where id=?')->execute(array($current_path, $id)); $name = $current_path; } } elseif (strpos($check['body'], '加密分享了文件') !== false) { $ret['conn_valid'] = true; $ret['user_valid'] = false; } else { $ret['conn_valid'] = true; $ret['user_valid'] = true; $ret['valid'] = false; } } } $ret['url'] = $url; return $ret; }
function getBaiduToken($cookie, $username) { global $ua; $token = request('http://pan.baidu.com/disk/home', $ua, $cookie); $bdstoken = findBetween($token['body'], 'TOKEN = "', '";'); if (strlen($bdstoken) < 10) { alert_error('cookie失效,或者百度封了IP!', 'switch_user.php?name=' . $username); } return $bdstoken; }
if ($verify_ret->errno == 0) { $share_page = request('http://pan.baidu.com/share/link?' . $share_info); $success = true; } elseif ($verify_ret->errno == -9) { echo '<h1>错误:提取码错误。</h1>'; } elseif ($verify_ret->errno == -62) { echo '<h1>错误:韩度要求输入验证码。</h1>'; $need_vcode = true; } else { echo '<h1>未知错误:' . $verify_ret->errno . '</h1>'; } } else { $_POST['code'] = 0; } if ($success) { $fileinfo = json_decode(findBetween($share_page['body'], 'var _context = ', ';'), true); if ($fileinfo == NULL) { echo '<h1>错误:找不到文件信息,可能韩度修改了页面结构,请联系作者!</h1>'; } else { foreach ($fileinfo['file_list']['list'] as &$v) { $v['fs_id'] = number_format($v['fs_id'], 0, '', ''); } $check_user = $mysql->query("select * from users where username='******'linkusername']}'")->fetch(); if (empty($check_user)) { echo '<h1>错误:用户【' . $fileinfo['linkusername'] . '】未添加进数据库!</h1>'; } elseif (count($fileinfo['file_list']['list']) > 1) { echo '<h1>错误:该分享有多个文件。当前暂未支持多文件补档……</h1>'; } else { if ($check_user['newmd5'] == '') { echo '<font color="red"><b>因为没有设置MD5,无法启用换MD5补档模式。</b>请在“浏览文件”模式添加一个小文件(几字节即可),并在添加时输入提取码为“md5”。</font><br />'; }
function login($username, $password, $codestring = '', $captcha = '') { global $bdstoken; request('http://pan.baidu.com/'); if ($codestring == '') { $captcha = loginCheck($username); if ($captcha) { $ret['errno'] = 257; $ret['code_string'] = $captcha; $ret['captcha'] = 'https://passport.baidu.com/cgi-bin/genimage?' . $captcha; return $ret; } } $guid = GUID(); getToken($guid); //加密登录不太灵,不知道怎么回事,抽风似的,不用了 /*$_key = request('https://passport.baidu.com/v2/getpublickey?token='.$bdstoken); $key = json_decode(str_replace("'", '"', $_key['body']), true); if (!isset($key['pubkey']) || !isset($key['key'])) { echo '无法获取public key!请联系开发者!服务器返回:'.$_key['body']; die(); } $pubkey = openssl_pkey_get_public($key['pubkey']); openssl_public_encrypt($password, $crypted_password, $pubkey); $crypted_password = base64_encode($crypted_password); $result = request('https://passport.baidu.com/v2/api/?login', "charset=utf-8&tpl=netdisk&subpro=netdisk_web&apiver=v3&tt=".time()."&token=$bdstoken&loginmerge=true&safeflg=0&codestring=$codestring&detect=1&foreignusername=&gid=&idc=&isPhone=&loglogintype=pc_loginBasic&logintype=basicLogin&mem_pass=on&password=$crypted_password&rsakey={$key['key']}&crypttype=12&quick_user=0&safeflag=0&staticpage=http://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html&u=http://pan.baidu.com/&username=$username&countrycode=&verifycode=$captcha&gid=$guid&ppui_logintime=".mt_rand(10000, 15000));*/ $result = request('https://passport.baidu.com/v2/api/?login', "charset=utf-8&tpl=netdisk&subpro=netdisk_web&apiver=v3&tt=" . time() . "&token={$bdstoken}&loginmerge=true&safeflg=0&codestring={$codestring}&detect=1&foreignusername=&gid=&idc=&isPhone=&loglogintype=pc_loginBasic&logintype=basicLogin&mem_pass=on&password={$password}&quick_user=0&safeflag=0&staticpage=http://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html&u=http://pan.baidu.com/&username={$username}&countrycode=&verifycode={$captcha}&gid={$guid}&ppui_logintime=" . mt_rand(10000, 15000)); parse_str(findBetween($result['body'], 'href += "', '"'), $output); if (!isset($output['err_no'])) { echo '无法登录!请联系开发者!服务器返回:<xmp>' . $result['body']; die; } $ret['errno'] = $output['err_no']; if (strlen($output['codeString'])) { $ret['code_string'] = $output['codeString']; $ret['captcha'] = 'https://passport.baidu.com/cgi-bin/genimage?' . $output['codeString']; } return $ret; }