1、app.json配置信息是怎样的?
1 { 2 "pages":[ 3 "pages/页面1/页面1", 4 "pages/页面2/页面2", 5 ], 6 "window":{ 7 "backgroundTextStyle":"light",//文本背景样式 8 "navigationBarBackgroundColor": "White",//导航背景颜色 9 "navigationBarTitleText": "WeChat",//导航背景标题 10 "navigationBarTextStyle":"black",//导航背景文本样式 11 "enablePullDownRefresh": true//是否开启下拉刷新 12 }, 13 "tabBar": {//底部菜单栏最多5个 14 "color": "#000", 15 "selectedColor": "#000000", 16 "backgroundColor": "#efefef", 17 "borderStyle": "White", 18 "list": [{ 19 "pagePath": "pages/shopping/shopping", 20 "iconPath": "images/scshop_i.png", 21 "selectedIconPath": "images/scshop.png", 22 "text": "商城" 23 },{ 24 "pagePath": "pages/shopcar/shopcar", 25 "iconPath": "images/shopca.png", 26 "selectedIconPath": "images/shopcar.png", 27 "text": "购物车" 28 },{ 29 "pagePath": "pages/index/index", 30 "iconPath": "images/latest.png", 31 "selectedIconPath": "images/latest_on.png", 32 "text": "我的" 33 }] 34 }, 35 "networkTimeout": {//网络请求时间 36 "request": 20000, 37 "connectSocket": 20000, 38 "uploadFile": 20000, 39 "downloadFile": 20000 40 }, 41 "debug":true 42 }
2、如何获取用户的身份信息?
1 var appUserinfo; 2 var openid = ''; 3 var sessionkey = ''; 4 var encryptedData = ''; 5 var iv = ''; 6 App({ 7 //用户登录 8 getUserInfo: function (callback) { 9 //调用登录接口 10 var retuser = {}; 11 var that = this; 12 wx.showLoading({ title: "加载中..." }); 13 wx.login({ 14 success: function (res) { 15 var code = res.code; 16 if (code) { 17 //读取会员信息 18 wx.request({ 19 url: "https"+aspx,// 通过获取code来换取session_key 20 data: { 21 code: code, 22 }, 23 success: function (res) {//res返回值获得session_key&openid 24 console.log(res) 25 var retdata = res.data.data; 26 openid = retdata.openid, 27 sessionkey = retdata.session_key; 28 //设置微信用户信息 29 wx.getUserInfo({ 30 success: function (res) { 31 encryptedData = res.encryptedData; 32 iv = res.iv; 33 appUserinfo = res.userInfo 34 wx.request({ 35 url: "https"+aspx,//通过session_key来换取公众号信息 36 data: { 37 openid:openid, 38 unionid:encryptedData,//解析unionid(md5加密&解密获得) 39 sessionkey:sessionkey, 40 iv:iv, 41 appid: 'wx758e9825590dc405' 42 }, 43 dataType: "json", 44 success: function (ret) { 45 wx.hideLoading(); 46 var retdata = ret.data; 47 for (var key in retdata) { 48 retuser[key] = retdata[key]; 49 } 50 retuser.littleid = retuser.uid;//换取公众平台用户的id信息 51 retuser.openid=openid; 52 callback && callback(retuser); 53 } 54 }); 55 }, 56 fail: function (res) { 57 var that = this 58 console.log(res) 59 /* 60 wx.redirectTo({ 61 url: '/pages/error/error?error=请同意获得微信用户信息' 62 }) 63 */if(res){//res返回值来检查用户授权信息&重新授权 64 wx.showModal({ 65 title: '警告', 66 content: '若不授权微信登陆,您将无法使用商城部分功能,点击重新获取授权', 67 success: function () { 68 wx.openSetting({ 69 success: function (res) { 70 if (!res.authSetting["scope.userInfo"] || !res.authSetting["scope.userLocation"]) { 71 wx.getUserInfo({}) 72 } 73 } 74 }) 75 } 76 }) 77 } 78 } 79 }) 80 } 81 }); 82 } 83 } 84 }) 85 } 86 })
以上就是我在初学小程序时所走的坑吧,分享给各位,希望对大家有所帮助