<!--#include file="wxpay.Api.asp" -->
<%

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"))&"&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)"
   out_trade_no = wxpay.GetDateTime
   attach = "呵呵目于网络"'商户自定义数据包.
   total_fee = "0.01"

    wxpay.setParameter "openid",Request.Cookies("openid")'"oiQ6Bs4Vo0OWAAiHxVSbry7z6yzE"
    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
    'xml= wxpay.Get_Return_Xml()
	'wxpay.Die jsApiParameters
	
 set wxpay = Nothing
 %>
 <html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/> 
    <title>微信安全支付</title>
    <script type="text/javascript">
	//调用微信JS api 支付
	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>
</head>
<body>
    <br/>

    <font color="#9ACD32"><b>订单号：<span style="color:#f00;font-size:20px"><%= out_trade_no %></span></b></font><br/>
	<font color="#9ACD32"><b>商品名称：<span style="color:#f00;font-size:20px"><%= body %></span></b></font><br/>
	<font color="#9ACD32"><b>付款金额：<span style="color:#f00;font-size:50px"><%= total_fee %></span>元</b></font><br/>
	<div align="center">
		<button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" type="button" onClick="callpay()" >立即支付</button>
	</div>
</body>