我已经构建了一个 IPN 侦听器并在沙盒中使用 IPN 模拟器对其进行了测试,它工作正常,但是当我添加“NOTIFYURL”参数并将其设置为我的 IPN 侦听器时,我没有收到来自我的侦听器的任何通知,但付款仍然有效通过。
我还需要做些什么才能使其正常工作吗?
这是我的代码
我的 IPN 侦听器(为了测试它只是将整个结果导入 SQL 表)
include "dbconnect.php";
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$email."')");
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
我的支付处理脚本中与贝宝交互的部分:
// Store request params in an array
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => 'Visa',
'ACCT' => '4887864152287206',
'EXPDATE' => '072018',
'CVV2' => '123',
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => '100.00',
'CURRENCYCODE' => 'USD',
'NOTIFYURL' => 'http://www.mysite.com/ipnlistener.php',
'DESC' => 'Testing Payments Pro'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
echo $result.'<br /><br />';
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$result."')");
为什么我没有收到通知?