登录阿里巴巴cURL

时间:2015-02-20 16:10:02

标签: curl login

我想弄清楚如何使用PHP和CURL登录网站https://login.alibaba.com。我使用下面的代码,但它似乎没有工作。您如何建议我自动登录此网站?

我的当前代码:

<?
$cookie = "cookie.txt";
// set global curl options
$curloptions = array(
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
        CURLOPT_TIMEOUT => 60,
        CURLOPT_COOKIEJAR => $cookie,
        CURLOPT_COOKIEFILE => $cookie,
        CURLOPT_REFERER => 'http://www.alibaba.com'
);

// set userinfo
$username = 'xxxxxx';
$password = 'xxxxxx';

// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);

// make a dummy request to generate a session
$response = curl_http_request('https://passport.alibaba.com/mini_login.htm?lang=pt_br&appName=aebuyer&appEntrance=default&cssLink=&styleType=auto&bizParams=&notLoadSsoView=false&notKeepLogin=true&rnd=0.6961233267322033', $curloptions);
preg_match('/name="ua".+?value="([^"]+)"/mis', $response, $matches);
$ua = $matches[1];

// login
curl_http_request('https://passport.alibaba.com/newlogin/login.do?fromSite=4', 
    array(
        CURLOPT_POSTFIELDS => http_build_query(array(
            'ua' => $ua,
            'appName' => $appName,
            'appEntrance' => $appEntrance,
            '_csrf_token' => $_csrf_token,
            'rdsToken' => $rdsToken,
            'cid' => $cid,
            'umidToken' => $umidToken,
            'lang' => $lang,
            'hsid' => $hsid,
            'isRDSReady' => $isRDSReady,
            'isUMIDReady' => $isUMIDReady,
            'umidGetStatusVal' => $umidGetStatusVal,
            'isRequiresHasTimeout' => $isRequiresHasTimeout,
            'loginHost' => $loginHost,
            'scene' => $scene,
            'isMobile' => $isMobile,

            // all input
        )),
        CURLOPT_POST => FALSE
    ), $curloptions
);

//example request

function curl_http_request ($url, $moreoptions = array(), $options = array())
{
    foreach ($moreoptions as $k => $v) $options[$k] = $v;
  $handle = curl_init($url);
  curl_setopt_array($handle, $options);
  ob_start();
  $buffer = curl_exec($handle);
  ob_end_clean();
  curl_close($handle);
  return $buffer;
}
?>

感谢!!!

0 个答案:

没有答案