"use strict";
const common_vendor = require("../../vendor.js");
const common_js_cache_storage = require("../cache/storage.js");
const common_js_net_mainUrl = require("./mainUrl.js");
function request(url, method = "GET", data = {}, params = {}, project = "copyright", needToken = true) {
  const header = {
    "content-type": "application/json"
    // 有其他content-type需求加点逻辑判断处理即可
  };
  if (needToken) {
    const token = common_js_cache_storage.get("token");
    if (token) {
      header.Auth = `Bearer ${token}`;
    }
  }
  var baseUrl = common_js_net_mainUrl.operatorUrl;
  if (project == "operator") {
    baseUrl = common_js_net_mainUrl.operatorUrl;
  } else if (project == "copyright") {
    baseUrl = common_js_net_mainUrl.copyrightUrl;
  } else if (project == "plug") {
    baseUrl = common_js_net_mainUrl.operatorPlug;
  }
  return new Promise(function(resolve, reject) {
    common_vendor.index.request({
      url: baseUrl + url,
      timeout: 8e3,
      method,
      data,
      dataType: "json",
      // 微信官方文档中介绍会对数据进行一次JSON.parse
      header,
      success(res) {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          common_vendor.index.__f__("log", "at common/js/net/http.js:55", "错误success");
          reject(res.data);
        }
      },
      fail(err) {
        common_vendor.index.__f__("log", "at common/js/net/http.js:60", "错误");
        if (err.data) {
          reject(err.data);
        } else {
          reject(err);
        }
      }
    });
  });
}
exports.request = request;
//# sourceMappingURL=../../../../.sourcemap/mp-toutiao/common/js/net/http.js.map
