Ei kuvausta

newinviteApp.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. var user_id,token,source = '0';
  2. var qs = parseQueryString(location.href);
  3. var source=qs.source?qs.source:"";
  4. var version=qs.version?qs.version:"";
  5. $().ready(function(){
  6. getTokenAddUserIdEvent();//获取token 等信息
  7. })
  8. $('.button').on('click',function (event) {
  9. event.stopPropagation();//阻止事件冒泡
  10. $(".alert").toggle();
  11. //点击空白处,下拉框隐藏-------开始
  12. var tag = $(this).siblings('.alert');
  13. var flag = true;
  14. $(document).bind("click",function(e){//点击空白处,设置的弹框消失
  15. var target = $(e.target);
  16. if(target[0]!=tag[0] && flag == true){
  17. $(tag).hide();
  18. flag = false;
  19. }
  20. });
  21. });
  22. $(".title").on("click",function(){
  23. window.location.href="inviteDetail.html?token="+token+"&source="+source+"&version="+version
  24. })
  25. $(".weixin").on("click",function(){
  26. var param = {
  27. "shareImageUrl": "https://credit-loan.oss-cn-beijing.aliyuncs.com/Uploads/logo/60%403x.png",
  28. "shareTitle": "信贷经理线上获客神器",
  29. "shareDescirpt": "真实一手好单,时时推送,边抢边赚钱,邀好友免费抢单~",
  30. "shareUrl": getLocation()+"inviteWeixin.html?user_id="+user_id+'&source='+source+'&version='+version,//详情链接
  31. "shareType": 1 //1:微信好友 2:朋友圈
  32. }
  33. param = JSON.stringify(param);
  34. try {
  35. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  36. window.webkit.messageHandlers.shareWithWechatSession.postMessage(param);
  37. }
  38. if (navigator.userAgent.match(/android/i)) {
  39. obj4H5.shareWithWechatSession(param);
  40. }
  41. } catch (error) {
  42. console.log("微信share")
  43. }
  44. })
  45. $(".quan").on("click",function(){
  46. var param = {
  47. "shareImageUrl": "https://credit-loan.oss-cn-beijing.aliyuncs.com/Uploads/logo/60%403x.png",
  48. "shareTitle": "信贷经理线上获客神器",
  49. "shareDescirpt": "真实一手好单,时时推送,边抢边赚钱,邀好友免费抢单~",
  50. "shareUrl": getLocation()+"inviteWeixin.html?user_id="+user_id+'&source='+source+'&version='+version,//详情链接
  51. "shareType": 1 //1:微信好友 2:朋友圈
  52. }
  53. console.log(param.shareUrl)
  54. param = JSON.stringify(param);
  55. try {
  56. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  57. window.webkit.messageHandlers.shareWithWechatTimeline.postMessage(param);
  58. }
  59. if (navigator.userAgent.match(/android/i)) {
  60. obj4H5.shareWithWechatTimeline(param);
  61. }
  62. } catch (error) {
  63. console.log("朋友圈share")
  64. }
  65. })
  66. $(".qqShare").on("click",function(){
  67. console.log("QQQ");
  68. var param = {
  69. "shareImageUrl": "https://credit-loan.oss-cn-beijing.aliyuncs.com/Uploads/logo/60%403x.png",
  70. "shareTitle": "信贷经理线上获客神器",
  71. "shareDescirpt": "真实一手好单,时时推送,边抢边赚钱,邀好友免费抢单~",
  72. "shareUrl": getLocation()+"inviteWeixin.html?user_id="+user_id+'&source='+source+'&version='+version,//详情链接
  73. "shareType": 1 //1:微信好友 2:朋友圈
  74. }
  75. console.log(param.shareUrl)
  76. param = JSON.stringify(param);
  77. try {
  78. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  79. window.webkit.messageHandlers.shareWithWQQTimeline.postMessage(param);
  80. }
  81. if (navigator.userAgent.match(/android/i)) {
  82. obj4H5.shareWithWQQTimeline(param);
  83. }
  84. } catch (error) {
  85. console.log("qq share")
  86. }
  87. })
  88. $(".copy").on("click",function(){
  89. console.log("copy");
  90. copyPassword();
  91. })
  92. // 获取token
  93. function getTokenAddUserIdEvent () {
  94. //获取token 和 user_id
  95. var param = '{"js_callback" : "getTokenAddUserId"}';
  96. try{
  97. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  98. window.webkit.messageHandlers.app_h5_getTokenAndUserid.postMessage(param);
  99. }
  100. if(navigator.userAgent.match(/android/i)){
  101. obj4H5.app_h5_getTokenAndUserid(param);
  102. }
  103. }catch(e){
  104. console.log("兼容");
  105. // token = '5c7e767d445a81276a49bf346ae170bb'
  106. // user_id = '6'
  107. // inviteInformation();//获得的金币数量
  108. // console.log(user_id)
  109. // $(".copyTarget").text(getLocation()+"inviteWeixin.html?user_id="+user_id+'&source='+source+'&version='+version)
  110. }
  111. }
  112. function getTokenAddUserId (data) {//app token 回调
  113. var dataes = JSON.parse(data)
  114. token = dataes.token;
  115. user_id = dataes.user_id;
  116. // if(dataes.source){source = dataes.source}
  117. inviteInformation();//获得的金币数量
  118. $(".copyTarget").text(getLocation()+"inviteWeixin.html?user_id="+user_id+'&source='+source+'&version='+version)
  119. }
  120. function inviteInformation () {
  121. //获取邀请好友数量以及获得的金币数量
  122. $.ajax({
  123. url:'/user/inviteInformation',
  124. type:'get',
  125. dataType:'json',
  126. headers:{
  127. token:token,
  128. version:version,
  129. source:source
  130. },
  131. success: function (res){
  132. if(res && res.errno == 0){
  133. // 认证人数=>有效人数
  134. $("#inviteNum").html(res.rst.auth_num?res.rst.auth_num:0);
  135. $("#inviteGold").html(res.rst.invite_gold?res.rst.invite_gold:0);
  136. }
  137. },
  138. error: function (err){
  139. showMsg(res.err)
  140. console.log("error")
  141. }
  142. })
  143. }
  144. // 获取上级地址
  145. function getLocation() {
  146. var upper=window.location.href.split("/")[window.location.href.split("/").length-1]
  147. return window.location.href.replace(upper,"");
  148. }
  149. //获取地址栏参数
  150. function parseQueryString(url) {
  151. var urlObj = {};
  152. var reg = /([^?=&]+)=([^?=&]+)/g;
  153. url.replace(reg, function($0, $1, $2) {
  154. urlObj[$1] = decodeURIComponent($2);
  155. })
  156. return urlObj;
  157. }
  158. // 复制淘口令
  159. function copyPassword() {
  160. var data=$(".copyTarget").text()
  161. copy_2.innerHTML = data;
  162. copy_1.value = data;
  163. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  164. //区分iPhone设备
  165. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  166. var Url2=document.getElementById("copy_2");//要复制文字的节点
  167. var range = document.createRange();
  168. // 选中需要复制的节点
  169. range.selectNode(Url2);
  170. // 执行选中元素
  171. window.getSelection().addRange(range);
  172. // 执行 copy 操作
  173. var successful = document.execCommand('copy');
  174. // 移除选中的元素
  175. window.getSelection().removeAllRanges();
  176. }else{
  177. var Url2=document.getElementById("copy_1");//要复制文字的节点
  178. Url2.select(); // 选择对象
  179. document.execCommand("Copy"); // 执行浏览器复制命令
  180. }
  181. showMsg("复制成功")
  182. }
  183. // 展示错误提示信息
  184. function showMsg(msg) {
  185. $(".alert-info").show();
  186. $(".alert-info p").text(msg);
  187. setTimeout(function() {
  188. $(".alert-info").hide();
  189. }, 1000);
  190. }