js 调用微信浏览器内置方法,启动支付

 $.post("{php echo app_url('pay/cash')}",{orderno:orderno,paytype:paytype},function(m){ //todo: 跳转到微信支付,获取支付的相关信息
                            if(!m.errno){
                                m.data.timeStamp = String(m.data.timeStamp);
                                WeixinJSBridge.invoke('getBrandWCPayRequest', {
                                    'appId': m.data.appid ? m.data.appid : m.data.appId,
                                    'timeStamp': m.data.timeStamp,
                                    'nonceStr': m.data.nonceStr,
                                    'package': m.data.package,
                                    'signType': m.data.signType,
                                    'paySign': m.data.paySign,
                                }, function(res) {
                                    if(res.err_msg == 'get_brand_wcpay_request:ok') {
                                        location.href = "{php echo app_url('pay/cash')}&orderno="+orderno+"&paytype="+paytype+"&done=1";
                                    } else {
                                        $.post("{php echo app_url('pay/paytype')}",{orderno:orderno,remark:remark,othername:othername,op:"ajax",checkpay:"8"},function(m){
                                            $.toast("已取消支付");
                                        },"json");
                                    }
                                });
                            }else{
                                $.confirm(m.message, function () {
                                    history.go(-1);
                                })
                            }
                        },"json");

  

 document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.invoke('getBrandWCPayRequest',pathinfo , function(res) { // Pathinfo:json,相关的信息
            if(res.err_msg == 'get_brand_wcpay_request:ok') {
                location.href='/index.php/Mobile/User/order_detail/id/'+orderid+'.html'
            } else {
                location.href='{$url}'
            }
        });
    }, false);

  

posted @ 2018-03-16 09:30  小小强学习网  阅读(4103)  评论(0编辑  收藏  举报