<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>微信安全支付</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            height: 100%;
            position: relative;
        }

        .banner {
            width: 100%;
            height: 67.4vw;
            display: block;
        }

        .tip {
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-box-align: center;
            -ms-flex-align: center;
            align-items: center;
            -webkit-box-orient: horizontal;
            -webkit-box-direction: normal;
            -ms-flex-direction: row;
            flex-direction: row;
            -webkit-box-pack: start;
            -ms-flex-pack: start;
            justify-content: flex-start;
            font-size: 16px;
            color: #808080;
            padding: 25px 12px;
        }

        .tip img {
            width: 1em;
            margin-right: 20px;
        }

        .btn{
            background-color: #4ac22b;
            border-radius: 5px;
            text-align: center;
            font-size: 18px;
            height: 50px;
            line-height: 50px;
            margin: 0 12px;
            color: #fff;
        }

        .support{
            position: absolute;
            width: 100%;
            bottom: 1.5em;
            left: 0;
            text-align: center;
            color: #999;
            font-size: 14px;
        }
    </style>
</head>
<body>
<img class="banner" src="https://cdn-novel.iycdm.com/static/img/paybackground.jpg">
<div class="tip">
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlCAYAAADFniADAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG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d5Gd38wGXlDM3vz+FAvTVfsXW7iMNiBtfVC/YoCtrJL0OtlzARmsTM2CxbVDdoL3kKKRhmh+oFCgcj3m30q5dzlGtPvoAcoUq1R+zfb2PjZgHF9/y/gxyhYqE45qLzaHzVsXu32hdmB9Hr3IAcP770dPZPWDcomzxxBXKMEgJCX5iXoIHevt9gXoPaP3wD3YEFo6GfDAqLjIxDM8qegQZG9YJpRt1TkCuUHTZKENXGM1amMp6BXKM6sKX4Ov+f4iiO4ig/UGpnHMMytv4ViqITtPZ8iBXMNM12fysHQznJExRFadIDUpukNEYYzeqfoJ4fAQYAz8zjeuE3n/8AAAAASUVORK5CYII=">
    <p>已开启支付安全</p>
</div>
<div class="btn" onclick="onBridgeReady()">
    确认支付
</div>
<p class="support">支付安全由中国人民财产保险股份有限公司承保</p>

<script>
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId":"{{ $pay_info['appId'] }}",     //公众号名称，由商户传入
                "timeStamp":"{{ $pay_info['timeStamp'] }}",         //时间戳，自1970年以来的秒数
                "nonceStr":"{{ $pay_info['nonceStr'] }}", //随机串
                "package":"{{ $pay_info['package'] }}",
                "signType":"{{ $pay_info['signType'] }}",         //微信签名方式：
                "paySign":"{{ $pay_info['paySign'] }}" //微信签名
            },
            function(res){
                // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                    //alert('支付成功，点击跳转回去');
                    window.location.href = "{!! $pay_info['pay_wait_url'] !!}";
                } else{
                    var str = JSON.stringify(res);
                    var appid = "{{ $pay_info['appId'] }}"
                    var pay_order = "{{ $pay_order }}"
                    var rand = Math.random();
                    var temp_str = appid+','+pay_order+','+rand;
                    postError('onBridgeReady Error,'+str+','+temp_str);
                }
            }
        );
    }

    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }

   function postError(data) {
       try{
           var xhr = new XMLHttpRequest();
           xhr.open("POST", '/pay/reportError', true);
           xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
           xhr.send('data='+data);
       }catch (Error){
            alert('sys error');
       }
   }
</script>
</body>
</html>