1(function(){ 2 var origin_url = location.href; 3 var oauth_url = 'https://vx.mcilife.com/weixin/api/oauth/?callback='; 4 5 var $_GET = (function(){ 6 var url = window.document.location.href.toString(); 7 var u = url.split("?"); 8 if(typeof(u[1]) == "string"){ 9 u = u[1].split("&"); 10 var get = {}; 11 for(var i in u){ 12 var j = u[i].split("="); 13 get[j[0]] = j[1]; 14 } 15 return get; 16 } else { 17 return {}; 18 } 19 })(); 20 //localStroage 21 var storage = { 22 read:function(name){ 23 return localStorage.getItem(name); 24 }, 25 write:function(name,value){ 26 localStorage.setItem(name, String(value)); 27 }, 28 rm:function(name){ 29 localStorage.removeItem(name); 30 }, 31 clear:function(){ 32 localStorage.clear(); 33 } 34 } 35 //鐢ㄦ埛 36 var user = { 37 login:function(){ 38 39 if(storage.read('token') === null && !$_GET['token']){ 40 //token鍙傛暟銆佸瓨鍌ㄩ兘涓嶅瓨鍦� 鎺堟潈 41 user.oauth(); 42 }else if($_GET['token'] && storage.read('token') === null){ 43 //token瀛樺湪銆佸瓨鍌ㄤ笉瀛樺湪 鍐欏叆瀛樺偍 璺宠浆 44 storage.write('token',$_GET['token']); 45 user.setInfo();//鑾峰彇鍒皌oken涔嬪悗鏇存柊鐢ㄦ埛淇℃伅 46 location.href = origin_url; 47 }else if(storage.read('token') !== null){ 48 49 } 50 }, 51 oauth:function(){ 52 var url = encodeURIComponent(origin_url); 53 location.href= oauth_url + url; 54 }, 55 setInfo:function(){ 56 if(storage.read('openid') 57 && storage.read('unionid') 58 && storage.read('nickname') 59 && storage.read('headimgurl') 60 && storage.read('isSubscribe')) return false; 61 62 var isApp = getQueryString("isApp"); 63 if(isApp=="10000"||isApp=="10001"){ 64 65 }else if(isApp=="20000"){ 66 67 $.ajax({ 68 url:'https://vx.mcilife.com/weixin/api/getinfo/?token='+storage.read('token'), 69 type:'get', 70 async:false, 71 dataType:'json', 72 success:function(data){ 73 if(data.code == 0){ 74 75 if('openid' in data.data) storage.write('openid',data.data.openid); 76 if('unionid' in data.data) storage.write('unionid',data.data.unionid); 77 if('nickname' in data.data) storage.write('nickname',data.data.nickname); 78 if('headimgurl' in data.data) storage.write('headimgurl',data.data.headimgurl); 79 if('isSubscribe' in data.data) storage.write('isSubscribe',data.data.isSubscribe); 80 81 }else{ 82 user.oauth();//鑾峰彇淇℃伅澶辫触锛岄噸鏂版巿鏉� 83 } 84 } 85 }) 86 } 87 } 88 }; 89 90 if(isApp=="20000"){ 91 user.login(); 92 } 93 94 //授权成功 95 var shareimg = 'http://gcw.mcilife.com/Square/image/mc.jpg';//分享的图片 96 $.ajax({ 97 url : "http://vx.mcilife.com/weixin/jssdk/share/",//分享接口地址 98 type : 'post', 99 data:{url:location.href}, 100 cache: false, 101 dataType : 'json', 102 success : function(data) { 103 console.log(data); 104 wx.config( { 105 appId : data.data.appId,// 必填,公众号的唯一标识 106 timestamp : data.data.timestamp,// 必填,生成签名的时间戳 107 nonceStr : data.data.nonceStr,// 必填,生成签名的随机串 108 signature : data.data.signature,// 必填,签名,见附录1 109 jsApiList : [ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'showOptionMenu' ,'onMenuShareQQ' ,'onMenuShareWeibo' ] 110 // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 111 }); 112 113 wx.ready(function() { 114 wx.showOptionMenu();//打开分享按钮 115 116 //分享到朋友圈 117 wx.onMenuShareTimeline( { 118 title : "微信朋友圈:山屿海广场舞活动",// 分享标题 119 desc: '活动快乐,广场舞......快来参加!!', //描述 120 link : window.location.href,// 分享链接 121 imgUrl : shareimg,// 分享图标 122 success : function(data) { 123 124 $.ajax({ 125 url: 'http://'+setIp+':8080/mcilife-inter/gcw/insertUserVoteNum', 126 type:'post', 127 dataType:'json', 128 cache: false, 129 data:{ 130 userId:userId, 131 num:2, 132 isTime:0 133 }, 134 success: function(data) { 135 }, 136 error: function () { 137 138 } 139 }) 140 141 }, 142 cancel : function() { 143 144 } 145 }); 146 147 //分享到朋友 148 wx.onMenuShareAppMessage( { 149 title : '微信好友:山屿海广场舞活动', 150 desc : '活动快乐,广场舞......快来参加!!', 151 link : window.location.href, 152 imgUrl : shareimg, 153 success : function(data) {// 用户确认分享后执行的回调函数 154 $.ajax({ 155 url: 'http://'+setIp+':8080/mcilife-inter/gcw/insertUserVoteNum', 156 type:'post', 157 dataType:'json', 158 cache: false, 159 data:{ 160 userId:userId, 161 num:2, 162 isTime:0 163 }, 164 success: function(data) { 165 }, 166 error: function () { 167 168 } 169 }) 170 },cancel : function() {} 171 }); 172 173 wx.onMenuShareQQ({ 174 title: 'QQ:山屿海广场舞活动', 175 desc: '活动快乐,广场舞......快来参加!!', 176 link:window.location.href, 177 imgUrl: shareimg, 178 success: function () { 179 $.ajax({ 180 url: 'http://'+setIp+':8080/mcilife-inter/gcw/insertUserVoteNum', 181 type:'post', 182 dataType:'json', 183 cache: false, 184 data:{ 185 userId:userId, 186 num:2, 187 isTime:0 188 }, 189 success: function(data) { 190 }, 191 error: function () { 192 193 } 194 }) 195 }, 196 cancel: function () { 197 198 } 199 }); 200 201 wx.onMenuShareWeibo({ 202 title: '微博:山屿海广场舞活动', 203 desc: '活动快乐,广场舞......快来参加!!', 204 link: window.location.href, 205 imgUrl: shareimg, 206 success: function () { 207 $.ajax({ 208 url: 'http://'+setIp+':8080/mcilife-inter/gcw/insertUserVoteNum', 209 type:'post', 210 dataType:'json', 211 cache: false, 212 data:{ 213 userId:userId, 214 num:2, 215 isTime:0 216 }, 217 success: function(data) { 218 }, 219 error: function () { 220 221 } 222 }) 223 }, 224 cancel: function () { 225 226 } 227 }); 228 }) 229 } 230 }) 231 232})()
JS授权
Wesley13
2021-10-11
1232 0 0
点赞
收藏
评论区
加载中...