let is = 2 var baseURL = 'https://api.hxxfb.com/gateway/' // API访问的地址 if(is==1){ baseURL = 'https://api.hxxfb.com/gateway/';//测试环境 }else if(is==2){ // baseURL = 'https://api.hebeiyhc.com/gateway/'; //生产环境 // baseURL = 'https://api.hebeiyhc.com/gateway/'; //生产环境 baseURL = 'https://testapi.hxxfb.com/gateway/'; //预生产环境 // baseURL = '/gateway/'; //预生产环境 }else{ baseURL = 'https://api.hxxfb.com/gateway/'; //预生产环境 } let token = ''; // 用户的token let volunteerToken = ''; // DES+B64加密 import time from '@/commit/item.js'; import { encryptDes, decryptDes } from '@/encryption/index.js' // 引用路径根据自己的文件结构而定 import Base64 from 'base-64' var d = new Date(); //标准时间 let Fzitem = time.dateFormat("yyyy-MM-dd HH:mm:SS", d) //2022-08-08 14:02:59 let shijian = '123456789/' + Fzitem //定义时间 + 封装时间 let jmi = encryptDes(shijian, "bjtdba123") let bas = Base64.encode(jmi + "," + Fzitem) export const myRequest = (options) => { return new Promise((resolve, reject) => { if(options.apiType === 'php'){ baseURL = '/api/' // baseURL = '/' console.log('url = ',baseURL + options.url,"PHP") } uni.request({ url: baseURL + options.url, //接口地址:前缀+方法中传入的地址 method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET” data: options.data || {}, //传递参数:传入的参数或者默认传递空集合 header: { // 'Content-Type': 'application/x-www-form-urlencoded', "Content-Type":"application/json; charset=utf-8", 'X-token': uni.getStorageSync('authorization'), //请求头信息 // "Access-Control-Allow-Methods":"GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE", // "Access-Control-Allow-Headers":" X-Token, user-token, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With", // 'X-token':'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuaHh4ZmIuY29tIiwiYXVkIjoiYXBpLmh4eGZiLmNvbSIsImlhdCI6MTczOTk2NDIxMiwibmJmIjoxNzM5OTY0MjEyLCJleHAiOjE3NTA3NjQyMTIsImp0aSI6WzM1OSwibWVyIl19.IX8wt8Fc05VgshXbUFTusGag4KD__teryi13L-QrJQM', 'volunteerdes': bas // DES+B64加密 }, success: (res) => { console.log('url = ',baseURL + options.url) console.log('params = ',options.data) // debugger resolve(res, "查看") //返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败) // 如果不满足上述判断就输出数据 if (res.data.status == 200) { //接口返回200走一下操作 resolve(res) } else if (res.data.status == 500) {//接口返回500走一下操作 return uni.showToast({ title: res.data.error, icon: 'none' }) } else { //除了500都会走以下操作 return uni.showToast({ title: res.data.message, icon: 'none' }) } }, // 这里的接口请求,如果出现问题就输出接口请求失败 fail: (err) => { reject(err) } }) }) }