No Description

invitation.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. var userId = 0;
  2. var flag = true;
  3. var str=location.href; //取得整个地址栏
  4. var num=str.indexOf("?");
  5. str=str.substr(num+1); //str得到?之后的字符串
  6. var brr=str.split("&");
  7. for(var i = 0 ; i<brr.length; i++){
  8. if(brr[i].indexOf('userId') != -1){
  9. userId = brr[i].split('=')[1];//用户id
  10. }
  11. }
  12. $().ready(function() {
  13. shareFriendTwo();
  14. })
  15. $(".shareMask").click(function(e){
  16. $(".shareMask").css('display','none')
  17. })
  18. $(".weixins").click(function(e){
  19. e.preventDefault();
  20. return false
  21. })
  22. var jsons = {
  23. title:'@你,快来瓜分10000个红包!',
  24. desc:'福利放送!淘宝无门槛购物红包天天领!来看看你的手气~',
  25. url: BASEURL + '/api/V2/shareRedPacket?user_id=0'
  26. };
  27. jsons = JSON.stringify(jsons);
  28. function shareWeixin () {
  29. if(navigator.userAgent.indexOf('Android') != -1){
  30. messageHandlers.shareWithWechatSession(jsons)
  31. }else{
  32. window.webkit.messageHandlers.shareWithWechatSession.postMessage(jsons)
  33. }
  34. $("#index").css("display","none");
  35. $("#invitation").css("display","block");
  36. $(".shareMask").css('display','none')
  37. }
  38. function sharePengyouquan () {
  39. if(navigator.userAgent.indexOf('Android') != -1){
  40. messageHandlers.shareWithWechatTimeline(jsons)
  41. }else{
  42. window.webkit.messageHandlers.shareWithWechatTimeline.postMessage(jsons)
  43. }
  44. $("#index").css("display","none");
  45. $("#invitation").css("display","block");
  46. $(".shareMask").css('display','none')
  47. }
  48. //点击立即分享
  49. $(".shareHongbao").click(function () {
  50. if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){
  51. //微信
  52. $(".shareWechat").css('display','block');
  53. shareFriend();
  54. }else{
  55. //app端
  56. $(".shareMask").css('display','block');
  57. shareRedPacket();
  58. }
  59. share();
  60. })
  61. //带你几取消分享
  62. $(".cancel").click(function () {
  63. $(".shareMask").css('display','none');
  64. $(".shareWechat").css('display','none')
  65. })
  66. var num = 0;
  67. //分享
  68. function share() {
  69. //分享统计
  70. $.ajax({
  71. type:"post",
  72. url:"/api/V2/share",
  73. data:{
  74. type:1,
  75. count: num
  76. },
  77. dataType:'json',
  78. success: function (res) {
  79. var data =res;
  80. num = data.res.count;
  81. }
  82. })
  83. }
  84. function shareFriend () {
  85. //微信sdk分享验证信息
  86. $.ajax({
  87. type:"post",
  88. url:"/api/V2/jsonConfig",
  89. dataType:"json",
  90. data:{
  91. url:location.href
  92. },
  93. success: function (res) {
  94. if(res && res.code == 0){
  95. wexinPay(BASEURL + '/api/V2/shareRedPacket?user_id=0',res.res,() => {
  96. // 分享成功
  97. $("#index").css("display","none");
  98. $("#invitation").css("display","block");
  99. $(".shareMask").css('display','none')
  100. $(".shareWechat").css('display','none')
  101. },() => {
  102. showMsg("分享失败")
  103. flag = false;
  104. },() => {
  105. //微信审核为通过
  106. flag = false;
  107. })
  108. }else{
  109. flag = false;
  110. }
  111. if(!flag){
  112. //分享不成功
  113. setTimeout(function () {
  114. $("#index").css("display","none");
  115. $("#invitation").css("display","block");
  116. $(".shareMask").css('display','none')
  117. $(".shareWechat").css('display','none')
  118. },3000)
  119. }
  120. }
  121. })
  122. }
  123. //页面加载就可以去分享
  124. function shareFriendTwo () {
  125. //微信sdk分享验证信息
  126. $.ajax({
  127. type:"post",
  128. url:"/api/V2/jsonConfig",
  129. dataType:"json",
  130. data:{
  131. url:location.href
  132. },
  133. success: function (res) {
  134. if(res && res.code == 0){
  135. wexinPay(BASEURL + '/api/V2/shareRedPacket?user_id=0',res.res,() => {
  136. // 分享成功
  137. $("#index").css("display","none");
  138. $("#invitation").css("display","block");
  139. $(".shareMask").css('display','none')
  140. $(".shareWechat").css('display','none')
  141. },() => {
  142. showMsg("分享失败")
  143. },() => {
  144. //微信审核为通过
  145. })
  146. }
  147. }
  148. })
  149. }
  150. //复制淘口令
  151. function copyPassword() {
  152. var data=document.getElementById("taokouling").innerHTML;
  153. copy_2.innerHTML = data;
  154. copy_1.value = data;
  155. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  156. //区分iPhone设备
  157. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  158. var Url2=document.getElementById("copy_2");//要复制文字的节点
  159. var range = document.createRange();
  160. // 选中需要复制的节点
  161. range.selectNode(Url2);
  162. // 执行选中元素
  163. window.getSelection().addRange(range);
  164. // 执行 copy 操作
  165. var successful = document.execCommand('copy');
  166. // 移除选中的元素
  167. window.getSelection().removeAllRanges();
  168. }else{
  169. var Url2=document.getElementById("copy_1");//要复制文字的节点
  170. Url2.select(); // 选择对象
  171. document.execCommand("Copy"); // 执行浏览器复制命令
  172. }
  173. showMsg("复制成功")
  174. }
  175. /**
  176. * [showMsg 提示各种错误信息,3s后消失]
  177. */
  178. function showMsg(msg) {
  179. var msgBox = $('.alert-info');
  180. msgBox.children('p').text(msg);
  181. msgBox.show();
  182. setTimeout(function() {
  183. msgBox.hide();
  184. }, 3000);
  185. }
  186. //分享用户授权
  187. function shareRedPacket () {
  188. $.ajax({
  189. type:"get",
  190. url:"/api/V2/shareRedPacket",
  191. dataType:"json",
  192. data:{
  193. 'user_id':userId
  194. },
  195. success: function (res) {
  196. console.log(res)
  197. }
  198. })
  199. }
  200. $('.shareCopy').click(function () {
  201. copyPassword()
  202. })
  203. //去下载猎豆app
  204. function downApp () {
  205. $.ajax({
  206. type:"get",
  207. url:"/api/V2/appDownStatistics",
  208. dataType:'json',
  209. success: function (res){
  210. }
  211. });
  212. window.location.href="http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou"
  213. }