亲宝软件园·资讯

展开

js微信支付实现代码

奇葩葩葩 人气:0

本文实例为大家分享了js微信支付的具体代码,供大家参考,具体内容如下

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.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" /> 
 <title>微信支付</title> 
 <script type="text/javascript" src="/js/jquery.min.js"></script> 
 <script type="text/javascript" src="http://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> 

加载全部内容

相关教程
猜你喜欢
用户评论