PHPCURL simulates login Sina Weibo capture page content based on EaglePHP framework development

Source: Internet
Author: User
PHPCURL simulates login Sina Weibo capture page content is developed based on EaglePHP framework. For more information, see. Sina Weibo

The code is as follows:
/**
* CURL request
* @ Param String $ url request address
* @ Param Array $ data request data
*/
Function curlRequest ($ url, $ data = '', $ cookieFile = ''){
$ Ch = curl_init ();
$ Option = array (
CURLOPT_URL => $ url,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
);
If ($ cookieFile ){
$ Option [CURLOPT_COOKIEJAR] = $ cookieFile;
$ Option [CURLOPT_COOKIEFILE] = $ cookieFile;
// $ Option [CURLOPT_COOKIESESSION] = true;
// $ Option [CURLOPT_COOKIE] = 'prov = 42; city = 1 ';
}
If ($ data ){
$ Option [CURLOPT_POST] = 1;
$ Option [CURLOPT_POSTFIELDS] = $ data;
}
Curl_setopt_array ($ ch, $ option );
$ Response = curl_exec ($ ch );
If (curl_errno ($ ch)> 0 ){
Throw_exception ("curl error: $ url". curl_error ($ ch ));
}
Curl_close ($ ch );
Return $ response;
}
Function login ($ username, $ password ){
If ($ username & $ password ){
$ PreLoginData = curlRequest ('http: // login.sina.com.cn/sso/prelogin.php? Entry = weibo & callback = sinaSSOController. preloginCallBack & su = '. base64_encode ($ username ). '& client = ssologin. js (v1.3.16) ', '', self: COOKIE_FILE );
Preg_match ('/sinaSSOController. preloginCallBack \ (. *) \)/', $ preLoginData, $ preArr );
$ JsonArr = json_decode ($ preArr [1], true );
If (is_array ($ jsonArr )){
$ PostArr = array (
'Entry '=> 'Weibo ',
'Gateway' => 1,
'From' => '',
'Savestate' => 7,
'Useticket '=> 1,
'Ssosimplelogin' => 1,
'Su '=> base64_encode (urlencode ($ username )),
'Service' => 'miniblog ',
'Servertime' => $ jsonArr ['servertime'],
'Nonce '=> $ jsonArr ['nonce'],
'Pwencode' => 'wsse ',
'Sp '=> sha1 (sha1 (sha1 ($ password). $ jsonArr ['servertime']. $ jsonArr ['nonce']),
'Encoding' => 'utf-8 ',
'URL' => 'http: // weibo.com/ajaxlogin.php? Framelogin = 1 & callback = parent. sinaSSOController. feedBackUrlCallBack ',
'Returntype' => 'meta'
);
$ LoginData = curlRequest ('http: // login.sina.com.cn/sso/login.php? Client = ssologin. js (v1.3.16) ', $ postArr, self: COOKIE_FILE );
If ($ loginData ){
$ Matchs = array ();
Preg_match ('/replace \(\'(.*?) \ '\)/', $ LoginData, $ matchs );
$ LoginResult = curlRequest ($ matchs [1], '', self: COOKIE_FILE );
$ LoginResultArr = array ();
Preg_match ('/feedBackUrlCallBack \((.*?) \)/', $ LoginResult, $ loginResultArr );
// $ UserInfo = json_decode ($ loginResultArr [1], true );
// Log: info (var_export ($ loginResultArr [1]);
} Else {
Throw_exception ('login sina fail .');
}
} Else {
Throw_exception ($ preLoginData );
}
} Else {
Throw_exception ('param error .');
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.