Commit 812ab945 authored by 崔勇哲's avatar 崔勇哲

修改以兼容队长端api接口

parent a88b7965
import { Base } from './utils/base.js';
const base = new Base()
App({ App({
onLaunch: function () { onLaunch: function () {
this.isReload() // 小程序是否有新版本 this.isReload() // 小程序是否有新版本
this.getToken() // 获取token this.getSessionKey() // 获取token
}, },
// 小程序是否有新版本 // 小程序是否有新版本
isReload: function () { isReload: function () {
...@@ -59,62 +61,58 @@ App({ ...@@ -59,62 +61,58 @@ App({
codeChangeToken(code, cb) { codeChangeToken(code, cb) {
// 发起网络请求 // 发起网络请求
let that = this let that = this
wx.request({ let params = {
url: 'https://openapi.xueyoubangedu.com/request/allrequest',
data: { data: {
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/getsessionkey', url: 'getsessionkey',
code: code code: code
}, },
method: 'GET', callback: (data) => {
success: function (res) { try {
if (res.data.meta.code === 200) { wx.setStorageSync('token', data.token)
try { } catch (e) {
wx.setStorageSync('token', res.data.data.token) console.log('token缓存失败')
} catch (e) {
console.log('token缓存失败')
}
that.globalData.token = res.data.data.token
typeof cb == 'function' && cb()
} else {
console.log(res)
} }
that.globalData.token = data.token
typeof cb == 'function' && cb()
} }
}) }
base.newRequest(params)
}, },
// 保存用户信息 // 保存用户信息
saveUserInfo: function (info, cb) { saveUserInfo: function (info, cb) {
let that = this let that = this
wx.checkSession({ wx.checkSession({
success() { success() {
wx.request({ let params = {
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/saveinfo',
data: { data: {
url: 'saveinfo',
encryptedData: encodeURIComponent(info.encryptedData), encryptedData: encodeURIComponent(info.encryptedData),
iv: encodeURIComponent(info.iv), iv: encodeURIComponent(info.iv),
token: wx.getStorageSync('token'), token: wx.getStorageSync('token')
}, },
method: 'POST', type: 'POST',
success: function (res) { callback: data => {
if (res.data.meta.code == 200) { // if (res.data.meta.code == 200) {
wx.showToast({ wx.showToast({
title: '已授权', title: '已授权',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
that.globalData.userInfo = res.data.data; that.globalData.userInfo = data;
wx.setStorageSync('userInfo', res.data.data) wx.setStorageSync('userInfo', data)
} else { // }
wx.showToast({ // else {
title: res.data.meta.message, // wx.showToast({
icon: 'none', // title: res.data.meta.message,
duration: 1000 // icon: 'none',
}) // duration: 1000
} // })
// }
typeof cb == 'function' && cb() typeof cb == 'function' && cb()
}, }
fail: function () { } }
}) base.newRequest(params)
}, },
fail() { fail() {
// session_key 已经失效,需要重新执行登录流程 // session_key 已经失效,需要重新执行登录流程
......
...@@ -11,8 +11,8 @@ Page({ ...@@ -11,8 +11,8 @@ Page({
getPhoneNumber: function (e) { getPhoneNumber: function (e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
let params = { let params = {
url: 'user/switchPhone',
data: { data: {
url: 'user/switchPhone',
encryptedData: e.detail.encryptedData, encryptedData: e.detail.encryptedData,
iv: e.detail.iv iv: e.detail.iv
}, },
......
// 公共函数库 // 公共函数库
const app = getApp()
class Base { class Base {
constructor() { constructor() {
// this.baseUrl = 'https://wandoutiyu.xueyoubangedu.com/api/' //线上接口 // this.baseUrl = 'https://wandoutiyu.xueyoubangedu.com/api/' //线上接口
this.baseUrl = 'https://wandoutiyu.test.xueyoubangedu.com/api/' //测试接口 this.baseUrl = 'https://wandoutiyu.test.xueyoubangedu.com/api/' //测试接口
} }
newRequest(params, flag = false, tips = true) { newRequest(params, flag = false, tips = true) {
let that = this let that = this
if (!params.type) { if (!params.type) {
params.type = 'GET' params.type = 'GET'
} }
var cur_url = that.baseUrl + params.url var cur_url = that.baseUrl + params.data.url
// if (flag) { // if (flag) {
// params.url = params.url; // params.url = params.url;
// } else { // } else {
...@@ -21,7 +20,8 @@ class Base { ...@@ -21,7 +20,8 @@ class Base {
data: params.data, data: params.data,
method: params.type, method: params.type,
header: { header: {
'token': wx.getStorageSync('token') 'token': wx.getStorageSync('token'),
'app': 'coach'
}, },
success: function (res) { success: function (res) {
console.log(res) console.log(res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment