一位自由撰稿人几个月前为我写了一些自定义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;
////
答案 0 :(得分: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";
with:
//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