|
@@ -1,5 +1,6 @@
|
|
// app.js
|
|
// app.js
|
|
const {login,getUserInfo} = require('./API/appraise')
|
|
const {login,getUserInfo} = require('./API/appraise')
|
|
|
|
+const {wxLogin} = require('./utils/util')
|
|
|
|
|
|
App({
|
|
App({
|
|
onLaunch() {
|
|
onLaunch() {
|
|
@@ -37,39 +38,24 @@ var infoOption = {
|
|
if(wx.getStorageSync('token') == ''){
|
|
if(wx.getStorageSync('token') == ''){
|
|
// console.log('token不存在');
|
|
// console.log('token不存在');
|
|
// 登录
|
|
// 登录
|
|
- wx.login({
|
|
|
|
- success: (res) => {
|
|
|
|
- //获取用户昵称和头像
|
|
|
|
- //和微信接口服务校验
|
|
|
|
- // console.log("code: "+res.code);
|
|
|
|
- var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
|
|
|
|
- wx.request({
|
|
|
|
- url:url,
|
|
|
|
- success: (res) => {
|
|
|
|
- // console.log(res);
|
|
|
|
- // console.log(res.data.openid);
|
|
|
|
- wx.setStorageSync('vid', res.data.openid);
|
|
|
|
- // console.log(wx.getStorageSync('vid'));
|
|
|
|
- loginOption.data = {
|
|
|
|
- vid: wx.getStorageSync('vid'),
|
|
|
|
- }
|
|
|
|
- // console.log(loginOption.data);
|
|
|
|
- login(loginOption).then(res => {
|
|
|
|
- // console.log(res);
|
|
|
|
- wx.setStorageSync('token', res.data.data.token);
|
|
|
|
- wx.setStorageSync('uid', res.data.data.user_info.uid);
|
|
|
|
- wx.setStorageSync('avatarUrl', res.data.data.user_info.avatar);
|
|
|
|
- wx.setStorageSync('nickName', res.data.data.user_info.name);
|
|
|
|
- }).catch(err => {
|
|
|
|
- // console.log(err);
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: '/pages/register/register',
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ wxLogin().then((res)=>{
|
|
|
|
+ console.log(res);
|
|
|
|
+ loginOption.data = {
|
|
|
|
+ code:res.code
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ login(loginOption).then(res => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ wx.setStorageSync('token', res.data.data.token);
|
|
|
|
+ wx.setStorageSync('uid', res.data.data.user_info.uid);
|
|
|
|
+ wx.setStorageSync('avatarUrl', res.data.data.user_info.avatar);
|
|
|
|
+ wx.setStorageSync('nickName', res.data.data.user_info.name);
|
|
|
|
+ }).catch(err => {
|
|
|
|
+ console.log(err);
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: '/pages/register/register',
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ })
|
|
}else{
|
|
}else{
|
|
getUserInfo(infoOption).then(res => {
|
|
getUserInfo(infoOption).then(res => {
|
|
// console.log(res);
|
|
// console.log(res);
|
|
@@ -80,38 +66,25 @@ var infoOption = {
|
|
wx.setStorageSync('personalSignatrue', res.data.data.sign);
|
|
wx.setStorageSync('personalSignatrue', res.data.data.sign);
|
|
// console.log(wx.getStorageSync('uid'));
|
|
// console.log(wx.getStorageSync('uid'));
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
- // console.log('token已失效,请重新登录');
|
|
|
|
- wx.login({
|
|
|
|
- success: (res) => {
|
|
|
|
- //和微信接口服务校验
|
|
|
|
- // console.log("code: "+res.code);
|
|
|
|
- var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
|
|
|
|
- wx.request({
|
|
|
|
- url:url,
|
|
|
|
- success: (res) => {
|
|
|
|
- // console.log(res);
|
|
|
|
- // console.log(res.data.openid);
|
|
|
|
- wx.setStorageSync('vid', res.data.openid);
|
|
|
|
- // console.log(wx.getStorageSync('vid'));
|
|
|
|
- loginOption.data = {
|
|
|
|
- vid: wx.getStorageSync('vid'),
|
|
|
|
- }
|
|
|
|
- login(loginOption).then(res => {
|
|
|
|
- // console.log(res);
|
|
|
|
- wx.setStorageSync('token', res.data.data.token);
|
|
|
|
- wx.setStorageSync('uid', res.data.data.user_info.uid);
|
|
|
|
- wx.setStorageSync('avatarUrl', res.data.data.user_info.avatar);
|
|
|
|
- wx.setStorageSync('nickName', res.data.data.user_info.name);
|
|
|
|
- }).catch(err => {
|
|
|
|
- // console.log(err);
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: '/pages/register/register',
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ console.log('token已失效,请重新登录');
|
|
|
|
+ wxLogin().then((res)=>{
|
|
|
|
+ console.log(res);
|
|
|
|
+ loginOption.data = {
|
|
|
|
+ code: res.code,
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ login(loginOption).then(res => {
|
|
|
|
+ // console.log(res);
|
|
|
|
+ wx.setStorageSync('token', res.data.data.token);
|
|
|
|
+ wx.setStorageSync('uid', res.data.data.user_info.uid);
|
|
|
|
+ wx.setStorageSync('avatarUrl', res.data.data.user_info.avatar);
|
|
|
|
+ wx.setStorageSync('nickName', res.data.data.user_info.name);
|
|
|
|
+ }).catch(err => {
|
|
|
|
+ // console.log(err);
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: '/pages/register/register',
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
|
|
})
|
|
})
|
|
|
|
|