贝宝cURL登录不再作为一个月前的功能


PayPal cURL login no longer functioning as of a month ago

几个月前,一个自由编码员为我编写了一些自定义PHP cURL,用于登录我的企业PayPal帐户并通过加拿大邮政打印运输标签。

大约一个月前,登录过程开始失败。参见下面的代码。它每次都不能通过完整性检查。今天这个代码还能用,第二天就不行了。编码员找不到问题的根源。有人能看出这段代码有什么问题吗?

////
// 1. INITIALIZE
cp_progress(1, 'Initializing');
if (file_exists(PAYPAL_COOKIE_FILE)) {
unlink(PAYPAL_COOKIE_FILE); // delete old cookie file
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_REFERER, '');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  //Windows 2003 Compatibility 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, PAYPAL_COOKIE_FILE);
curl_setopt($ch, CURLOPT_COOKIEJAR, PAYPAL_COOKIE_FILE);
////
// 2. LOG IN
cp_progress(2, 'Logging in');
$response = cp_get_page($ch, 'https://www.paypal.com/ca/cgi-bin/webscr?cmd=_ship-now');
// echo '<br /><br /><br /><br /> Response = ',$response,'<br /><br /><br /><br />'; // exit;
cp_sanity_check($response, '<title>Login - PayPal</title>');
$matches = '';
// preg_match("/<form method='"post'" name='"login_form'" target='"paypal'" action='"([^'"]*)'"/siU", $response, $matches);
preg_match("/<form method='"post'" name='"login_form'" action='"([^'"]*)'"/siU", $response, $matches);
$form_action = $matches[1];
$matches = '';
preg_match("/<input type='"hidden'" id='"CONTEXT_CGI_VAR'" name='"CONTEXT'" value='"([^'"]*)'"/siU", $response, $matches);
$form_context = $matches[1];
// echo "form_action = $form_action<br>";
// echo "form_context = $form_context<br>";
/*$query_string = "CONTEXT=$form_context&login_email=" . PAYPAL_EMAIL . "&login_password=" . PAYPAL_PASSWORD
. "&login_cmd=&login_params=&submit.x=Log%20In&operating_system=Linux&form_charset=UTF-8&browser_name=Firefox&browser_version=3";*/  
$query_string = "CONTEXT=$form_context&login_email=" . PAYPAL_EMAIL . "&login_password=" . PAYPAL_PASSWORD
. "&login_cmd=&login_params=&submit.x=Log%20In&operating_system=Windows%2NT&form_charset=UTF-8&browser_name=Firefox&browser_version=19";
// echo '$form_action = ',$form_action;
// echo '$query_string = ',$query_string; exit;
$response = cp_post_page($ch, $form_action, $query_string);
// echo '<br /><br /><br /><br /> Response = ',$response,'<br /><br /><br /><br />'; // exit;
cp_sanity_check($response, '<title>Canada Post - Create Your Shipping Label - PayPal</title>');
$matches = '';
preg_match("/<form method='"post'" name='"shippingForm'" action='"([^'"]*)'"/siU", $response, $matches);
$form_action = $matches[1];
$matches = '';
preg_match("/<input type='"hidden'" id='"CONTEXT_CGI_VAR'" name='"CONTEXT'" value='"([^'"]*)'"/siU", $response, $matches);
$form_context = $matches[1];
$matches = '';
preg_match("/<input name='"auth'" type='"hidden'" value='"([^'"]*)'"/siU", $response, $matches);
$form_auth = $matches[1];
// echo $form_auth; exit;
////

Paypal已更新此登录页面中的字段。替换代码:

$matches = '';
preg_match("/<input type='"hidden'" id='"CONTEXT_CGI_VAR'" name='"CONTEXT'" value='"([^'"]*)'"/siU", $response, $matches);
$form_context = $matches[1];
// echo "form_action = $form_action<br>";
// echo "form_context = $form_context<br>";
/*$query_string = "CONTEXT=$form_context&login_email=" . PAYPAL_EMAIL . "&login_password=" . PAYPAL_PASSWORD
. "&login_cmd=&login_params=&submit.x=Log%20In&operating_system=Linux&form_charset=UTF-8&browser_name=Firefox&browser_version=3";*/  
$query_string = "CONTEXT=$form_context&login_email=" . PAYPAL_EMAIL . "&login_password=" . PAYPAL_PASSWORD
. "&login_cmd=&login_params=&submit.x=Log%20In&operating_system=Windows%2NT&form_charset=UTF-8&browser_name=Firefox&browser_version=19";

:

//changed
$matches = '';
preg_match("/<input type='"hidden'" id='"CONTEXT_CGI_VAR'" name='"CONTEXT'" value='"([^'"]*)'"/siU", $response, $matches);
$form_context = html_entity_decode($matches[1]);

$matches = '';
preg_match("/<input name='"auth'" type='"hidden'" value='"([^'"]*)'"/siU", $respone, $matches);
$form_auth = urlencode($matches[1]);
//echo "form_action = $form_action<br>";
//echo "form_context = $form_context<br>";
$query_string = "CONTEXT=$form_context&login_email=" . PAYPAL_EMAIL . "&login_password=" . PAYPAL_PASSWORD
            . "&login_cmd=&login_params=&submit.x=Log%20In&operating_system=Linux&form_charset=UTF-8&browser_name=Firefox&browser_version=3&auth=$form_auth";
//end changed

您正在添加新的preg_match行和$form_auth