Пример #1
0
function request($url, $ua = NULL, $cookie = NULL, $postData = NULL)
{
    $hRequest = curl_init($url);
    if (substr($url, 0, 5) == 'https') {
        curl_setopt($hRequest, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($hRequest, CURLOPT_SSL_VERIFYPEER, false);
    }
    if ($postData !== NULL) {
        curl_setopt($hRequest, CURLOPT_POST, true);
        curl_setopt($hRequest, CURLOPT_POSTFIELDS, $postData);
    }
    if ($ua !== NULL) {
        curl_setopt($hRequest, CURLOPT_USERAGENT, $ua);
    }
    if ($cookie) {
        curl_setopt($hRequest, CURLOPT_COOKIE, $cookie);
    } elseif ($cookie !== '') {
        curl_setopt($hRequest, CURLOPT_COOKIE, get_baidu_base_cookie());
    }
    curl_setopt($hRequest, CURLOPT_HEADER, 1);
    curl_setopt($hRequest, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($hRequest, CURLOPT_MAXREDIRS, 3);
    curl_setopt($hRequest, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($hRequest);
    $ret = array('header' => array());
    $head_size = curl_getinfo($hRequest, CURLINFO_HEADER_SIZE);
    $body = substr($response, $head_size);
    $headerRaw = explode("\r\n", substr($response, 0, $head_size));
    array_shift($headerRaw);
    $ret['body'] = $body;
    foreach ($headerRaw as $line) {
        $exp = explode(': ', $line, 2);
        if (count($exp) == 2) {
            $ret['header'][strtolower($exp[0])] = $exp[1];
        }
    }
    $ret['code'] = curl_getinfo($hRequest, CURLINFO_HTTP_CODE);
    $ret['real_url'] = curl_getinfo($hRequest, CURLINFO_EFFECTIVE_URL);
    $ret['error'] = curl_error($hRequest);
    curl_close($hRequest);
    return $ret;
}
Пример #2
0
 }
 if ($_POST['code'] !== '0' && strlen($_POST['code']) != 4) {
     echo '<h1>错误:提取码位数不对。请输入4个半角字符,或者1个全角字符和1个半角字符的组合。</h1>';
 } else {
     if (substr($_POST['link'], 0, 20) == 'http://pan.baidu.com') {
         $_POST['link'] = substr($_POST['link'], 20);
     } elseif (substr($_POST['link'], 0, 13) == 'pan.baidu.com') {
         $_POST['link'] = substr($_POST['link'], 13);
     } else {
         $_POST['link'] = false;
         echo '<h1>错误:地址输入有误。</h1>';
     }
     if ($_POST['link']) {
         $success = true;
         $share_page = request('http://pan.baidu.com' . $_POST['link'], $ua);
         $cookie = set_cookie(get_baidu_base_cookie(), $share_page['header']['set-cookie']);
         if (strpos($share_page['real_url'], '/share/init?') !== false) {
             $success = false;
             $share_info = substr($share_page['real_url'], strpos($share_page['real_url'], 'shareid'));
             $verify = request('http://pan.baidu.com/share/verify?' . $share_info . '&t=' . time() * 1000 . '&channel=chunlei&clienttype=0&web=1', $ua, $cookie, 'pwd=' . $_POST['code'] . '&vcode=');
             $verify_ret = json_decode($verify['body']);
             if ($verify_ret->errno == 0) {
                 $cookie = set_cookie($cookie, $verify['header']['set-cookie']);
                 $share_page = request('http://pan.baidu.com/share/link?' . $share_info, $ua, $cookie);
                 $success = true;
             } elseif ($verify_ret->errno == -9) {
                 echo '<h1>错误:提取码错误。</h1>';
             } elseif ($verify_ret->errno == -62) {
                 echo '<h1>错误:韩度要求输入验证码。</h1>';
                 $need_vcode = true;
             } else {
Пример #3
0
function baidu_login($username, $password, $codestring = '', $captcha = '')
{
    global $ua;
    $cookie = get_baidu_base_cookie();
    $post = array('isphone' => '0', 'passwd' => base64_encode($password), 'un' => $username, 'vcode' => $captcha, 'vcode_md5' => $codestring, 'from' => 'baidu_appstore', 'stErrorNums' => '0', 'stMethod' => '1', 'stMode' => '1', 'stSize' => mt_rand(50, 2000), 'stTime' => mt_rand(50, 500), 'stTimesNum' => '0', 'timestamp' => time() * 1000, '_client_id' => 'wappc_138' . mt_rand(1000000000, 9999999999) . '_' . mt_rand(100, 999), '_client_type' => '1', '_client_version' => '6.0.1', '_phone_imei' => md5(mt_rand()), 'cuid' => strtoupper(md5(mt_rand())) . '|' . substr(md5(mt_rand()), 1), 'model' => 'M1');
    ksort($post);
    $sign = '';
    foreach ($post as $k => $v) {
        $sign .= $k . '=' . $v;
    }
    $rq = request('http://c.tieba.baidu.com/c/s/login', 'BaiduTieba for Android 6.0.1', null, http_build_query($post) . '&sign=' . strtoupper(md5($sign . 'tiebaclient!!!')));
    $result = json_decode($rq['body']);
    $ret['errno'] = $result->error_code;
    if ($ret['errno'] == 0) {
        $ret['bduss'] = substr($result->user->BDUSS, 0, strpos($result->user->BDUSS, '|'));
        $ret['cookie'] = $cookie . ';BDUSS=' . $ret['bduss'];
    } else {
        if (isset($result->anti->need_vcode)) {
            $ret['code_string'] = $result->anti->vcode_md5;
            $ret['captcha'] = $result->anti->vcode_pic_url;
        }
        $ret['message'] = $result->error_msg;
    }
    return $ret;
}