Php PayPal API不再一直工作
我们的大多数API调用都能成功地工作并存储到数据库中,但有一些不能。我收集了一些日志,我们收到一个“错误400错误请求” -- [29-Sep-2020 08:04:48 UTC]未验证错误101:HTTP/1.1 400错误请求 [29-Sep-2020 08:04:48 UTC]未验证错误101:连接:关闭 [29-Sep-2020 08:04:48 UTC]未验证错误101:内容长度:11 [29-Sep-2020 08:04:48 UTC]未验证错误101:内容类型:文本/普通;字符集=utf-8 [29-Sep-2020 08:04:48 UTC]未验证错误101: [29-Sep-2020 08:04:48 UTC]未验证错误101:请求错误 -- 日志: 代码:Php PayPal API不再一直工作,php,api,paypal,Php,Api,Paypal,我们的大多数API调用都能成功地工作并存储到数据库中,但有一些不能。我收集了一些日志,我们收到一个“错误400错误请求” -- [29-Sep-2020 08:04:48 UTC]未验证错误101:HTTP/1.1 400错误请求 [29-Sep-2020 08:04:48 UTC]未验证错误101:连接:关闭 [29-Sep-2020 08:04:48 UTC]未验证错误101:内容长度:11 [29-Sep-2020 08:04:48 UTC]未验证错误101:内容类型:文本/普通;字符集=
$header.=“POST/cgi-bin/webscr-HTTP/1.1\r\n”;
$header.=“内容类型:application/x-www-form-urlencoded\r\n”;
$header.=“主机:www.paypal.com:443\r\n”;
$header.=“连接关闭\r\n”;
$header.=“内容长度:”。斯特伦($req)。“\r\n\r\n”;
$fp=fsockopen($fp)ssl://www.paypal.com“,443,$errno,$errstr,30);
//$fp=fsockopen('ipnpb.paypal.com',443,$errno,$errstr,30);
如果(!$fp)
{
//HTTP错误
回声“错误”;
错误日志(“第53行失败”);
}否则{
//没有HTTP错误
FPUT($fp,$header.$req);
而(!feof($fp))
{
$res=fgets($fp,1024);
如果(strcmp(微调($res),“已验证”)==0){
//设置所需变量
$txn_id=$_POST['txn_id'];
$first\u name=$\u POST['first\u name'];
$last_name=$_POST['last_name'];
$cust_name=$first_name.'.$last_name;
$cust_email=$_POST['payer_email'];
$cust_id=$_POST['auction_buyer_id'];
$cust_status=$_POST['payer_status'];
$payment\u date=$\u POST['payment\u date'];
$currency=$_POST['mc_currency'];
$address_street=$_POST['address_street'];
$address\u city=$\u POST['address\u city'];
$address\u state=$\u POST['address\u state'];
$address\u zip=$\u POST['address\u zip'];
$address\u country=$\u POST['address\u country'];
$address\u status=$\u POST['address\u status'];
$g_ref=“”;
如果(isset($\u POST['fulfillment\u order\u reference\u number'])){
$g_ref=$_POST['fulfillment_order_ref_ref_number'];
$address_street=$_POST['fulfillment_address_line1'];
$address\u city=$\u POST['fulfillment\u address\u city'];
$address\u state=$\u POST['fulfillment\u address\u state'];
$address\u zip=$\u POST['fulfillment\u address\u zip'];
}
$item\u count=$\u POST['num\u cart\u items';
//验证所需的其他变量
$payment\u status=$\u POST['payment\u status'];
$receiver\u email=$\u POST['receiver\u email'];
$our#email='######PP email HERE
$our_email_2='######PP email HERE
如果($payment_status=='Completed')&($receiver_email==$our_email)| |($receiver_email==$our_email|2)))
{
//检查尚未处理的事务
//$check=$db\u query->duplicate\u check($txn\u id);
//如果($check!=0){exit();}
//区分账户
如果($receiver\u email==$our\u email){
$pp_acc=“CB”;
}否则如果($receiver\u email==$our\u email\u 2){
$pp_acc=“IK”;
}
对于中提到的($n=1;$n),请确保在请求头中包含一个用户代理:
字段,其值为大于7个字符左右的任何字符串
您还应该使用HTTPS/SSL连接(标准端口443)连接到ipnpb.paypal.com
,不知道为什么您的代码使用较旧的www.paypal.com
端点作为IPN。好,那么我该如何更改?$header.=“主机:www.paypal.com:443\r\n”$fp=fsockopen('ssl://www.paypal.com’,443,$errno,$errstr,30);显然,您需要在两个位置更改www,并分别添加新的用户代理标头
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "HOST: www.paypal.com:443\r\n";
$header .= "Connection close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
//$fp = fsockopen ('ipnpb.paypal.com', 443, $errno, $errstr, 30);
if (!$fp)
{
// HTTP ERROR
echo "error";
error_log("FAILED line 53");
} else {
// NO HTTP ERROR
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets($fp, 1024);
if (strcmp (trim($res), "VERIFIED") == 0) {
//Setup Required Variables
$txn_id = $_POST['txn_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$cust_name = $first_name .' '. $last_name;
$cust_email = $_POST['payer_email'];
$cust_id = $_POST['auction_buyer_id'];
$cust_status = $_POST['payer_status'];
$payment_date = $_POST['payment_date'];
$currency = $_POST['mc_currency'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$g_ref = "";
if (isset($_POST['fulfillment_order_reference_number'])) {
$g_ref = $_POST['fulfillment_order_reference_number'];
$address_street = $_POST['fulfillment_address_line1'];
$address_city = $_POST['fulfillment_address_city'];
$address_state= $_POST['fulfillment_address_state'];
$address_zip = $_POST['fulfillment_address_zip'];
}
$item_count = $_POST['num_cart_items'];
//Misc Variables Requried for Authentication
$payment_status = $_POST['payment_status'];
$receiver_email = $_POST['receiver_email'];
$our_email = '###'; #PP EMAIL HERE
$our_email_2 = '###'; #PP EMAIL HERE
if (($payment_status == 'Completed') && (($receiver_email == $our_email) || ($receiver_email == $our_email_2)))
{
//Check Transaction Not Already Processed
// $check = $db_query->duplicate_check($txn_id);
// if ($check != 0) { exit(); }
//Distinguish between accounts
if ($receiver_email == $our_email) {
$pp_acc = "CB";
} else if ($receiver_email == $our_email_2) {
$pp_acc = "IK";
}
for ($n=1;$n<=$item_count;$n++) {
$item_name = $_POST['item_name'. $n];
$item_quantity = $_POST['quantity'. $n];
$item_number = $_POST['item_number'. $n];
$total_paid = $_POST['mc_gross_'. $n];
error_log("HIT ADD ORDER tx: $txn_id");
//Add Order to DB (Removed)
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
error_log("Invalid Error 102");
}
else {
// This is where it seems to be hitting
error_log("not verified Error 101: " . $res);
}
}
}
fclose ($fp);