123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- const GET = 'GET';
- const POST = 'POST';
- const PUT = 'PUT';
- const FORM = 'FORM';
- const DELETE = 'DELETE';
- // wxb299e10e65157301
- // wx2938132b773c7b5a
- const baseURL = 'https://wx.scxjc.club';
- // const baseURL = 'https://www.hunanwanzhu.com';
- // const baseURL = 'https://api.hunanwanzhu.com';
- function request(method, url, data) {
- var token='';
- return new Promise(function (resolve, reject) {
- wx.getStorage({
- key: 'userInfo',
- complete: res => {
- if (res.data) {
- token = res.data.token
- }
- let header = {
- 'content-type': 'application/json',
- 'Authorization': token
- };
- wx.request({
- url: baseURL + url,
- method: method,
- data: data,
- header: header,
- success(res) {
- //请求成功
- //判断状态码---errCode状态根据后端定义来判断
- if (res.data.code == 0) {
- resolve(res);
- } else if (res.data.code == 403) {
- //未登录
- reject(403)
- wx.switchTab({
- url: '../user/user',
- })
- }else{
- wx.hideNavigationBarLoading()
- wx.hideLoading()
- wx.showToast({
- title: res.data.message,
- icon:'none',
- duration:3000
- })
- }
- },
- fail(err) {
- //请求失败
- wx.showToast({
- icon:'none',
- title: '服务器开小差了',
- })
- reject(err)
- }
- })
- }
- })
-
- })
- }
- function uploadFile(url, filePath, name, formData, isSubDomain) {
- var token = '';
- return new Promise((resolve, reject) => {
- wx.getStorage({
- key: 'userInfo',
- complete: res => {
- if (res.data) {
- token = res.data.token
- }
- let header = {
- 'content-type': 'application/json',
- 'Authorization': token
- };
-
- wx.uploadFile({
- url: baseURL + url,
- filePath: filePath,
- name: name,
- // formData: formData,
- header: header,
- success: res => {
- resolve(JSON.parse(res.data))
- },
- fail(err) {
- //请求失败
- reject(err)
- }
- })
- }
- })
-
- })
- }
- const API = {
- getOpenid: (data) => request(GET, `/api/wx/openid`, data),
- login: (data) => request(POST, `/api/wx/v3/login`, data),
- bindphone: (data) => request(POST, `/api/wx/v3/phone/bind`, data),
- sendcode: (data) => request(POST, `/api/wx/v3/phone/code`, data),
- getAuthinfo: (data) => request(GET, `/api/wx/authinfo`, data),
- getEnumList: (data) => request(GET, `/api/wx/v2/enum/list`, data),
- getIndex: (data) => request(GET, `/api/wx/index`, data),
- getRank: (data) => request(GET, `/api/wx/group/rank/list`, data),
- getRankList: (data) => request(GET, `/api/wx/group/rank`, data),
- getPlayerMatch: (data) => request(GET, `/api/wx/player/match`, data),//参赛资料
- updateFollow: (data) => request(POST, `/api/wx/v2/user/follow`, data),
- getRinrate: (data) => request(GET, `/api/wx/v2/winrate/rank`, data),
- getDefend: (data) => request(GET, `/api/wx/v2/defend/rank`, data),
- getHotbuyList: (data) => request(GET, `/api/wx/v2/hot/stock/buy/list`, data),
- getHotsellList: (data) => request(GET, `/api/wx/v2/hot/stock/sell/list`, data),
- getSellStock: (data) => request(GET, `/api/wx/v2/hot/stock/sell/players`, data),
- getChampionlList: (data) => request(GET, `/api/wx/v2/champion/article/list`, data),
- upload: (filePath, name) => uploadFile(`/api/wx/uploadfile`, filePath, name),
- updateStyle: (data) => request(PUT, `/api/wx/v2/mine/style`, data),
- getMyStyle: (data) => request(GET, `/api/wx/v2/mine/style`, data),
- getMyFollow: (data) => request(GET, `/api/wx/v2/user/follow/list`, data),
- getMyMatch: (data) => request(GET, `/api/wx/player/match/list`, data),
- getComment: (data) => request(GET, `/api/wx/v2/wanzhu/comment/list`, data),
- getRecordList: (data) => request(GET, `/api/wx/player/match/record/list`, data),
- follow: (data) => request(POST, `/api/wx/v2/user/follow`, data),
- getPlayerList: (data) => request(GET, `/api/wx/v2/player/list`, data),
- updateRecord: (data) => request(POST, `/api/wx/player/record`, data),
- getRecord: (data) => request(GET, `/api/wx/player/record`, data),
- getCurrecord: (data) => request(GET, `/api/wx/player/currecord`, data),
- getArticle: (data) => request(GET, `/api/wx/article`, data),
- getStock: (data) => request(GET, `/api/wx/v2/stock`, data),
- searchStock: (data) => request(GET, `/api/wx/stock/search`, data),
- getNotoice: (data) => request(GET, `/api/wx/v2/notices/list`, data),
- getDate: (data) => request(GET, `/api/wx/v2/default/date`, data),
- getHotFollow: (data) => request(GET, `/api/wx/v2/hot/follow/list`, data),
- getCalendar: (data) => request(GET, `/api/wx/v2/player/match/calendar`, data),
- getMatchList: (data) => request(GET, `/api/wx/v2/match/list`, data),
- getMineLatest: (data) => request(GET, `/api/wx/v2/mine/latest`, data),
-
- };
- module.exports = {
- API: API
- }
|