Thinkphp整合微信支付功能

2019-05-02 08:19:53王冬梅

发起支付后拼接预支付数据参数(参数列表看微信普通商户开发者文档——微信支付——统一下单)display的页面:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta name="format-detection" content="telephone=no"/> 
<title>下</title>
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<meta name="keyword" content="">
<meta name="description" content="">
<script type="text/javascript">
var order_sn = "{$res['order_sn']}";
//调用微信JS api 支付
function jsApiCall(){
 WeixinJSBridge.invoke(
  'getBrandWCPayRequest',
  <?php echo $jsApiParameters; ?>,
  function(res){
   //如果支付成功
   if (res.err_msg == 'get_brand_wcpay_request:ok') {
    //支付成功后跳转的地址
    location.href = "{:U('Home/User/my_order')}";
   }else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
    alert('请尽快完成支付哦!');
   }else if (res.err_msg == 'get_brand_wcpay_request:fail') {
    alert('支付失败');
   }else {
    alert('意外错误');
   }
   //WeixinJSBridge.log(res.err_msg);
   //alert(res.err_code+res.err_desc+res.err_msg);
   /*if (res.err_msg == 'get_brand_wcpay_request:ok') {
    alert('支付成功');
   }else {
    alert('取消支付');
   }*/
  }
 );
}
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>
<style>
*{font-family:'微软雅黑','Microsoft YaHei';}
body #head{position:relative;z-index:99999999999999;padding:0 10px;}
body .zh-head{padding:0 0 0 0;height:auto;}
.zh-head-conter{position:relative;height:40px;}
.zh-logo{position:absolute;left:50%;top:0;margin:0 0 0 -60px;float:none;width:auto;}
.zh-logo a{display:block;}
.zh-logo img{width:120px;height:40px;display:block;}
.heads_fix .zh-logo{}
#head{position:fixed!important;left:0;top:0;right:0;z-index:99999;background:#fff;border-bottom:1px solid #ddd;}
.zh-logo{height:40px;}
.flowpay{margin-top:25%;}
.flowpay dt{text-align:center;}
.flowpay strong.price{font-size:40px;}
.wxLogo{text-align:center;}
.wxLogo img{}
.flowpay dd{margin:0;padding:20px 0 10px 0;}
.flowpay dd input{margin:0 auto;padding:0;width:90%;height:45px;line-height:45px;border:0;border-radius:4px;background:#0CBC0A;color:#fff;font-size:17px;display:block;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;}
</style>
</head>
<body>
<!--头部开始-->
<div class="flowpay">
 <dl>
  <dt>
   <p class="wxLogo"><img src="__PUBLIC__/home/images/1479953699138120.png" alt=""></p>
   本次订单需支付:¥<strong class="price">{$res['order_amount']}</strong> 元
  </dt>
  <dd>
   <input type="button" id="hhhhhh" onclick="callpay()" value="立即支付" />
  </dd>
 </dl>
</div>
<!--尾结束-->
</body>
</html>								 
			 
相关文章 大家在看