import { getCurrentUser, getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import gg5xxxxx from 'js-md5';
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';

const isTest = getUrlInfo().test;

export function getHeaders(url = '', headersApi = undefined) {
  const token = getToken();
  const currentInfo = getCurrentUser() || {};
  const user = getUserInfo() || {};
  const userId = user.id || currentInfo.xgUserId;
  const timestamp = user.differenceBetweenServerAndClientTime ? new Date().getTime() + user.differenceBetweenServerAndClientTime : new Date().getTime();
  const secretString = token + userId + timestamp;
  const res = {
    headers: {},
  };

  if (!token || token === 'null') {
    return res;
  } else {
    res.headers.Authorization = `bearer ${token}`; // 这个必须要带上
  }

  if (getIsBei_Dian() && userId) {
    res.headers.Authorization = `bearer ${token}`;
    res.headers.auth = gg5xxxxx(secretString);
    res.headers.timestamp = timestamp;
    if (headersApi) {
      res.headers.apis = headersApi;
    }
  }
  return res;
}
