Php Codeigniter paypal_lib IPN不工作
我试图捕捉用户在paypal(沙盒)中付款的时间。IPN是这个问题的答案,但我似乎没有得到任何回应。我试着把它放在日志里,甚至数据库里,但是没有数据输入。我知道IPN是一个倾听者,但我不知道为什么不工作。。对此有何澄清和想法 我正在使用codeigniter 以下是我的脚本: 首先我声明了字段Php Codeigniter paypal_lib IPN不工作,php,codeigniter,paypal-sandbox,Php,Codeigniter,Paypal Sandbox,我试图捕捉用户在paypal(沙盒)中付款的时间。IPN是这个问题的答案,但我似乎没有得到任何回应。我试着把它放在日志里,甚至数据库里,但是没有数据输入。我知道IPN是一个倾听者,但我不知道为什么不工作。。对此有何澄清和想法 我正在使用codeigniter 以下是我的脚本: 首先我声明了字段 $this->paypal_lib->add_field('cmd','_cart'); $this->paypal_lib->add_field('upload','1'); $
$this->paypal_lib->add_field('cmd','_cart');
$this->paypal_lib->add_field('upload','1');
$this->paypal_lib->add_field('business', $business_email);
$this->paypal_lib->add_field('return', site_url('invoice/payment_success/'.$invoice_id.'/'.$album_id));
$this->paypal_lib->add_field('cancel_return', site_url('invoice/payment_cancel/'.$invoice_id));
$this->paypal_lib->add_field('notify_url', site_url('invoice/payment_validate/'.$invoice_id)); // <-- IPN url
$this->paypal_lib->add_field('custom', $invoice_id); // <-- Verify return
这是图书馆里的ipn
函数validate_ipn()
{
}我知道这是一个愚蠢的问题,但你是在本地主机上开发的吗?当您在本地主机上测试PayPal IPN时,它可能无法访问您的服务器。考虑PageKite、LoopCaleToT等工具,让你的本地计算机上网,让贝宝可以访问它。
另一种方法是登录商户沙箱帐户并查看IPN历史记录,以查看到底是什么错误。回答我自己的问题: 无法接收paypal IPN,因为连接到paypal时出现问题,要解决此问题,您只需将端口更改为:
$fp = fsockopen($url_parsed['host'],'80',$err_num,$err_str,30);
到
现在接收连接已建立并接收paypal IPN通知
在后面的部分中,我体验到在沙箱中测试IPN失败了,我发现沙箱中的IPN不起作用。你可以参考我已经考虑过这个事实,但我认为它应该是有效的,因为我可以点击贝宝(沙盒),点击付费按钮。在paypal沙盒中我可以在哪里找到IPN历史记录?是的,你是对的。我在这里找到的谢谢你的提示。
// get instance
$CI =& get_instance();
// parse the paypal URL
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
#if(count($_POST))
if($_POST)
{
#foreach (array_keys($_POST) as $field)
foreach ($_POST as $field => $value)
{
#$value = $CI->input->post($field, true);
$this->ipn_data[$field] = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
}
$post_string.='cmd=_notify-validate'; // append ipn command
// open the connection to paypal
$fp = fsockopen($url_parsed['host'],'80',$err_num,$err_str,30);
if(!$fp)
{
// could not open the connection. If loggin is on, the error message
// will be in the log.
$this->last_error = 'fsockopen error no. '.$err_num.': '.$err_str;
$this->log_ipn_results(false);
return false;
}
else
{
// Post the data back to paypal
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while(!feof($fp))
$this->ipn_response .= fgets($fp, 1024);
fclose($fp); // close connection
}
if (eregi('VERIFIED',$this->ipn_response))
{
// Valid IPN transaction.
if ($this->ipn_log_method == 'db')
{
return $this->log_ipn_results(true);
}
/*// Valid IPN transaction.
$this->log_ipn_results(true);*/
return true;
}
else
{
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
$fp = fsockopen($url_parsed['host'],'80',$err_num,$err_str,30);
$fp = fsockopen($url_parsed['host'],'443',$err_num,$err_str,30);