uni-app微信公众号授权问题

tech2025-11-25  0

uni-app微信公众号授权问题

onLaunch: function() { var that= this console.log('App Launch') that.ScanAudio(); if(!uni.getStorageSync('strs')){ uni.setStorageSync('strs',GetRequest('strs')) console.log('333:'+uni.getStorageSync('strs')) }else{ var code = getUrlParam("code"); console.log('444:'+code) } //判断code是否存在 if (code) { //alert(code); //此处应当使用code获取用户openid及登录信息 uni.request({ url: 'http://csdn.cn/api/v1.login/init', header: { 'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息 }, method: 'POST', data: { code:code, uuid:uni.getStorageSync('strs') }, success: res => { console.log(res) if(res.data.code==200){ uni.setStorageSync('token',res.data.token) }else{ uni.showToast({ title:res.data.msg, duration:1500, icon:'none' }) } }, }); }else { // uni.request({ url: 'http://csdn.cn/api/v1.login/code', header: { 'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息 }, method: 'POST', data: { }, success: res => { console.log(res); setTimeout(function(){ window.location.href = res.data.url; },1500) }, }); } function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } function GetRequest(strs) { var urls = location.search; //获取url中"?"符后的字串 console.log('111:'+urls) var theRequest = new Object(); if (urls.indexOf("?") != -1) { var str = urls.substr(1); if(str.indexOf("=") != -1){ var strs = str.substr(5,26); } return strs } } }

创作不易,多多支持!

最新回复(0)