Нет описания

newinviteWeixin.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. var qs=parseQueryString(location.href);
  2. var code_type=1;//短信验证码为1,语音验证码是2
  3. var countDown = '',count_down = '';
  4. var myreg = /^[0-9]{11}$/;
  5. var ttl="",uid="",token="",source = '',user_id = '';
  6. $().ready(function(){
  7. getSignPackage();//过微信审核用
  8. if(qs.user_id){user_id = qs.user_id}
  9. if(qs.source){source = qs.source}
  10. })
  11. // 点击语音验证码
  12. $(".notice span").on("click",function(){
  13. console.log($(".check").attr("disabled"))
  14. if(!myreg.test($("#text").val())) {
  15. showMsg('请正确填写手机号');
  16. }else if ($(".check").attr("disabled") == 'disabled'){
  17. //短信验证码发送中
  18. showMsg('短信验证码已发送,请稍后尝试语音验证码')
  19. }else{
  20. // 发送语音验证码
  21. sendCode(2)
  22. $(".notice").hide();
  23. }
  24. })
  25. // 发送验证码
  26. $(".check").on("click",function(){
  27. if (!myreg.test($("#text").val())) {
  28. //手机号码未填写及填写不正确
  29. showMsg('请正确填写手机号')
  30. return;
  31. }else {
  32. // $(".notice").show();
  33. // 默认发送短信验证码
  34. sendCode(1)
  35. }
  36. })
  37. function sendCode(type) {
  38. var ttl=new Date().getTime();
  39. var arr=["phone="+$("#text").val(),"code_type="+type,"send_type=1","ttl="+ttl].sort()
  40. var sign=arr.join("&")
  41. $.ajax({
  42. type:"post",
  43. url:"/user/sendCode",
  44. dataType:'json',
  45. headers:{
  46. source:source
  47. },
  48. data:{
  49. // channel_id:source,
  50. phone:$("#text").val(),
  51. code_type:type,//1是短信验证码,2是语音验证码
  52. application_type:2,//2为信贷端
  53. send_type:1,//动态登录
  54. ttl:ttl,
  55. sign:hex_md5(sign+"cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL")
  56. },
  57. success: function (res){
  58. if(res && res.errno == 0){
  59. countDown = res.rst.wait_time;
  60. count_down = countDown;
  61. $(".check").html(count_down+"s");
  62. count_down = count_down-1;
  63. $(".check").attr("disabled","true")
  64. var time = setInterval(function () {
  65. $(".check").html(count_down+"s");
  66. count_down--;
  67. if(count_down < 0){
  68. $(".check").removeAttr("disabled")
  69. .html('获取验证码')
  70. if(type == 2){
  71. //语音验证码
  72. $(".notice").show();
  73. }
  74. clearInterval(time);
  75. count_down = countDown;
  76. }
  77. },1000)
  78. }else{
  79. showMsg(res.err)
  80. $(".notice").show();
  81. }
  82. }
  83. });
  84. }
  85. $(".button").on("click",function(){
  86. if (!myreg.test($("#text").val())) {
  87. //手机号码未填写及填写不正确
  88. showMsg('请正确填写手机号')
  89. return;
  90. }else if(!$("#text").val()||!$("#code").val()){
  91. if (!myreg.test($("#text").val())) {
  92. //手机号码未填写及填写不正确
  93. showMsg('请正确填写手机号')
  94. return;
  95. }else {
  96. showMsg("验证码不能为空")
  97. return;
  98. }
  99. }else {
  100. $(".loading").show();
  101. $.ajax({
  102. url:"/user/h5Login",
  103. type:"post",
  104. dataType:"json",
  105. data:{
  106. phone:$("#text").val(),
  107. code:$("#code").val(),
  108. user_id: user_id
  109. },
  110. headers:{
  111. source:source
  112. },
  113. success:function(res) {
  114. $(".loading").hide();
  115. console.log(res)
  116. if(res&&res.errno==0) {
  117. window.location.href = '../inviteWeixinSuccess.html?v=1'
  118. }else if(res.errno == 1013){
  119. window.location.href = '../inviteWeixinSuccess.html?v=1'
  120. }else{
  121. showMsg(res.rst.msg)
  122. }
  123. },
  124. error:function(err) {
  125. $(".loading").hide();
  126. showMsg("网络错误,请稍后再试")
  127. }
  128. })
  129. }
  130. })
  131. // 埋点
  132. function clickRecord(eventId,eventName){
  133. $.ajax({
  134. url:"/user/clickRecord",
  135. type:"post",
  136. dataType:"json",
  137. data:{
  138. event_id:eventId,
  139. event_name:eventName,
  140. channel_id:source?source:1001
  141. },
  142. success:function(res) {
  143. }
  144. })
  145. }
  146. // 微信过审用
  147. function getSignPackage () {
  148. //过微信审核用
  149. var _this = this;
  150. $.ajax({
  151. url:'/user/jsonConfig',
  152. type:'get',
  153. data:{
  154. url:location.href
  155. },
  156. success: function (res) {
  157. console.log(res)
  158. wexinPay(location.href,res.rst,function() {
  159. // 分享成功
  160. showMsg("分享成功")
  161. },function() {
  162. //分享失败
  163. showMsg("分享失败")
  164. },function() {
  165. //微信审核为通过
  166. })
  167. }
  168. })
  169. }
  170. // 展示错误提示信息
  171. function showMsg(msg) {
  172. $(".alert-info").show();
  173. $(".alert-info p").text(msg);
  174. setTimeout(function() {
  175. $(".alert-info").hide();
  176. }, 1000);
  177. }
  178. //获取地址栏参数
  179. function parseQueryString(url) {
  180. var urlObj = {};
  181. var reg = /([^?=&]+)=([^?=&]+)/g;
  182. url.replace(reg, function($0, $1, $2) {
  183. urlObj[$1] = decodeURIComponent($2);
  184. })
  185. return urlObj;
  186. }