thinkphp5 tp5 调用微信支付 坑 时间戳 out_trade_no timestamp 字符串 模板输出变量时要使用原生PHP输出json数据

 

    //调用微信JS api 支付
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            <?PHP echo $param ?>,
            function(res){
                WeixinJSBridge.log(res.err_msg);
                alert(res.err_code+res.err_desc+res.err_msg);
            }
        );
    }

 

        $totalFee = $order['money']/100;
        $out_trade_no = date('Ymd',time()).uniqid();
        $notifyUrl = url('index/notify','','html',true);
        $timestamp = strval(time());

 

ajax请求支付参数在不同的手机上可能会出现问题

<script>
    $(function () {
        wx.config({
            debug: true,//调试模式
            appId: '<?php echo $signPackage['appId'] ?>',
            timestamp: <?php echo $signPackage['timestamp'] ?>,
            nonceStr: '<?php echo $signPackage['nonceStr'] ?>',
            signature: '<?php echo $signPackage['signature'] ?>',
            jsApiList: [
                'chooseWXPay'
            ]
        });
        $(".js-btn-wxpay").click(function () {
            if (typeof WeixinJSBridge == "undefined") {
                alert("请在微信中打开");
                return;
            }
            var success = false;
            wx.chooseWXPay({
                timestamp: <?php echo $bizPackage['timeStamp'] ?>,
                nonceStr: '<?php echo $bizPackage['nonceStr'] ?>',
                package: '<?php echo $bizPackage['package'] ?>',
                signType: '<?php echo $bizPackage['signType'] ?>',
                paySign: '<?php echo $bizPackage['paySign'] ?>',
                success: function (res) {
                    success = true;
                },
                complete: function () {
                    if (success) {
                        alert('支付成功');
                    } else {
                        alert('支付失败');
                    }
                }
            });
        });
    });

</script>

 

posted @ 2018-02-23 11:18  WilliamShaw  阅读(1632)  评论(0编辑  收藏  举报