No Description

inviteWeixin.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 if(!($("#agreement[type='checkbox']").is(':checked'))){
  100. showMsg("请同意用户协议")
  101. return;
  102. }else {
  103. $(".loading").show();
  104. $.ajax({
  105. url:"/user/h5Login",
  106. type:"post",
  107. dataType:"json",
  108. data:{
  109. phone:$("#text").val(),
  110. code:$("#code").val(),
  111. user_id: user_id
  112. },
  113. headers:{
  114. source:source
  115. },
  116. success:function(res) {
  117. $(".loading").hide();
  118. console.log(res)
  119. if(res&&res.errno==0) {
  120. window.location.href = './inviteWeixinSuccess.html'
  121. }else if(res.errno == '1013'){
  122. window.location.href = './inviteWeixinSuccess.html'
  123. }else{
  124. showMsg(res.rst.msg)
  125. }
  126. },
  127. error:function(err) {
  128. $(".loading").hide();
  129. showMsg("网络错误,请稍后再试")
  130. }
  131. })
  132. }
  133. })
  134. function goAgreement () {
  135. //去用户协议页面
  136. window.location.href = './agreement.html'
  137. }
  138. // 埋点
  139. function clickRecord(eventId,eventName){
  140. $.ajax({
  141. url:"/user/clickRecord",
  142. type:"post",
  143. dataType:"json",
  144. data:{
  145. event_id:eventId,
  146. event_name:eventName,
  147. channel_id:source?source:1001
  148. },
  149. success:function(res) {
  150. }
  151. })
  152. }
  153. // 微信过审用
  154. function getSignPackage () {
  155. //过微信审核用
  156. var _this = this;
  157. $.ajax({
  158. url:'/user/jsonConfig',
  159. type:'get',
  160. data:{
  161. url:location.href
  162. },
  163. success: function (res) {
  164. console.log(res)
  165. wexinPay(location.href,res.rst,function() {
  166. // 分享成功
  167. showMsg("分享成功")
  168. },function() {
  169. //分享失败
  170. showMsg("分享失败")
  171. },function() {
  172. //微信审核为通过
  173. })
  174. }
  175. })
  176. }
  177. // 展示错误提示信息
  178. function showMsg(msg) {
  179. $(".alert-info").show();
  180. $(".alert-info p").text(msg);
  181. setTimeout(function() {
  182. $(".alert-info").hide();
  183. }, 1000);
  184. }
  185. //获取地址栏参数
  186. function parseQueryString(url) {
  187. var urlObj = {};
  188. var reg = /([^?=&]+)=([^?=&]+)/g;
  189. url.replace(reg, function($0, $1, $2) {
  190. urlObj[$1] = decodeURIComponent($2);
  191. })
  192. return urlObj;
  193. }