<?php
	header("Content-type:text/html;charset=utf-8");
	include("../include/conn_2.php");
	include("../include/function.php");
	include("../include/public.php");

	session_start();
	$username = $_SESSION["glo_username"];
	$amount = $_POST['amount'];
	$Bank   = $_POST['paytype'];

	if($amount && $Bank){

		//判断金额
		if(is_int($amount)){
			echo"<script>alert('金额必须是整数倍');history.go(-1);</script>";  
			die();
		 }

		if($amount<10){
			echo"<script>alert('金额必须大于等于100');history.go(-1);</script>";  
			die();
		}

		//支付
		$orderNo 	   = ordernumber();				 //生成订单号
		$tradeDate 	   = date('Ymd',time());
		$amt 	   	   = intval($amount);
		$merchParam    = "";				   		 // 商户参数
		$tradeSummary  = $username.' | '.$amt;		 //交易摘要
		$bankCode  	   = trim($Bank);				 //银行

		//插入记录
		$sql_in_log = "insert into {$db_prefix}member_order(`ordernumber`,`username`,`amount`,`memo`,`type`,`status`,`posttime`,`ip`,`bank`) value('{$orderNo}','{$username}','{$amt}','{$tradeSummary}','在线充值',0,'".time()."','".getip()."','{$bankCode}')";
		$rs_log = $db->query($sql_in_log);
		if($rs_log){
			mobaoPay($orderNo,$tradeDate,$amt,$bankCode,$merchParam,$tradeSummary);
		}else{
			echo"<script>alert('充值失败，请重新提交');history.go(-1);</script>";  
			die();
		}
	}

	function mobaoPay($orderNo,$tradeDate,$amt,$bankCode,$merchParam,$tradeSummary)
	{
		
		echo "<html>";
		echo "<head>";
		echo "<title>To Pay Page</title>";
		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>";
		echo "<body onLoad=\"document.form1.submit();\">";
		echo "<form name=\"form1\" id=\"form1\" action=\"http://order.kel1.top/mobile/action/NewPay/req.php\" method=\"post\">";
		echo "<input type=\"hidden\" name=\"orderNo\" id=\"orderNo\" value=\"".$orderNo."\">";
		echo "<input type=\"hidden\" name=\"tradeDate\" id=\"tradeDate\" value=\"".$tradeDate."\">";
		echo "<input type=\"hidden\" name=\"amt\" id=\"amt\" value=\"".$amt."\">";
		echo "<input type=\"hidden\" name=\"bankcode\" id=\"bankcode\" value=\"".$bankCode."\">";
		echo "<input type=\"hidden\" name=\"merchParam\" id=\"merchParam\" value=\"".$merchParam."\">";
		echo "<input type=\"hidden\" name=\"tradeSummary\" id=\"tradeSummary\" value=\"".$tradeSummary."\">";
		echo "</form>";
		echo "</body>";
		echo "</html>";
	}

?>