<!--#include file="../wxpay/wxpay.Api.asp" -->
<!--#include file="member_check.asp" -->
<%
Function GetBody(url,sString) :set https=server.createobject("microsoft.XMLHTTP"):If Err Then:Err.Clear:set https=server.createobject("MSXML2.XMLHTTP"):end if:With https :.Open "Post", url, False:.setRequestHeader "Content-Type","application/x-www-form-urlencoded":.Send sString:GetBody = .ResponseBody:End With :GetBody = BytesToBstr(GetBody,"utf-8"):Set https = Nothing :End Function
Function BytesToBstr(body,Cset):dim objstream:set objstream = Server.CreateObject("adodb.stream"):objstream.Type = 1:objstream.Mode =3:objstream.Open:objstream.Write body:objstream.Position = 0:objstream.Type = 2:objstream.Charset = Cset:BytesToBstr = objstream.ReadText :objstream.Close:set objstream = nothing:End Function
O_id=trim(Request("O_id"))
action=trim(Request("action"))
pay_type=trim(Request("pay_type"))

if action="bankpay" then
if pay_type="" then
call box("请选择付款方式!","back","error")
else
response.Redirect "../bank/alipayapi.asp?O_id="&O_id&"&WIDdefaultbank="&pay_type
end if
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="qinuoli">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/user.css" type="text/css" />
<style>
.boxx{width:70px; height:25px; float:left; font-size:18px; padding:10px;background-color:#EEEEEE;border:#DDDDDD solid 1px; text-align:center;}
.box2x{width:70px; height:25px; float:left; font-size:18px; padding:10px;background-color:#EEEEEE;border-top:#DDDDDD solid 1px;border-right:#DDDDDD solid 1px;border-bottom:#DDDDDD solid 1px;text-align:center;}
.box3x{width:70px; height:25px; float:left; font-size:18px; padding:10px;background-color:#FFFFFF;border-left:#DDDDDD solid 1px;border-right:#DDDDDD solid 1px;border-top:#ff0000 solid 2px;text-align:center; }
.box4x{width:70px; height:25px; float:left; font-size:18px; padding:10px;background-color:#FFFFFF;border-right:#DDDDDD solid 1px;border-top:#ff0000 solid 2px; text-align:center;}

.boxy{background-color:#0066FF; padding:10px; margin:10px 3px 10px 3px; float:left; color:#FFFFFF; font-size:14px; width:60px;}
.box2y{background-color:#0099FF; padding:10px; margin:10px 3px 10px 3px; float:left; color:#FFFFFF; font-size:14px; width:60px;}
.bankbox{padding:5px; margin:5px; border:#CCCCCC solid 1px; width:185px; height:35px; float:left;}
</style>
<script>
function showv() { 
<%if C_alipayon="true" then%>
document.getElementById("v").style.display=''; 
document.getElementById("vv").className="box4x";
<%end if%>
<%if C_wxpayon="true" then%>
document.getElementById("t").style.display='none'; 
document.getElementById("tt").className="box2x";
<%end if%>
<%if C_bankon="true" then%>
document.getElementById("x").style.display='none'; 
document.getElementById("xx").className="box2x";
<%end if%>
 }
function showt() { 
<%if C_alipayon="true" then%>
document.getElementById("v").style.display='none'; 
document.getElementById("vv").className="box2x";
<%end if%>
<%if C_wxpayon="true" then%>
document.getElementById("t").style.display=''; 
document.getElementById("tt").className="box4x";
<%end if%>
<%if C_bankon="true" then%>
document.getElementById("x").style.display='none'; 
document.getElementById("xx").className="box2x";
<%end if%>
 }
function showx() { 
<%if C_alipayon="true" then%>
document.getElementById("v").style.display='none'; 
document.getElementById("vv").className="box2x";
<%end if%>
<%if C_wxpayon="true" then%>
document.getElementById("t").style.display='none'; 
document.getElementById("tt").className="box2x";
<%end if%>
<%if C_bankon="true" then%>
document.getElementById("x").style.display=''; 
document.getElementById("xx").className="box4x";
<%end if%>
 }
</script>
<script src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function test(){
$.post("post.asp",
    {
      O_id:"<%=O_id%>",
    },
    function(data){
	if(data==1){
	alert("支付成功！");
	document.location.href="member_order.asp";
	}
    });
}
setInterval("test()",3000); 
</SCRIPT>
<title>在线支付</title>
</head>
<body onLoad="<%if ubound(split(LCase(Request.ServerVariables("HTTP_USER_AGENT")),"micromessenger"))>0 Then%>showt()<%else%>showv()<%end if%>">
<%
if M_name="未填写" or M_add="未填写" or M_mobile="未填写" or M_code="未填写"  then
call box("请先完善收货信息，在进行支付","member_edit.asp","error")
end if

sql="select * from SL_orders,SL_product where O_pid=P_id and O_id="&O_id
set rs=Server.CreateObject("ADODB.RecordSet")
		rs.open sql,conn,1,1
		if not rs.eof then
		P_title=rs("P_title")
		P_path=rs("P_path")
		O_num=rs("O_num")
		O_price=rs("O_price")
		O_shuxing=rs("O_shuxing")
		end if
		rs.close
		set rs=nothing
		
		if O_shuxing="" then
		O_shuxing="标配"
		end if

if ubound(split(LCase(Request.ServerVariables("HTTP_USER_AGENT")),"micromessenger"))>0 Then
If Request.Cookies("openid")="" Then
     Code = Trim(Request.QueryString("code"))
     If Code = "" Then
	 response.Redirect "https://open.weixin.qq.com/connect/oauth2/authorize?appid="&APPID&"&redirect_uri="&server.URLEncode("http://"&request.ServerVariables("HTTP_HOST")&request.ServerVariables("URL")&"?O_id="&O_id)&"&response_type=code&scope=snsapi_base&state=123&connect_redirect=1#wechat_redirect"
     Else
set xmlhttp=server.createobject("microsoft.XMLHTTP")
If Err Then
Err.Clear
set xmlhttp=server.createobject("MSXML2.XMLHTTP")
end if
xmlhttp.open "Post","https://api.weixin.qq.com/sns/oauth2/access_token?appid="&APPID&"&secret="&APPSECRET&"&code="&Trim(Request.QueryString("code"))&"&grant_type=authorization_code",false
xmlhttp.send
xmlpass=xmlhttp.responsetext
set xmlhttp=nothing
C_config=xmlpass
response.Cookies("openid")=split(split(C_config,"openid"":""")(1),"""")(0)
End If
End If
Set Wx=Nothing
 set wxpay = New WxPayApi
   Dim body,out_trade_no,attach,total_fee,Arr,sUrl
   body = wxpay.GetDateTime
   out_trade_no = wxpay.GetDateTime
   attach = O_id
   total_fee = formatnumber(O_price*O_num,2,-1)

    wxpay.setParameter "openid",Request.Cookies("openid")
    wxpay.setParameter "body",body
	wxpay.setParameter "out_trade_no",out_trade_no
	wxpay.setParameter "attach",attach
	wxpay.setParameter "total_fee",(total_fee)*100
	wxpay.setParameter "trade_type","JSAPI"
    wxpay.setParameter "spbill_create_ip","127.0.0.1"
	wxpay.setParameter "notify_url",NOTIFY_URL
	wxpay.setParameter "device_info","WEB"
	
    jsApiParameters = wxpay.get_Parameters
	EditAddressParameters = wxpay.GetEditAddressParameters
	
 set wxpay = Nothing
 %>
 <script type="text/javascript">
	function jsApiCall()
	{
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			<%= jsApiParameters %>,
			function(res){
				WeixinJSBridge.log(res.err_msg);
				alert(res.err_code+res.err_desc+res.err_msg);
			}
		);
	}

	function callpay()
	{
		if (typeof WeixinJSBridge == "undefined"){
		    if( document.addEventListener ){
		        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
		    }else if (document.attachEvent){
		        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
		        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
		    }
		}else{
		    jsApiCall();
		}
	}
	</script>
<%
end if
%>
<!--#include file="top.asp" -->

<div style="background:#FFFFFF;">
<div style="background-color:#EEEEEE; height:47px;">
<%if C_alipayon="true" then%><a href="javascript:void(0);" onClick="showv()"><div class="box2x" id="vv"><img src="img/alipay.png"></div></a><%end if%>
<%if C_wxpayon="true" then%><a href="javascript:void(0);" onClick="showt()"><div class="box2x" id="tt"><img src="img/weixin.png"></div></a><%end if%>
<%if C_bankon="true" then%><a href="javascript:void(0);" onClick="showx()"><div class="box2x" id="xx"><img src="img/bank.png"></div></a><%end if%>
</div>
<%if C_alipayon="true" then%>
<div id="v">
<div style="background:#eeeeee; border:#CCCCCC solid 1px; margin:10px 0 10px 0; padding:10px;">
<table style="line-height:180%;">
<tr><td><img src="../<%=P_path%>" height="130" style="border:#FFFFFF solid 5px; margin-right:10px;"></td><td>
商品名称：<%=P_title%><br>
属性：<%=O_shuxing%><br>
单价：<%=formatnumber(O_price,2,-1)%>元<br>
数量：<%=O_num%><br>
价格：<%=formatnumber(O_price*O_num,2,-1)%>元
</td></tr>
</table>

</div>
<input type="button" class="button blue" value="付款" onClick="document.location.href='../alipay/alipayapi.asp?O_id=<%=O_id%>'">
</div>
<%end if%>
<%if C_wxpayon="true" then
set wxpay = New WxPayApi
%>
<div id="t">
<div style="background:#eeeeee; border:#CCCCCC solid 1px; margin:10px 0 10px 0; padding:10px;">
<table style="line-height:180%;">
<tr><td><img src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<%=split(GetBody("http://"&Request.ServerVariables("HTTP_HOST")&C_dir&"wxpay/native.asp","body="&P_title&"&attach="&O_id&"&total_fee="&formatnumber(O_price*O_num,2,-1)),"|")(0)%>" height="140" style="padding-right:10px;"></td><td>
商品名称：<%=P_title%><br>
属性：<%=O_shuxing%><br>
单价：<%=formatnumber(O_price,2,-1)%>元<br>
数量：<%=O_num%><br>
价格：<%=formatnumber(O_price*O_num,2,-1)%>元
</td></tr>
</table>
</div>
<%
if ubound(split(LCase(Request.ServerVariables("HTTP_USER_AGENT")),"micromessenger"))>0 Then
%>
<input type="button" class="button blue" value="付款" onClick="callpay()">
<%else
%>
支付方式：<br>
（1）微信中打开链接<br>
（2）使用微信扫描二维码完成付款。
<%
set wxpay = nothing
end if%>
</div>
<%end if%>
<%if C_bankon="true" then%>
<div id="x">
<div style="background:#eeeeee; border:#CCCCCC solid 1px; margin:10px 0 10px 0; padding:10px;">
<table style="line-height:180%;">
<tr><td><img src="../<%=P_path%>" height="130" style="border:#FFFFFF solid 5px; margin-right:10px;"></td><td>
商品名称：<%=P_title%><br>
属性：<%=O_shuxing%><br>
单价：<%=formatnumber(O_price,2,-1)%>元<br>
数量：<%=O_num%><br>
价格：<%=formatnumber(O_price*O_num,2,-1)%>元
</td></tr>
</table>
</div>
<form action="member_pay.asp?action=bankpay" method="post">
<table width="100%">
<input type="hidden" name="O_id" value="<%=O_id%>">
<tr><td>
<div class="bankbox"><input type="radio" value="ICBCB2C" name="pay_type" > <img src="img/bank/image001.jpg"></div> 
<div class="bankbox"><input type="radio" value="ABC" name="pay_type" > <img src="img/bank/image002.jpg"></div> 
<div class="bankbox"><input type="radio" value="CMB" name="pay_type" > <img src="img/bank/image003.jpg"></div> 
<div class="bankbox"><input type="radio" value="CCB" name="pay_type" > <img src="img/bank/image004.jpg"></div> 
<div class="bankbox"><input type="radio" value="BOCB2C" name="pay_type" > <img src="img/bank/image005.jpg"></div> 
<div class="bankbox"><input type="radio" value="COMM-DEBIT" name="pay_type" > <img src="img/bank/image006.jpg"></div> 
<div class="bankbox"><input type="radio" value="GDB" name="pay_type" > <img src="img/bank/image007.jpg"></div> 
<div class="bankbox"><input type="radio" value="CEB-DEBIT" name="pay_type" > <img src="img/bank/image008.jpg"></div> 
<div class="bankbox"><input type="radio" value="CITIC" name="pay_type" > <img src="img/bank/image009.jpg"></div> 
<div class="bankbox"><input type="radio" value="CMBC" name="pay_type" > <img src="img/bank/image010.jpg"></div> 
<div class="bankbox"><input type="radio" value="POSTGC" name="pay_type" > <img src="img/bank/image011.jpg"></div> 
<div class="bankbox"><input type="radio" value="SPABANK" name="pay_type" > <img src="img/bank/image013.jpg"></div> 
<div class="bankbox"><input type="radio" value="SPDB-DEBIT" name="pay_type" > <img src="img/bank/image014.jpg"></div> 
<div class="bankbox"><input type="radio" value="BJBANK" name="pay_type" > <img src="img/bank/image015.jpg"></div> 
<div class="bankbox"><input type="radio" value="SHRCB" name="pay_type" > <img src="img/bank/image016.jpg"></div> 
<div class="bankbox"><input type="radio" value="NBBANK" name="pay_type" > <img src="img/bank/image019.jpg"></div>
<div class="bankbox"><input type="radio" value="ICBCBTB" name="pay_type" > <img src="img/bank/image020.jpg"></div>
<div class="bankbox"><input type="radio" value="CMBBTB" name="pay_type" > <img src="img/bank/image021.jpg"></div>
<div class="bankbox"><input type="radio" value="CCBBTB" name="pay_type" > <img src="img/bank/image022.jpg"></div>
<div class="bankbox"><input type="radio" value="ABCBTB" name="pay_type" > <img src="img/bank/image023.jpg"></div>
<div class="bankbox"><input type="radio" value="SPDBB2B" name="pay_type" > <img src="img/bank/image024.jpg"></div>
</td></tr>

</table>
<input type="Submit" class="button blue" value="付款">
</form>
</div>
<%end if%>

<div style="font: 0px/0px sans-serif;clear: both;display: block"> </div>
</div>
</div>
</div>
</body>
</html>
