Nycholas 0 Denunciar post Postado Agosto 3, 2011 Olá pessoal, estou terminando de montar meu server de tibia e parei na parte do retorno automático para os 'points' que uma account ganha ao pagar por ela... Bem, os códigos em php estão com alguns erros, nos quais não consegui resolver completamente, por isso, preciso da ajuda de vocês, e gostaria de saber se poderiam revisar cada código... pagseguro.php: <?php if(!$logged)if($action == "logout")$main_content .= '<div class="TableContainer" > <table class="Table1" cellpadding="0" cellspacing="0" > <div class="CaptionContainer" > <div class="CaptionInnerContainer" > <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <div class="Text" >Logout Successful</div> <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer" > <table style="width:100%;" ><tr><td>You have logged out of your '.$config['server']['serverName'].' account. In order to view your account you need to <a href="?subtopic=accountmanagement" >log in</a> again.</td></tr> </table> </div> </table></div></td></tr>'; else $main_content .= 'Please enter your account name and your password.<br/> <a href="?subtopic=createaccount" >Create an account</a> if you do not have one yet.<br/> <br/><form action="?subtopic=accountmanagement" method="post" ><div class="TableContainer" > <table class="Table1" cellpadding="0" cellspacing="0" > <div class="CaptionContainer" > <div class="CaptionInnerContainer" > <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <div class="Text" >Account Login</div> <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer" > <table style="width:100%;" ><tr><td class="LabelV" ><span >Account Name:</span></td> <td style="width:100%;" ><input type="password" name="account_login" SIZE="10" maxlength="10" ></td></tr><tr><td class="LabelV" > <span >Password:</span></td><td><input type="password" name="password_login" size="30" maxlength="29" ></td></tr> </table> </div> </table></div></td></tr><br/> <table width="100%" ><tr align="center" ><td><table border="0" cellspacing="0" cellpadding="0" ><tr><td style="border:0px;" > <div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" > <div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div> <input class="ButtonText" type="image" name="Submit" alt="Submit" src="'.$layout_name.'/images/buttons/_sbutton_submit.gif" ></div></div></td><tr></form></table></td> <td><table border="0" cellspacing="0" cellpadding="0" ><form action="?subtopic=lostaccount" method="post" ><tr> <td style="border:0px;" ><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" > <div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div> <input class="ButtonText" type="image" name="Account lost?" alt="Account lost?" src="'.$layout_name.'/images/buttons/_sbutton_accountlost.gif" ></div></div></td></tr></form></table></td></tr></table>'; else {$main_content .= '<form target="pagseguro" method="post" action="https://pagseguro.uol.com.br/checkout/checkout.jhtml"><input type="hidden" name="email_cobranca" value="'. $config['pagseguro']['email']. '"> <input type="hidden" name="tipo" value="CP"><input type="hidden" name="moeda" value="BRL"><input type="hidden" name="item_id_1" value="1"> <input type="hidden" name="item_descr_1" value="Pontos na account de nome: '.$account_logged->getCustomField("name").'"> <input type="hidden" name="item_valor_1" value="'. $config['pagseguro']['produtoValor'] .'"><input type="hidden" name="item_frete_1" value="0"> <input type="hidden" name="item_peso_1" value="0"><input type="hidden" name="ref_transacao" value="'.$account_logged->getCustomField("name").'"> <table border="0" cellpadding="4" cellspacing="1" width="100%" id="#estilo"><tbody><tr bgcolor="#505050" class="white"><th colspan="2"> <strong>Escolha a quantidade de pontos que deseja comprar</strong></th></tr><tr><td width="10%">Sua conta</td><td><strong>'.$account_logged->getCustomField("name").'</strong></td></tr><tr> <td width="10%">Pontos</td><td><input name="item_quant_1" type="text" value="1" size="5" maxlength="5"></td></tr><tr> <td colspan="2"><input type="image" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/carrinhoproprio/btnFinalizar.jpg" name="submit" alt="Pague com PagSeguro - é rápido, grátis e seguro!" /></td></tr></tbody></table></form>'; } ?> retorno.php: <?php if (!defined('TOKEN')) define ('TOKEN', '7DF14A366DB74B5586C23EDA6791B102');/*** RetornoPagSeguro** Classe de manipulação para o retorno do post do pagseguro** @package PagSeguro*/ class RetornoPagSeguro {/*** _preparaDados** Prepara os dados vindos do post e converte-os para url, adicionando* o token do usuario quando necessario.** @internal é usado pela {@see RetornoPAgSeguro::verifica} para gerar os,* dados que serão enviados pelo PagSeguro** @access private** @param array $post Array contendo os posts do pagseguro* @param bool $confirmacao Controlando a adicao do token no post* @return string*/ function _preparaDados($post, $confirmacao=true) {if ('array' !== gettype($post)) $post=array(); if ($confirmacao) {$post['Comando'] = 'validar';$post['Token'] = TOKEN;}$retorno=array(); foreach ($post as $key=>$value){if('string'!==gettype($value)) $post[$key]='';$value=urlencode(stripslashes($value));$retorno[]="{$key}={$value}";} return implode('&', $retorno);}/*** _tipoEnvio** Checa qual será a conexao de acordo com a versao do PHP* preferencialmente em CURL ou via socket** em CURL o retorno será:* <code> array ('curl','https://pagseguro.uol.com.br/Security/NPI/Default.aspx') </code>* já em socket o retorno será:* <code> array ('fsocket', '/Security/NPI/Default.aspx', $objeto-de-conexao) </code>* se não encontrar nenhum nem outro:* <code> array ('','') </code>** @access private* @global string $_retPagSeguroErrNo Numero de erro do pagseguro* @global string $_retPagSeguroErrStr Texto descritivo do erro do pagseguro* @return array Array com as configurações**/ function _tipoEnvio() {//Prefira utilizar a função CURL do PHP //Leia mais sobre CURL em: http://us3.php.net/curlglobal $_retPagSeguroErrNo, $_retPagSeguroErrStr;if (function_exists('curl_exec'))return array('curl', 'https://pagseguro.uol.com.br/Security/NPI/Default.aspx');elseif ((PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://pagseguro.uol.com.br', 443, $_retPagSeguroErrNo, $_retPagSeguroErrStr, 30)))return array('fsocket', '/Security/NPI/Default.aspx', $fp);elseif ($fp = @fsockopen('pagseguro.uol.com.br', 80, $_retPagSeguroErrNo, $_retPagSeguroErrStr, 30))return array('fsocket', '/Security/NPI/Default.aspx', $fp);return array ('', '');}/*** not_null** Extraido de OScommerce 2.2 com base no original do pagseguro,* Checa se o valor e nulo** @access public** @param mixed $value Variável a ser checada se é nula* @return bool*/function not_null($value) {if (is_array($value)) {if (sizeof($value) > 0) {return true;} else {return false;}} else {if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {return true;} else {return false;}}}/*** verifica** Verifica o tipo de conexão aberta e envia os dados vindos* do post** @access public** @use RetornoPagSeguro::_tipoenvio()* @global string $_retPagSeguroErrNo Numero de erro do pagseguro* @global string $_retPagSeguroErrStr Texto descritivo do erro do pagseguro* @param array $post Array contendo os posts do pagseguro* @param bool $tipoEnvio (opcional) Verifica o tipo de envio do post* @return bool*/function verifica($post, $tipoEnvio=false) {global $_retPagSeguroErrNo, $_retPagSeguroErrStr;if ('array' !== gettype($tipoEnvio))$tipoEnvio = RetornoPagSeguro::_tipoEnvio();$spost=RetornoPagSeguro::_preparaDados($post);if (!in_array($tipoEnvio[0], array('curl', 'fsocket')))return false;$confirma = false;if ($tipoEnvio[0] === 'curl') {$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $tipoEnvio[1]);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $spost);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_TIMEOUT, 30);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);$resp = curl_exec($ch);if (!RetornoPagSeguro::not_null($resp)) {curl_setopt($ch, CURLOPT_URL, $tipoEnvio[1]);$resp = curl_exec($ch);}curl_close($ch);$confirma = (strcmp ($resp, 'VERIFICADO') == 0);} elseif ($tipoEnvio[0] === 'fsocket') {if (!$tipoEnvio[2]) {die ("{$_retPagSeguroErrStr} ($_retPagSeguroErrNo)");} else {$cabecalho = "POST {$tipoEnvio[1]} HTTP/1.0\r\n";$cabecalho .= "Content-Type: application/x-www-form-urlencoded\r\n";$cabecalho .= "Content-Length: " . strlen($spost) . "\r\n\r\n";$resp = '';fwrite ($tipoEnvio[2], "{$cabecalho}{$spost}");while (!feof($tipoEnvio[2])) {$resp = fgets ($tipoEnvio[2], 1024);if (strcmp ($resp, 'VERIFICADO') == 0) {$confirma = (strcmp ($resp, 'VERIFICADO') == 0);$confirma=true;break;}}fclose ($tipoEnvio[2]);}}if ($confirma && function_exists('retorno_automatico')) {$itens = array ('VendedorEmail', 'TransacaoID', 'Referencia', 'TipoFrete','ValorFrete', 'Anotacao', 'DataTransacao', 'TipoPagamento','StatusTransacao', 'CliNome', 'CliEmail', 'CliEndereco','CliNumero', 'CliComplemento', 'CliBairro', 'CliCidade','CliEstado', 'CliCEP', 'CliTelefone', 'NumItens',);foreach ($itens as $item) {if (!isset($post[$item])) $post[$item] = '';if ($item=='ValorFrete') $post[$item] = str_replace(',', '.', $post[$item]);}$produtos = array ();for ($i=1;isset($post["ProdID_{$i}"]);$i++) {$produtos[] = array ('ProdID' => $post["ProdID_{$i}"],'ProdDescricao' => $post["ProdDescricao_{$i}"],'ProdValor' => (double) (str_replace(',', '.', $post["ProdValor_{$i}"])),'ProdQuantidade' => $post["ProdQuantidade_{$i}"],'ProdFrete' => (double) (str_replace(',', '.', $post["ProdFrete_{$i}"])),'ProdExtras' => (double) (str_replace(',', '.', $post["ProdExtras_{$i}"])),);}retorno_automatico ($post['VendedorEmail'], $post['TransacaoID'], $post['Referencia'], $post['TipoFrete'],$post['ValorFrete'], $post['Anotacao'], $post['DataTransacao'], $post['TipoPagamento'],$post['StatusTransacao'], $post['CliNome'], $post['CliEmail'], $post['CliEndereco'],$post['CliNumero'], $post['CliComplemento'], $post['CliBairro'], $post['CliCidade'],$post['CliEstado'], $post['CliCEP'], $post['CliTelefone'], $produtos, $post['NumItens']);}return $confirma;}}if ($_POST) {RetornoPagSeguro::verifica($_POST);die();} ?> retpagseguro.php: <?php #CONFIGURAÇÕES## $retorno_site = '/?subtopic=latestnews'; // Site para onde o usuário vai ser redirecionado $retorno_host = 'localhost'; // Local da base de dados MySql $retorno_database = 'otserv'; // Nome da base de dados MySql $retorno_usuario = 'root'; // Usuario com acesso a base de dados MySql $retorno_senha = ''; // Senha de acesso a base de dados MySql ################################################################ NÃO ALTERE DESTA LINHA PARA BAIXO################################################################ $lnk = mysql_connect($retorno_host, $retorno_usuario, $retorno_senha) or die ('Nao foi possível conectar ao MySql: ' . mysql_error()); mysql_select_db($retorno_database, $lnk) or die ('Nao foi possível ao banco de dados selecionado no MySql: ' . mysql_error()); require_once("retorno.php"); function retorno_automatico ($VendedorEmail, $TransacaoID, $Referencia, $TipoFrete,$ValorFrete, $Anotacao, $DataTransacao, $TipoPagamento,$StatusTransacao, $CliNome, $CliEmail, $CliEndereco,$CliNumero, $CliComplemento, $CliBairro, $CliCidade,$CliEstado, $CliCEP, $CliTelefone, $produtos, $NumItens) // Gravando DadosP { $quantidade = $produtos[0]['ProdQuantidade']; mysql_query("INSERT into PagSeguroTransacoes SET TransacaoID='$TransacaoID', VendedorEmail='$VendedorEmail', Referencia='$Referencia', TipoFrete='$TipoFrete', ValorFrete='$ValorFrete', Extras='$Extras', Anotacao='$Anotacao', TipoPagamento='$TipoPagamento', StatusTransacao='$StatusTransacao', CliNome='$CliNome', CliEmail='$CliEmail', CliEndereco='$CliEndereco', CliNumero='$CliNumero', CliComplemento='$CliComplemento', CliBairro='$CliBairro', CliCidade='$CliCidade', CliEstado='$CliEstado', CliCEP='$CliCEP', CliTelefone='$CliTelefone', NumItens='$NumItens', ProdQuantidade='$quantidade', Data=now();"); if ($StatusTransacao == 'Completo' OR $StatusTransacao == 'Aprovado') {$query = "SELECT premium_points FROM accounts WHERE accounts.name = '$Referencia'"; $result = mysql_query($query); $prem = mysql_fetch_array($result);$points = $prem['premium_points'] + $quantidade; // $points = mysql_query($prem)$qry2 = "UPDATE accounts SET premium_points = '$points' WHERE accounts.name = '$Referencia'"; $result2 = mysql_query($qry2); }} <script type="text/javascript">window.location = '/?subtopic=latestnews';</script> ?> Bem, por favor, me ajudem a terminar ou ver o que está errado... OBS: Já tentei usar outros sistemas e não funcionaram, ainda tenho um pouco de fé quanto a esse. Compartilhar este post Link para o post Compartilhar em outros sites
alcaidedigital 57 Denunciar post Postado Agosto 4, 2011 Está dando algum erro? Fica meio difícil procurar uma coisa que não sabemos exatamente o que estamos procurando. Compartilhar este post Link para o post Compartilhar em outros sites