var qs=parseQueryString(location.href); var code_type=1;//短信验证码为1,语音验证码是2 var countDown = '',count_down = ''; var myreg = /^[0-9]{11}$/; var ttl="",uid="",token="",source = '',user_id = ''; $().ready(function(){ getSignPackage();//过微信审核用 if(qs.user_id){user_id = qs.user_id} if(qs.source){source = qs.source} }) // 点击语音验证码 // $(".notice span").on("click",function(){ // console.log($(".check").attr("disabled")) // if(!myreg.test($("#text").val())) { // showMsg('请正确填写手机号'); // }else if ($(".check").attr("disabled") == 'disabled'){ // //短信验证码发送中 // showMsg('短信验证码已发送,请稍后尝试语音验证码') // }else{ // // 发送语音验证码 // sendCode(2) // $(".notice").hide(); // } // }) // 发送验证码 $(".check").on("click",function(){ if (!myreg.test($("#text").val())) { //手机号码未填写及填写不正确 showMsg('请正确填写手机号') return; }else { // $(".notice").show(); // 默认发送短信验证码 sendCode(1) } }) function sendCode(type) { var ttl=new Date().getTime(); var arr=["phone="+$("#text").val(),"code_type="+type,"send_type=1","ttl="+ttl].sort() var sign=arr.join("&") $.ajax({ type:"post", url:"/user/sendCode", dataType:'json', headers:{ source:source }, data:{ // channel_id:source, phone:$("#text").val(), code_type:type,//1是短信验证码,2是语音验证码 application_type:2,//2为信贷端 send_type:1,//动态登录 ttl:ttl, sign:hex_md5(sign+"cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL") }, success: function (res){ if(res && res.errno == 0){ countDown = res.rst.wait_time; count_down = countDown; $(".check").html(count_down+"s"); count_down = count_down-1; $(".check").attr("disabled","true") var time = setInterval(function () { $(".check").html(count_down+"s"); count_down--; if(count_down < 0){ $(".check").removeAttr("disabled") .html('获取验证码') // if(type == 2){ // //语音验证码 // $(".notice").show(); // } clearInterval(time); count_down = countDown; } },1000) }else{ showMsg(res.err) // $(".notice").show(); } } }); } $(".button").on("click",function(){ if (!myreg.test($("#text").val())) { //手机号码未填写及填写不正确 showMsg('请正确填写手机号') return; }else if(!$("#text").val()||!$("#code").val()){ if (!myreg.test($("#text").val())) { //手机号码未填写及填写不正确 showMsg('请正确填写手机号') return; }else { showMsg("验证码不能为空") return; } }else if(!($("#agreement[type='checkbox']").is(':checked'))){ showMsg("请同意用户协议") return; }else { $(".loading").show(); $.ajax({ url:"/user/h5Login", type:"post", dataType:"json", data:{ phone:$("#text").val(), code:$("#code").val(), user_id: user_id }, headers:{ source:source }, success:function(res) { $(".loading").hide(); console.log(res) if(res&&res.errno==0) { window.location.href = './inviteWeixinSuccess.html' }else if(res.errno == '1013'){ window.location.href = './inviteWeixinSuccess.html' }else{ showMsg(res.rst.msg) } }, error:function(err) { $(".loading").hide(); showMsg("网络错误,请稍后再试") } }) } }) function goAgreement () { //去用户协议页面 window.location.href = './agreement.html' } // 埋点 function clickRecord(eventId,eventName){ $.ajax({ url:"/user/clickRecord", type:"post", dataType:"json", data:{ event_id:eventId, event_name:eventName, channel_id:source?source:1001 }, success:function(res) { } }) } // 微信过审用 function getSignPackage () { //过微信审核用 var _this = this; $.ajax({ url:'/user/jsonConfig', type:'get', data:{ url:location.href }, success: function (res) { console.log(res) wexinPay(location.href,res.rst,function() { // 分享成功 showMsg("分享成功") },function() { //分享失败 showMsg("分享失败") },function() { //微信审核为通过 }) } }) } // 展示错误提示信息 function showMsg(msg) { $(".alert-info").show(); $(".alert-info p").text(msg); setTimeout(function() { $(".alert-info").hide(); }, 1000); } //获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, function($0, $1, $2) { urlObj[$1] = decodeURIComponent($2); }) return urlObj; }