<?php
require ('authentication_member.php');
?>
<?php

/* 在线充值入帐 */  
/* 162100源码 - 162100.comhttps://cashier.alipay.com/standard/gateway/ebankPay.htm?outBizNo=2011110436025777&bizIdentity=trade20001&orderId=951375f737ae278bb48a6654a8da8658 */
//https://cashier.alipay.com/standard/gateway/ebankPay.htm?outBizNo=2011110436152377&bizIdentity=trade20001&orderId=f9383e308bfaf787f90ba9b79e592e94

//https://cashierzue.alipay.com/standard/result/rnPaymentResult.htm?payNo=20150504A6DF5365&outBizNo=2015050400001000650051162011&msg=%7B%7D&bizIdentity=trade20001&orderId=0504ffe4d5e9130ea753b37009105656&stat=ok

$out_trade_no = $_POST['WIDout_trade_no'];
$trade_no     = $_POST['WIDtrade_no'];
$total_fee    = $_POST['WIDtotal_fee'];

function run_datetime($v) {
  $v = preg_replace('/^(\d{4})(\d{2})?(\d{2})?(\d{2})?(\d{2})?(\d{2})?$/', '$1-$2-$3 $4:$5:$6', preg_replace('/[^\d]+/', '', $v));
  return preg_replace('/^[^\d]+|[^\d]+$/', '', $v);
}

if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] == '') {

    $result = @mysql_query('SELECT id FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE type="0" AND date="'.run_datetime($out_trade_no).'"', $db);
    if (!@mysql_num_rows($result) > 0) {
      @mysql_free_result($result);

      list($amount, $username) = @explode('|', @file_get_contents('__temp__/order/'.$out_trade_no.'.txt'));
      if (!empty($amount) && $total_fee == $amount) {

        @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`date`,`money`,`other`) VALUES ("'.$username.'","0","在线充值","'.run_datetime($out_trade_no).'","'.$total_fee.'","交易号：'.$trade_no.'")', $db);
        if (@mysql_affected_rows() > 0) {
          @unlink('__temp__/order/'.$out_trade_no.'.txt');
          alert('充值成功！', 'member.php?get=myfunds');
        }
      }/* else {
        err ('无法找到订单文件（或交易数据往来出错）！');
      }*/
    } else {
      @mysql_close();
      alert('充值已完成！', 'member.php?get=myfunds');
    }

}/* else {
  err($sql['db_err']);
}*/
@mysql_close();


err('很遗憾！充值失败。请记好此次充值订单号：'.$out_trade_no.'、交易号：'.$trade_no.'，<a href="member.php?get=mess&username=admin">联系管理员</a>解决。');




?>