我试图将PagSeguro(支付网关 - 巴西版本的PayPal)并入我的网站。客户完成PagSeguro后,他们将数据(通过POST)发送到我指定的功能。但是,我没有收到POST。在完成所有我能想到的故障排除之后,我联系了PagSeguro。他们说他们的日志表明POST正在正常发送,但他们正在接收HTTP 302响应。无法模拟HTTP 302响应
为了弄清楚为什么发生这种情况,我创建了隐藏值的形式来模拟发送POST到我的功能。我把这个表格放在不同的域名下,以防与它有关。每次我从模拟表单发送POST时,都会收到一个HTTP 200响应,而我的日志表明POST已收到。
PagSeguro如何接收与我的模拟不同的响应?它可能与服务器有关或与我的脚本有关吗?
下面是函数(使用笨)其他应当接受POST:
function pagseguro_retorno(){
if (count($_POST) == 0) {
return FALSE;
}
$msg = 'POST RECEIVED';
$simulate = $this->input->post('Simulate');
if (! empty($simulate)){
$result = 'VERIFICADO';
$msg .= ' FROM SIMULATOR';
} else {
$this->load->library(PagSeguroNpi);
$result = $this->PagSeguroNpi->notificationPost();
}
$this->log($msg);
if ($result == "VERIFICADO") {
$id = $this->input->post('Referencia');//cart id
$this->load->model('transacao_model');
$trans_row = $this->transacao_model->get_transaction($id);
if (! is_object($trans_row)){
//LOAD NEW TRANSACTION
if (! $this->new_transaction($id)){
$notice = "Unable to load new transaction</p><p>";
$this->log($notice);
$notice .= '<pre>'.print_r($_POST, TRUE).'</pre>';
$this->email_notice($notice);
}
}
$this->load->model('carrinho_model');
if($_POST['StatusTransacao'] == 'Aprovado'){
$status = 'apr';
}elseif($_POST['StatusTransacao'] == 'Em Análise'){
$status = 'anl';
}elseif($_POST['StatusTransacao'] == 'Aguardando Pagto'){
$status = 'wtg';
}elseif($_POST['StatusTransacao'] == 'Completo'){
$status = 'cmp';
//nothing more happens here - client must click on 'mark as shipped' before cart is removed and history data is loaded
}elseif($_POST['StatusTransacao'] == 'Cancelado'){
//reshelf - don't set $status, because the cart's about to be destroyed
$this->carrinho_model->reshelf(array($id));
}
if (isset($status)){
$this->carrinho_model->update_carrinho($id, array('status' => $status));
}
} else if ($result == "FALSO") {
$notice = "PagSeguro return was invalid.";
$this->log($notice);
$notice .= '<pre>'.print_r($_POST, TRUE).'</pre>';
$this->email_notice($notice);
} else {
$notice = "Error in PagSeguro request";
$this->log($notice);
$notice .= '<pre>'.print_r($_POST, TRUE).'</pre>';
$this->email_notice($notice);
}
}
安全更新:
张贴后,我很快就意识到,我是开自己交给了黑客攻击。该功能必须是公开的,所以任何知道该功能名称的人都可以访问它并发布“模拟”以便立即进行验证。然后他们可以传递他们想要的任何数据。
我改变了函数的名字的东西,是不可能的猜测,而当没有在生产模式,我已禁用的模拟选项。
您是否尝试过记录请求以确保PagSeguro实际上正在请求正确的页面?最好确定一下。 –
我不知道你的意思是如何记录请求,但毫无疑问,他们正在请求正确的页面。我已经多次验证了该网址。 –
我的意思是在Apache日志,谷歌分析,你的PHP应用程序,无论你想要的。使用HTTP_REFERER,请求的URL和GET/POST参数将每个请求写入日志文件,以确保它是正确的。如果你* 100%肯定*他们正在请求正确的URL,正确的参数,然后从来没有 - 但我会犯错谨慎的一面,只是确保。 –