123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- var userId = 0;
- var flag = true;
- var str=location.href; //取得整个地址栏
- var num=str.indexOf("?");
- str=str.substr(num+1); //str得到?之后的字符串
- var brr=str.split("&");
- for(var i = 0 ; i<brr.length; i++){
- if(brr[i].indexOf('userId') != -1){
- userId = brr[i].split('=')[1];//用户id
- }
- }
- $().ready(function() {
- shareFriendTwo();
- })
- $(".shareMask").click(function(e){
- $(".shareMask").css('display','none')
- })
- $(".weixins").click(function(e){
- e.preventDefault();
- return false
- })
- var jsons = {
- title:'@你,快来瓜分10000个红包!',
- desc:'福利放送!淘宝无门槛购物红包天天领!来看看你的手气~',
- url: BASEURL + '/api/V2/shareRedPacket?user_id=0'
- };
- jsons = JSON.stringify(jsons);
- function shareWeixin () {
- if(navigator.userAgent.indexOf('Android') != -1){
- messageHandlers.shareWithWechatSession(jsons)
- }else{
- window.webkit.messageHandlers.shareWithWechatSession.postMessage(jsons)
- }
- $("#index").css("display","none");
- $("#invitation").css("display","block");
- $(".shareMask").css('display','none')
- }
- function sharePengyouquan () {
- if(navigator.userAgent.indexOf('Android') != -1){
- messageHandlers.shareWithWechatTimeline(jsons)
- }else{
- window.webkit.messageHandlers.shareWithWechatTimeline.postMessage(jsons)
- }
- $("#index").css("display","none");
- $("#invitation").css("display","block");
- $(".shareMask").css('display','none')
- }
- //点击立即分享
- $(".shareHongbao").click(function () {
-
- if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){
- //微信
- $(".shareWechat").css('display','block');
- shareFriend();
- }else{
- //app端
- $(".shareMask").css('display','block');
- shareRedPacket();
- }
- share();
- })
- //带你几取消分享
- $(".cancel").click(function () {
- $(".shareMask").css('display','none');
- $(".shareWechat").css('display','none')
- })
- var num = 0;
- //分享
- function share() {
- //分享统计
- $.ajax({
- type:"post",
- url:"/api/V2/share",
- data:{
- type:1,
- count: num
- },
- dataType:'json',
- success: function (res) {
- var data =res;
- num = data.res.count;
- }
- })
- }
- function shareFriend () {
- //微信sdk分享验证信息
- $.ajax({
- type:"post",
- url:"/api/V2/jsonConfig",
- dataType:"json",
- data:{
- url:location.href
- },
- success: function (res) {
- if(res && res.code == 0){
- wexinPay(BASEURL + '/api/V2/shareRedPacket?user_id=0',res.res,() => {
- // 分享成功
- $("#index").css("display","none");
- $("#invitation").css("display","block");
- $(".shareMask").css('display','none')
- $(".shareWechat").css('display','none')
- },() => {
- showMsg("分享失败")
- flag = false;
- },() => {
- //微信审核为通过
- flag = false;
- })
- }else{
- flag = false;
- }
- if(!flag){
- //分享不成功
- setTimeout(function () {
- $("#index").css("display","none");
- $("#invitation").css("display","block");
- $(".shareMask").css('display','none')
- $(".shareWechat").css('display','none')
- },3000)
- }
- }
- })
- }
- //页面加载就可以去分享
- function shareFriendTwo () {
- //微信sdk分享验证信息
- $.ajax({
- type:"post",
- url:"/api/V2/jsonConfig",
- dataType:"json",
- data:{
- url:location.href
- },
- success: function (res) {
- if(res && res.code == 0){
- wexinPay(BASEURL + '/api/V2/shareRedPacket?user_id=0',res.res,() => {
- // 分享成功
- $("#index").css("display","none");
- $("#invitation").css("display","block");
- $(".shareMask").css('display','none')
- $(".shareWechat").css('display','none')
- },() => {
- showMsg("分享失败")
- },() => {
- //微信审核为通过
- })
- }
- }
- })
- }
- //复制淘口令
- function copyPassword() {
- var data=document.getElementById("taokouling").innerHTML;
- copy_2.innerHTML = data;
- copy_1.value = data;
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- //区分iPhone设备
- window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
- var Url2=document.getElementById("copy_2");//要复制文字的节点
- var range = document.createRange();
- // 选中需要复制的节点
- range.selectNode(Url2);
- // 执行选中元素
- window.getSelection().addRange(range);
- // 执行 copy 操作
- var successful = document.execCommand('copy');
- // 移除选中的元素
- window.getSelection().removeAllRanges();
- }else{
- var Url2=document.getElementById("copy_1");//要复制文字的节点
- Url2.select(); // 选择对象
- document.execCommand("Copy"); // 执行浏览器复制命令
- }
- showMsg("复制成功")
- }
- /**
- * [showMsg 提示各种错误信息,3s后消失]
- */
- function showMsg(msg) {
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- setTimeout(function() {
- msgBox.hide();
- }, 3000);
- }
- //分享用户授权
- function shareRedPacket () {
- $.ajax({
- type:"get",
- url:"/api/V2/shareRedPacket",
- dataType:"json",
- data:{
- 'user_id':userId
- },
- success: function (res) {
- console.log(res)
- }
- })
- }
- $('.shareCopy').click(function () {
- copyPassword()
- })
- //去下载猎豆app
- function downApp () {
- $.ajax({
- type:"get",
- url:"/api/V2/appDownStatistics",
- dataType:'json',
- success: function (res){
- }
- });
- window.location.href="http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou"
- }
|