昨天帮一个客户写的,他的程序是老的asp,想实现微信在手机上下单付款,让帮忙给写一份asp微信支付的接口代码,昨天晚上闲着没事,搞了一个晚上才搞好,其实asp支付并不需要安装证书,其实asp支付也很好用,微信对asp的支持还是有的,回调入库等都很完善,不说了,上代码:
支付部份=============================
<% ‘作者微信:18611436777 SET Wx = New WxAPI If Session("openid")="" Then Code = Trim(Request.QueryString("code")) If Code = "" Then wx.get_redirect_uri = "http://"&request.ServerVariables("HTTP_HOST")&request.ServerVariables("URL")&"?"&request.QueryString Response.Redirect(Wx.GetAuthorization_Code) Else Call Wx.GetAccess_Token(Code) End If End If Set Wx=Nothing set wxpay = New WxPayApi Dim body,out_trade_no,attach,total_fee,Arr,sUrl body = "微信支付测试(18611436777)" out_trade_no = wxpay.GetDateTime attach = "购买商品"‘商户自定义数据包. total_fee = "0.01" wxpay.setParameter "openid",Session("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); if(res.err_msg.indexOf("ok")>0){ alert("付款成功!"); window.location.href=‘./‘; }else if(res.err_msg.indexOf("cancel")>0){ alert("取消付款!"); window.location.href=‘./‘; }else{ 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> <script type="text/javascript"> //获取共享地址 function editAddress() { WeixinJSBridge.invoke( ‘editAddress‘, <%= EditAddressParameters %>, function(res){ var value1 = res.proviceFirstStageName; var value2 = res.addressCitySecondStageName; var value3 = res.addressCountiesThirdStageName; var value4 = res.addressDetailInfo; var tel = res.telNumber; //alert(value1 + value2 + value3 + value4 + ":" + tel); var addrval = value1 + value2 + value3 + value4 + ":" + tel; var addr = document.querySelector(‘#addr‘); if(addrval !=‘NaN:undefined‘){ addr.innerHTML = "收货地址:<br/>" + value1 + value2 + value3 + value4 + ":" + tel; } } ); } </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:45%; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onClick="editAddress()" >使用微信地址</button> <button style="width:45%; 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> <div id="addr" style="color:#9ACD32;font-size:20px; margin-top:10px"></div> </body>
原文地址:https://www.cnblogs.com/yjed/p/10843654.html
时间: 2024-11-05 01:01:45