1

几个月前,一位自由程序员为我编写了一些自定义 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;
////
4

1 回答 1

2

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

于 2013-06-04T18:43:30.733 回答