var union_id = 0; var isClickFlag = true;//是否可以点击获取验证码 window.onload = function () { union_id = getURLCode()['union_id'] || 0; if(union_id == 0){ window.location.href='http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou' } writeLogH5({action:'HB-register',channel:'H5',url:window.location.href});//海报手机注册 _czc.push(["_trackEvent",'邀请海报','页面',]); } //获取手机验证码 function getYzm () { var phoneNumber = getIdHtml("phone").value; var ttl = new Date().getTime(); var sign = hex_md5('phone=' + phoneNumber + '&ttl=' + ttl + 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL'); if(phoneNumber.length != 11){ showMsg('请正确输入手机号'); return; } if(!isClickFlag){ return; } axios.post('/api/v2/users/sendCode', { phone: phoneNumber, ttl: ttl, sign: sign, union_id: union_id },{ headers:{ source:6000 } }) .then(function (response) { var res = response.data,wait_time; if (res.errno == 0 && res.rst.success) { wait_time = res.rst.wait_time; var time = setInterval(function () { wait_time--; getIdHtml('yzmButton').innerHTML = wait_time + 's'; isClickFlag = false;//不可获取验证码 if(wait_time == 0){ clearInterval(time); getIdHtml('yzmButton').innerHTML = '获取验证码'; isClickFlag = true;//可以获取验证码 } },1000) }else if(res.errno == 0 && !res.rst.success){ showMsg('请稍后再试哦~') }else{//errno==1011 该手机号已绑定其他微信 showMsg(res.err); } }) .catch(function (error) { showMsg('请稍后再试哦~') }); } //注册事件 function registerEvent () { if(getIdHtml("phone").value.length != 11){ showMsg('请正确输入手机号'); return; } if((getIdHtml('yzm').value).trim().length == 0){ showMsg('请输入手机验证码') return; } //验证注册 axios.post('/api/v2/users/loginCode', { phone: getIdHtml("phone").value, code: getIdHtml('yzm').value, union_id: union_id },{ headers:{ source:6000 } }) .then(function (response) { var res = response.data; if (res.errno == 0) { document.getElementById('registerSuccess').style.visibility='visible'; writeLogH5({action:'HB-success',channel:'H5',url:window.location.href});//手机注册成功 _czc.push(["_trackEvent",'邀请海报','手机注册成功',]); }else if(res.errno == 1001){ showMsg('请稍后再试哦~') }else{ showMsg(res.err); } }) .catch(function (error) { showMsg('请稍后再试哦~') }); } function closeMake () { document.getElementById('registerSuccess').style.visibility='hidden'; } //封装 id标签 function getIdHtml (name){ return document.getElementById(name) } //封装 class标签 function getClassHtml (name){ return document.getElementsByClassName(name)[0] } /** * [showMsg 提示各种错误信息,3s后消失] */ function showMsg(msg) { var msgBox = document.getElementsByClassName('alert-info')[0]; msgBox.getElementsByTagName("p")[0].innerHTML=msg; msgBox.style.display="block"; setTimeout(function() { msgBox.style.display="none"; }, 1000); } //获取地址栏参数 function getURLCode () { var search = location.search.length > 0 ? location.search.substring(1) : '', args = {}, items = search.length ? search.split('&') : [], item = null, name = null, value = null, i = 0, len = items.length, data = ''; for (i = 0; i < len; i++) { item = items[i].split('='); name = decodeURIComponent(item[0]); value = decodeURIComponent(item[1]); if (item.length) {args[name] = value } } return args; } //埋点 function writeLogH5 (data) { axios.post('/api/v2/channel/writeLogH5', data,{ headers:{ source:6000 } }) .then(function (response) { }) .catch(function (error) { }); }