我正在看别人的代码,就是这个,我自己还是不是很明白,就是最后得到的是什么格式的返回数据
这个网址得到的数据
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
// var logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now())
// wx.setStorageSync('logs', logs)
this.getUserInfo();
},
getUserInfo:function(){
var that = this
if (wx.getStorageSync("userInfo")){
}else{
//调用登录接口
wx.login({
success: function (res1) {
var code = res1.code;
wx.getUserInfo({
success: function (res1) {
console.log(res1)
that.globalData.userInfo = res1.userInfo
wx.request({
url: 'https://api.wnschool.cn/user-save',
data: {
"code":code,
"clientJSONString": JSON.stringify(res1.userInfo)
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method:'POST',
success:function(res){
console.log(res)
if(res.data!="code is null"){
console.log(res);
that.globalData.userInfo.openid = res.data.openid;
that.globalData.userInfo.id = res.data.id;
wx.setStorageSync('userInfo', res.data);
}
}
})
}
})
}
})
}
},
globalData:{
userInfo:null
}
})
这是那段代码
然后完整的在github
目前我的问题是:
1.这个代码得到数据是什么格式的呢?
2.这个网址是什么?是我要自己申请的吗?
3.如果我需要后端的话因该做什么呢?
得到的是json,你java的话,用httpclient调用
第一个问题你得到是json,得到的数据应该是用户保存的数据。,第二个需要你自己申请,第三后端的话我真不知道
后端你就需要啥写啥,爱写啥写啥