<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> <meta content="yes" /> <meta content="black" /> <meta content="telephone=no" /> <title>微信支付</title> <script type="text/javascript" src="https://www.jb51.net/js/jquery.min.js"></script> <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> </head> <body> <script> //调用微信JS api 支付 function jsApiCall() { WeixinJSBridge.invoke( "getBrandWCPayRequest", {$parms}, //下面是支付完成后的回调,可以直接提示成功 function(res) { if(res.err_msg == "get_brand_wcpay_request:ok") { location.href = "{$success_url}"; }else if(res.err_msg == "get_brand_wcpay_request:cancel"){ // history.back(); location.href = "{$fail_url}"; }else{ alert("weixin return:" + JSON.stringify(res)); // alert(res.err_msg+" 参数有误,请返回!"); // history.back(); location.href = "{$fail_url}"; } } ); } 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(); } } callpay(); </script> </body> </html>
js微信支付实现代码
内容版权声明:除非注明,否则皆为本站原创文章。