<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>求真酒业</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div id="info">
    <div style="font-weight: bold;font-size:1.2rem;border-bottom: 1px solid #d5d5d5;padding: 1rem;text-align:center;">
        求真酒业品牌推荐官微信绑定
    </div>
    <div style="padding: 1rem;">
        品牌推荐官在绑定返利微信号OpenID后才可获得返利
    </div>
    <div>
        <div style="font-weight: bold;padding: 1rem;font-size:0.9rem;">
            手机号
        </div>
        <div style="padding: 0.2rem 1rem;">
            <input type="number" id="br-username" style="padding: 0.5rem;outline:none;width:90%;" placeholder="在此输入品牌推荐官手机号码"/>
        </div>
    </div>
    <div>
        <div style="font-weight: bold;padding: 1rem;font-size:0.9rem;">
            密码 (默认密码为123456)
        </div>
        <div style="padding: 0.2rem 1rem;">
            <input type="password" id="br-password" style="padding: 0.5rem;outline:none;width:90%;" placeholder="在此输入品牌推荐官帐号密码"/>
        </div>
    </div>
    <div style="display:flex;justify-content: center;align-items:center;padding: 1rem;margin-top:1rem;">
        <div id="br-btn-login" style="padding: 0.5rem 2rem;background: #588ac0;color:#fff;font-weight: bold;border-radius: 7px;">
            登录并绑定当前微信OpenID
        </div>
    </div>
</div>
    <script>
        
        function getQueryString(name) {
            let reg = `(^|&)${name}=([^&]*)(&|$)`
            let r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
        function getCookie(name)
        {
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
            if(arr=document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        }
        $(document).ready(function() {
                var consumer_id = getQueryString('consumer_id');
                var wxopenid = getCookie('wxopenid');

                $('#br-btn-login').click(function() {
                    var uploadData = new FormData();
                    uploadData.append('username', $('#br-username').val());
                    uploadData.append('password', $('#br-password').val());
                    uploadData.append('wxopenid', wxopenid);

                    $.ajax({
                        url :'https://davis.china315net.com/wx/activity_bonus/openidBinding/',
                        type: 'POST',
                        contentType: false,
                        processData: false,
                        data: uploadData,
                        success: function(res) {
                            console.log(res);
                            if(res.e == '') {
                                alert('绑定成功!');
                            }else {
                                alert('绑定失败：' + res.e);
                            }
                        }
                    })
                })

        })
    </script>
</body>
</html>
