|
@@ -1,11 +1,15 @@
|
|
-
|
|
|
|
|
|
+import util from './util.js'
|
|
class request {
|
|
class request {
|
|
|
|
|
|
-// static BASE_URL = 'http://www.hsay.com:81/'
|
|
|
|
- static BASE_URL = 'https://oapi.shpr.top/'//pre环境的
|
|
|
|
|
|
+ static BASE_URL = 'http://www.lx.com:81/'
|
|
|
|
+// static BASE_URL = 'https://oapi.shpr.top/'//pre环境的
|
|
|
|
+// @todo需要修改正式的域名
|
|
|
|
+
|
|
static HEAD = {
|
|
static HEAD = {
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
- "token":'',
|
|
|
|
|
|
+ "SIGN":'',
|
|
|
|
+ "NONCE":'',
|
|
|
|
+ "TIMESTAMP":'',
|
|
}
|
|
}
|
|
static constructor() {
|
|
static constructor() {
|
|
|
|
|
|
@@ -21,13 +25,9 @@ class request {
|
|
/**
|
|
/**
|
|
* GET类型的网络请求
|
|
* GET类型的网络请求
|
|
*/
|
|
*/
|
|
- static getRequest(url, data, header = this.HEAD ) {
|
|
|
|
-
|
|
|
|
- const token = wx.getStorageSync('token')
|
|
|
|
- if (token) {
|
|
|
|
- header.token = token
|
|
|
|
- }
|
|
|
|
- return this.requestAll(url, data, header, 'GET')
|
|
|
|
|
|
+ static getRequest(url, data ) {
|
|
|
|
+ let headerSign = this.getSignHead();
|
|
|
|
+ return this.requestAll(url, data, headerSign, 'GET')
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -35,19 +35,13 @@ class request {
|
|
/**
|
|
/**
|
|
* POST类型的网络请求
|
|
* POST类型的网络请求
|
|
*/
|
|
*/
|
|
- static postRequest(url, data, header = this.HEAD) {
|
|
|
|
- const token = wx.getStorageSync('token')
|
|
|
|
- if (token) {
|
|
|
|
- header.token = token
|
|
|
|
- }
|
|
|
|
- return this.requestAll(url, data, header, 'POST')
|
|
|
|
|
|
+ static postRequest(url, data) {
|
|
|
|
+ let headerSign = this.getSignHead();
|
|
|
|
+ return this.requestAll(url, data, headerSign, 'POST')
|
|
}
|
|
}
|
|
|
|
|
|
static upload(url, name, path, ortherData, header = this.HEAD){
|
|
static upload(url, name, path, ortherData, header = this.HEAD){
|
|
- const token = wx.getStorageSync('token')
|
|
|
|
- if (token) {
|
|
|
|
- header.token = token
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
wx.uploadFile({
|
|
url: url,
|
|
url: url,
|
|
@@ -62,7 +56,7 @@ class request {
|
|
resolve(res.data)
|
|
resolve(res.data)
|
|
} else {
|
|
} else {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
- title: res.data.message,
|
|
|
|
|
|
+ title: res.data.msg,
|
|
})
|
|
})
|
|
//其它错误,提示用户错误信息
|
|
//其它错误,提示用户错误信息
|
|
if (this._errorHandler != null) {
|
|
if (this._errorHandler != null) {
|
|
@@ -84,12 +78,25 @@ class request {
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ static getSignHead(){
|
|
|
|
+ let timestamp = parseInt(Date.now()/1000);
|
|
|
|
+ let nonce = Math.floor(Math.random() * 1000).toString()
|
|
|
|
+ let signStr = timestamp+nonce+""+"U6Watb875eCiX4Lq";
|
|
|
|
+ let sign = util.sha1(signStr).toString();
|
|
|
|
+
|
|
|
|
+ let signHeadInfo = {
|
|
|
|
+ "SIGN":sign,
|
|
|
|
+ "NONCE":nonce,
|
|
|
|
+ "TIMESTAMP":timestamp,
|
|
|
|
+ "Content-Type": "application/json"
|
|
|
|
+ }
|
|
|
|
+ return signHeadInfo;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 网络请求
|
|
* 网络请求
|
|
*/
|
|
*/
|
|
static requestAll(url, data, header, method) {
|
|
static requestAll(url, data, header, method) {
|
|
- const _self = this
|
|
|
|
|
|
+
|
|
wx.showLoading()
|
|
wx.showLoading()
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.request({
|
|
wx.request({
|