JS授权

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})()
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )