import {getPhpToken} from "../utils/readAppInfo" export let baseURL = 'https://testapi.hxxfb.com/' // export let baseURL = '' // 请求超出时间 const timeout = 50000 // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuaHh4ZmIuY29tIiwiYXVkIjoiYXBpLmh4eGZiLmNvbSIsImlhdCI6MTc0MDM3MTM1NSwibmJmIjoxNzQwMzcxMzU1LCJleHAiOjE3NTExNzEzNTUsImp0aSI6WzI5OCwibWVyIl19.j2f8VwdwWY4zBpcijHntzUZ9YUms2SxChaVsYf7KnPs" // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzaG9wLmh4eGZiLmNvbSIsImF1ZCI6InNob3AuaHh4ZmIuY29tIiwiaWF0IjoxNzQwNTY5NDI3LCJuYmYiOjE3NDA1Njk0MjcsImV4cCI6MTc1MTM2OTQyNywianRpIjpbMzU0LCJtZXIiXX0.aZrICBozUFC0lvqxHgJMKFdhQlDHG1eC9UVAPzDHs5s" // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0YXBpLmh4eGZiLmNvbSIsImF1ZCI6InRlc3RhcGkuaHh4ZmIuY29tIiwiaWF0IjoxNzQxNDA1MzY3LCJuYmYiOjE3NDE0MDUzNjcsImV4cCI6MTc1MjIwNTM2NywianRpIjpbMzEyOSwibWVyIl19.CQ206TpfwaY5mkwiETjAPWExLh1uh4mAf2Vy9uhvTRQ" const token = "" export const phpToken = uni.getStorageSync('phpToken') || token // 需要修改token,和根据实际修改请求头 export function myRequestPhp(options) { const phpTokens = uni.getStorageSync('phpToken') || token let url = options.url; let method = options.method || "get"; let data = options.data || {}; let contentType = options.contentType || "application/json;charset=UTF-8"; let header = { 'Content-Type': contentType, "X-Token": phpTokens, ...options.header } return new Promise((resolve, reject) => { uni.request({ url: baseURL + url, method: method, header: header, data: data, timeout, success:async function(response) { const res = response const message = res.data && res.data.message || "" // console.log(res, "resresresresres") // console.log(message, "99999message") 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 if ((res.data.status == 400 || res.data.status == 40000) && (message.indexOf('登录') > -1 || message.indexOf('过期') > -1 || message.indexOf('token') > -1)) { //接口返回400走一下操作500走一下操作 await getPhpToken() resolve(res) } else { //除了500都会走以下操作 // console.log(message, "messag9999e") uni.showToast({ title: message, icon: 'none', duration: 6000 }) // reject(res) } }, fail(err) { console.log(err,"接口") if (err.errMsg.indexOf('request:fail') !== -1) { uni.showToast({ title: '网络异常', icon: "error", duration: 2000 }) } else { uni.showToast({ title: '未知异常', duration: 2000 }) } uni.hideToast(); reject(err); }, complete() { // uni.hideToast(); } }); }).catch(() => { uni.hideToast(); }); };