// 请求自己的服务器
wx.request({
// 自己的服务接口地址
url : ‘自己的服务接口地址’,
method : ‘POST’,
header : {‘content-type’:‘application/x-www-form-urlencoded’},
data : {encryptedData: res2.encryptedData, iv: res2.iv, code: code},
success: function (res)
{
console.log(res)
// 4.解密成功后 获取自己服务器返回的结果
if(res.data.code == ‘200’)
{
wx.setStorageSync(‘user[app_key]’, res.data.result.app_key)
wx.setStorageSync(‘user[app_token]’, res.data.result.app_token)
wx.setStorageSync(‘user[paperTypeId]’, ‘201607301639232601224301’)
}else
{
wx.showLoading({
title: ‘网络错误’,
mask:true
})
}
},
fail:function(res)
{
wx.showLoading({
title: ‘系统内部错误’,
mask:true
})
}
})
}
})
}else
{
wx.showModal({
title: ‘提示’,
content: ‘获取用户登录态失败!’+res.errMsg
})
}
}
})
}
}
// 这是index.js的内容
onload
{
wx.showLoading({
title: ‘加载中’,
mask:true
})
// 在这里原本我是打算app.getUserInfo(function(){这里是我的下一步的request请求但是还是不行})
// 因为我需要登录后的用户信息,但是app.getUserInfo和下面的request请求基本上是同时请求的所以获取不到
app.getUserInfo()
var that = this
// 在这里我设置了一个定时器循环多次去执行去判断上一步的函数执行完毕没有
// 但是也不能无限循环,所以要叫一个判断当执行超过多少秒后报一个网络错误
var times = setInterval(function()
{
// 因为一开始缓存当中指定的key为假当为真的时候就说明上一步成功了这时候就可以开始发送下一步的请求了
var search = wx.getStorageSync(‘user[app_key]’)
if(search)
{
var app_key = wx.getStorageSync(‘user[app_key]’) // 用户名
var app_token = wx.getStorageSync(‘user[app_token]’) // 用户token
var paperTypeId = wx.getStorageSync(‘user[paperTypeId]’)// 考试类型
var ptype = wx.getStorageSync(‘ptype’)
wx.request({
url: ‘这是你服务器的网址’,
data:
{
app_key : app_key,
app_token : app_token,
paperTypeId : paperTypeId,
examId : ‘201607271938505071233880’
},
method: ‘GET’,
header: {‘content-type’: ‘application/json’},
success: function(res)
{
if(res.data.status === ‘200’)
{
that.setData({
items:res.data.result
})
// 在这里停止加载的提示框
setTimeout(function(){
结尾
学习html5、css、javascript这些基础知识,学习的渠道很多,就不多说了,例如,一些其他的优秀博客。但是本人觉得看书也很必要,可以节省很多时间,常见的javascript的书,例如:javascript的高级程序设计,是每位前端工程师必不可少的一本书,边看边用,了解js的一些基本知识,基本上很全面了,如果有时间可以读一些,js性能相关的书籍,以及设计者模式,在实践中都会用的到。
高级程序设计,是每位前端工程师必不可少的一本书,边看边用,了解js的一些基本知识,基本上很全面了,如果有时间可以读一些,js性能相关的书籍,以及设计者模式,在实践中都会用的到。