Files
peko-h5/view/peko/modules/identity/js/new.js

355 lines
12 KiB
JavaScript
Raw Normal View History

2022-09-08 18:22:18 +08:00
/**
* Created by raymondjack on 2018/12/21.
*/
2024-01-10 14:50:40 +08:00
// var pubInfo = {};
2022-09-08 18:22:18 +08:00
var $toast = $('.toast');
var $mask = $('.status-mask');
var lockBol = false;
2024-01-10 14:50:40 +08:00
let urlPrefix = getUrlPrefix()
var goToPage;
2022-09-08 18:22:18 +08:00
$(function () {
2024-01-10 14:50:40 +08:00
getInfoFromClient()
var browser = checkVersion();
var api = getUrlPrefix();
var timer = null;
var env = EnvCheck();
var urlObj = getQueryString();
2024-01-12 15:17:38 +08:00
console.log(urlObj.uid);
if (urlObj.uid) {
sessionStorage.setItem("uid", urlObj.uid);
sessionStorage.setItem("ticket", urlObj.ticket);
}
2024-01-10 14:50:40 +08:00
if (env == 'test') {
var vConsole = new VConsole();
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
getInfoFromClient && getInfoFromClient()
if (browser.app) {
2022-09-08 18:22:18 +08:00
if (browser.android) {
2024-01-10 14:50:40 +08:00
let channel = JSON.parse(pubInfo.deviceInfo).channel
if (channel.indexOf('toutiao') != -1 || channel.indexOf('kuaishou') != -1) {
$('.appName').html('piko')
}
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
var main = {
init: function () {
this.getDeviceMsg();
this.eventRegister();
var that = this;
setTimeout(function () {
that.getData();
}, 200)
2022-09-08 18:22:18 +08:00
},
2024-01-10 14:50:40 +08:00
getDeviceMsg: function () {
// if (browser.app) {
// if (browser.android) {
// pubInfo.uid = parseInt(window.androidJsObj.getUid());
// pubInfo.deviceId = window.androidJsObj.getDeviceId();
// pubInfo.ticket = window.androidJsObj.getTicket();
// } else {
// pubInfo.uid = tools.cookieUtils.get("uid");
// if (!pubInfo.uid) {
// window.webkit.messageHandlers.getUid.postMessage(null);
// }
// window.webkit.messageHandlers.getDeviceId.postMessage(null);
// window.webkit.messageHandlers.getTicket.postMessage(null);
// }
// } else {
// pubInfo.uid = 922473;
// pubInfo.deviceId = "204aa0c983384f1e84a3625b4f04bac1";
// }
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
// setTimeout(function () {
// $('.deviceId').val(pubInfo.deviceId);
// },200)
},
getData: function () {
console.log(urlObj, 'urlObj')
if (urlObj) {
pubInfo.auth = urlObj.auth
} else {
pubInfo.auth = ''
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
console.log(pubInfo.auth, 'pubInfo.auth')
networkRequest({
type: 'get',
url: urlPrefix + '/certification/hasCertify',
data: {
uid: pubInfo.uid,
auth: pubInfo.auth,
ticket: pubInfo.ticket,
},
success: function (res) {
if (res.code == 200) {
var checkBol = res.data;
var $mask = $('.status-mask');
2024-01-12 15:39:01 +08:00
if (checkBol.hasCertify) {
console.log('继续认证操作');
} else if (checkBol.canCertify == false && checkBol.hasCertify == false) {
goToPage == true;
$mask.addClass("failed");
$mask.find(".text").html("您未通过实名认证");
$mask.find(".tips").html("系统审核您的实名认证失败");
2024-01-12 15:39:01 +08:00
$mask.find(".goto-change").removeClass('hide');
2024-01-10 14:50:40 +08:00
$mask.show();
} else if (canCertify == false && hasCertify == true) {
goToPage == true;
2024-01-10 14:50:40 +08:00
$mask.addClass("have-identity");
$mask.find(".text").html("您已通过实名认证");
$mask.find(".tips").html("系统已成功审核您的实名认证");
2024-01-10 14:50:40 +08:00
$mask.find(".goto-change").removeClass('hide');
$mask.show();
}
}
},
error (err) {
console.log(err);
}
})
},
eventRegister: function () {
$('.button-submit').on('click', function () {
var name = $('.name').val();
var personId = $('.person-id').val();
2024-01-10 18:45:21 +08:00
var phone = `${$('.phone').val()}`;
2024-01-10 14:50:40 +08:00
var identityCode = $('.identity-code').val();
var agree = $('#agree').prop("checked");
if (!agree) {
toastShow("请同意直播协议");
return;
}
if (!name.trim()) {
toastShow("名字不能为空");
return;
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (!personId.trim()) {
toastShow("身份证号不能为空");
return;
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (!phone.trim()) {
toastShow("手机号不能为空");
return;
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (!identityCode.trim()) {
toastShow("验证码不能为空");
return;
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test(personId.trim())) {
toastShow("身份证号不符合规格");
return;
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/).test(phone.trim())) {
toastShow("手机号不符合规格");
return;
}
if (lockBol) {
return;
}
lockBol = true;
2024-01-10 18:45:21 +08:00
var metaInfo = window.getMetaInfo();
2024-01-10 14:50:40 +08:00
var requestParam = {
2024-01-10 18:45:21 +08:00
certType: 0,
code: identityCode,
identityNumber: encryptDes(personId, "1ea53d260ecf11e7b56e00163e046a26"),
2024-01-12 15:17:38 +08:00
metaInfo: JSON.stringify(metaInfo),
phone: encryptDes(86 + phone, "1ea53d260ecf11e7b56e00163e046a26"),
returnUrl: urlPrefix + `/peko/modules/identity/new.html?uid=${sessionStorage.getItem("uid")}&ticket=${sessionStorage.getItem("ticket")}`,
2024-01-10 14:50:40 +08:00
uid: pubInfo.uid,
username: encryptDes(name, "1ea53d260ecf11e7b56e00163e046a26"),
2024-01-12 15:17:38 +08:00
};
2024-01-10 14:50:40 +08:00
networkRequest({
2024-01-10 18:45:21 +08:00
type: 'post',
url: urlPrefix + '/certification/initFace',
2024-01-10 14:50:40 +08:00
data: requestParam,
success: function (res) {
if (res.code == 200) {
2024-01-10 18:45:21 +08:00
window.location.href = res.data.certifyUrl;
2024-01-10 14:50:40 +08:00
} else {
2024-01-10 18:45:21 +08:00
$mask.addClass("failed");
$mask.find(".text").html("实名认证失败");
$mask.find(".tips").html(res.message);
2024-01-10 14:50:40 +08:00
$mask.show();
lockBol = false;
setTimeout(function () {
$('.status-mask').hide();
}, 4000);
2024-01-10 18:45:21 +08:00
lockBol = false;
2024-01-10 14:50:40 +08:00
}
},
error (err) {
console.log(err);
}
})
})
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
$('.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)
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
var requestParam = {
2024-01-12 15:17:38 +08:00
phone: encryptDes(86 + phone, "1ea53d260ecf11e7b56e00163e046a26"),
2024-01-10 14:50:40 +08:00
uid: pubInfo.uid,
ticket: pubInfo.ticket
};
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
if (browser.android) {
requestParam.deviceInfo = JSON.stringify({
deviceId: pubInfo.deviceId
});
}
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
networkRequest({
type: 'post',
url: urlPrefix + '/certification/send/code',
data: requestParam,
success: function (res) {
if (res.code == 200) {
toastShow('发送成功');
} else {
toastShow(res.message);
}
},
error (err) {
console.log(err);
}
})
})
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
// 点击我要修改
$('.goto-change').on('click', function () {
$mask.hide();
$('.layer-box-2').show();
})
2022-09-08 18:22:18 +08:00
2024-01-10 14:50:40 +08:00
// 点击关闭弹层
$('.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();
2022-09-08 18:22:18 +08:00
});
2024-01-10 14:50:40 +08:00
function toastShow (text) {
$toast.html(text);
$toast.show();
setTimeout(function () {
$toast.hide();
}, 2000);
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
function getMessage (key, value) {
pubInfo[key] = value;
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
function renderByStatus (status) {
$mask.attr('class', 'status-mask');
console.log("开始回调," + "状态为" + status);
2024-01-10 18:45:21 +08:00
2024-01-10 14:50:40 +08:00
networkRequest({
type: 'post',
url: urlPrefix + '/certification/notify',
data: {
uid: pubInfo.uid,
ticket: pubInfo.ticket,
token: pubInfo.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);
}
}
},
error (err) {
console.log(err);
2022-09-08 18:22:18 +08:00
}
2024-01-10 14:50:40 +08:00
})
console.log('status', status);
2022-09-08 18:22:18 +08:00
}
//DES加密
const encryptDes = (message, key) => {
2024-01-10 14:50:40 +08:00
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();
2022-09-08 18:22:18 +08:00
}
$('.status-mask').click(function () {
if (goToPage) {
window.location.href = urlPrefix + '/peko/modules/h5Income/withdrawal.html'
} else {
$('.status-mask').hide();
}
})