我有一个 php 脚本,我已经使用了 2 年,并在 paypal 更改为 http 1.1 时对其进行了修改。它几乎适用于每笔交易,但最近失败了,我不知道为什么。下面是代码。
尝试查看响应时失败。这是无效的
它可能与地址中的非标准字符有关吗?
我曾尝试一次又一次地发送 ipn 请求,但总是失败
function paypal_ipn() {
$req = 'cmd=_notify-validate';
foreach($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&{$key}={$value}";
}
$res = '';
$ch = curl_init(paypal_url());
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$res = curl_exec($ch);
curl_close($ch);
if(PAYPAL_IPN_DEBUG && !empty($_POST)) {
$fname = 'ipn_intial_' . date('Y.m.d-h.i.s', time()) . '.txt';
file_put_contents('log/' . $fname, $req);
$fname = 'ipn_intial_result_' . date('Y.m.d-h.i.s', time()) . '.txt';
file_put_contents('log/' . $fname, $res);
}
if(strcmp($res, "VERIFIED") == 0) {
switch($_POST['txn_type'])
{
case 'web_accept':
$data = array();
$data['name'] = $_POST['first_name'] . ' ' . $_POST['last_name'];
$data['email'] = $_POST['payer_email'];
$data['txn_id'] = $_POST['txn_id'];
$data['payment_status'] = 'Completed';
$res = save_payment($data);
if ($res) {
$data = payment_details(array('txn_id' => $data['txn_id']));
mail_notification($data);
}
break;
case 'subscr_signup':
$params = array();
$params['name'] = $_POST['first_name'] . ' ' . $_POST['last_name'];
$params['email'] = $_POST['payer_email'];
$params['subscr_id'] = $_POST['subscr_id'];
$params['subscr_status'] = 'payment';
$data = save_subscription($params);
subscr_notification($data);
break;
case 'subscr_cancel':
$data = subscr_details(array('subscr_id' => $_POST['subscr_id']));
if ($data)
{
mysql_update('subscriptions', array('subscr_id' => $_POST['subscr_id']), array('subscr_status' => 'cancelled', 'cancel_date' => date('Y-m-d H:i:s')));
}
break;
}
}
if(PAYPAL_IPN_DEBUG && !empty($_POST)) {
$fname = 'ipn_' . date('Y.m.d-h.i.s', time()) . '.txt';
file_put_contents('log/' . $fname, serialize($_POST));
}
}