/** * Created by raymondjack on 2018/12/21. */ var info = {}; var $toast = $('.toast'); var $mask = $('.status-mask'); var lockBol = false; $(function () { var browser = checkVersion(); var api = getUrlPrefix(); var timer = null; var env = EnvCheck(); var urlObj = getQueryString(); if (env == 'test') { var vConsole = new VConsole(); } getInfoFromClient && getInfoFromClient() if (browser.app) { if (browser.android) { let channel = JSON.parse(pubInfo.deviceInfo).channel if (channel.indexOf('toutiao') != -1 || channel.indexOf('kuaishou') != -1) { $('.appName').html('piko') } } } var main = { init: function () { this.getDeviceMsg(); this.eventRegister(); var that = this; setTimeout(function () { that.getData(); }, 200) }, getDeviceMsg: function () { if (browser.app) { if (browser.android) { info.uid = parseInt(window.androidJsObj.getUid()); info.deviceId = window.androidJsObj.getDeviceId(); info.ticket = window.androidJsObj.getTicket(); } else { info.uid = tools.cookieUtils.get("uid"); if (!info.uid) { window.webkit.messageHandlers.getUid.postMessage(null); } window.webkit.messageHandlers.getDeviceId.postMessage(null); window.webkit.messageHandlers.getTicket.postMessage(null); } } else { info.uid = 922473; info.deviceId = "204aa0c983384f1e84a3625b4f04bac1"; } // setTimeout(function () { // $('.deviceId').val(info.deviceId); // },200) }, getData: function () { console.log(urlObj, 'urlObj') if (urlObj) { info.auth = urlObj.auth } else { info.auth = '' } console.log(info.auth, 'info.auth') $.ajax({ type: "get", url: api + "/certification/hasCertify", headers: { "pub_ticket": info.ticket }, data: { uid: info.uid, auth: info.auth, ticket: info.ticket, }, success: function (res) { if (res.code == 200) { var checkBol = res.data; var $mask = $('.status-mask'); if (checkBol.authResult) { console.log('已短信验证!') } else if (checkBol.hasCertify && !checkBol.canCertify) { console.log('已实名且没有机会了') $mask.addClass("have-identity"); $mask.find(".text").html("您已通过实名认证"); $mask.find(".tips").html("系统已成功审核您的实名认证"); $mask.show(); } else if (checkBol.hasCertify && checkBol.canCertify) { console.log('已实名还有一次机会') // var $mask = $('.status-mask'); $mask.addClass("have-identity"); $mask.find(".text").html("您已通过实名认证"); $mask.find(".tips").html("系统已成功审核您的实名认证"); $mask.find(".goto-change").removeClass('hide'); $mask.show(); } } } }) }, eventRegister: function () { $('.button-submit').on('click', function () { var name = $('.name').val(); var personId = $('.person-id').val(); var phone = $('.phone').val(); var identityCode = $('.identity-code').val(); var agree = $('#agree').prop("checked"); if (!agree) { toastShow("请同意直播协议"); return; } if (!name.trim()) { toastShow("名字不能为空"); return; } if (!personId.trim()) { toastShow("身份证号不能为空"); return; } if (!phone.trim()) { toastShow("手机号不能为空"); return; } if (!identityCode.trim()) { toastShow("验证码不能为空"); return; } if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test(personId.trim())) { toastShow("身份证号不符合规格"); return; } if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/).test(phone.trim())) { toastShow("手机号不符合规格"); return; } if (lockBol) { return; } lockBol = true; var requestParam = { uid: info.uid, username: encryptDes(name, "1ea53d260ecf11e7b56e00163e046a26"), identityNumber: encryptDes(personId, "1ea53d260ecf11e7b56e00163e046a26"), phone: encryptDes(phone, "1ea53d260ecf11e7b56e00163e046a26"), code: identityCode, ticket: info.ticket }; if (browser.android) { requestParam.deviceInfo = JSON.stringify({ deviceId: info.deviceId }); } $.ajax({ type: "get", url: api + "/certification/token", data: requestParam, headers: { "pub_ticket": info.ticket }, success: function (res) { if (res.code == 200) { var token = res.data.token; info.token = token; // if(browser.app){ if (browser.ios) { window.webkit.messageHandlers.openFaceLiveness.postMessage(token); } else { window.androidJsObj.openFaceLiveness(token); } // } } else { if (res.code == 10109) { $mask.addClass("failed"); $mask.find(".text").html("实名认证失败"); $mask.find(".tips").html("该身份证实名认证已达5次"); } else if (res.code == 10110) { $mask.addClass("have-identity"); $mask.find(".text").html("您已通过实名认证"); $mask.find(".tips").html("系统已成功审核您的实名认证"); } else if (res.code == 4003) { $mask.addClass("failed"); $mask.find(".text").html("实名认证失败"); $mask.find(".tips").html("验证码错误"); } else { $mask.addClass("failed"); $mask.find(".text").html("实名认证失败"); $mask.find(".tips").html("请填写真实有效的身份证信息"); } $mask.show(); lockBol = false; setTimeout(function () { $('.status-mask').hide(); }, 4000); } } }); // $.post(api + "/certification/doCheck",requestParam,function (res) { // // }) }) $('.button-identity-code').on('click', function () { var phone = $('.phone').val(); if (!phone.trim()) { toastShow("手机号不能为空"); return; } if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/).test(phone.trim())) { toastShow("手机号不符合规格"); return; } if ($(this).hasClass("disable")) { return; } $(this).addClass('disable'); var time = 60; var $that = $(this); $(this).html(time + 's后重新获取'); timer = setInterval(function () { time--; $that.html(time + "s后重新获取"); if (time < 0) { clearInterval(timer); $that.removeClass('disable'); $that.html("获取验证码"); } }, 1000) var requestParam = { phone: encryptDes(phone, "1ea53d260ecf11e7b56e00163e046a26"), uid: info.uid, ticket: info.ticket }; if (browser.android) { requestParam.deviceInfo = JSON.stringify({ deviceId: info.deviceId }); } $.ajax({ type: "post", url: api + "/certification/send/code", headers: { "pub_ticket": info.ticket }, data: requestParam, success: function (res) { console.log(res, '请求成功'); if (res.code == 200) { toastShow('发送成功'); } else { toastShow(res.message); console.log(res, '报错啦'); } }, error: function (res) { toastShow(res.message); console.log(res, '报错啦'); } }); }) // 点击我要修改 $('.goto-change').on('click', function () { $mask.hide(); $('.layer-box-2').show(); }) // 点击关闭弹层 $('.layer-2-close').on('click', function () { $('.layer-box-2').hide(); $mask.show(); }) // 点击跳转手机验证 $('.goto-change-layer').on('click', function () { window.location.href = 'mobile.html'; }) } }; main.init(); }); function toastShow(text) { $toast.html(text); $toast.show(); setTimeout(function () { $toast.hide(); }, 2000); } function getMessage(key, value) { info[key] = value; } function renderByStatus(status) { $mask.attr('class', 'status-mask'); console.log("开始回调," + "状态为" + status); $.ajax({ type: 'post', url: locateJudge() + '/certification/notify', headers: { "pub_ticket": info.ticket }, data: { uid: info.uid, ticket: info.ticket, token: info.token, statusCode: status }, success: function (res) { console.log(res); lockBol = false; if (res.code == 200) { console.log("success"); if (status == 2) { $mask.addClass("success"); $mask.find(".text").html("认证成功"); $mask.find('.tips').html(''); $mask.show(); } else { if (status == -2) { $mask.addClass("failed"); $mask.find(".text").html("认证失败"); $mask.find(".tips").html("网络不通或者网络异常"); } else if (status == 1) { $mask.addClass("failed"); $mask.find(".text").html("认证失败"); $mask.find(".tips").html("审核失败"); } else { console.log('存在异常,status=' + status); // window.location.reload(); return; } $mask.show(); setTimeout(function () { $mask.hide(); }, 4000); } } } }); console.log('status', status); } //DES加密 const encryptDes = (message, key) => { var keyHex = CryptoJS.enc.Utf8.parse(key); var encrypted = CryptoJS.DES.encrypt(message, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString(); }