123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- 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 {
- $(".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?v=1'
- }else if(res.errno == 1013){
- window.location.href = '../inviteWeixinSuccess.html?v=1'
- }else{
- showMsg(res.rst.msg)
- }
- },
- error:function(err) {
- $(".loading").hide();
- showMsg("网络错误,请稍后再试")
- }
- })
- }
- })
- // 埋点
- 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;
- }
|