
let locationName = window.location.hostname;
function getApiUrl() {
  let url = {
    urlPost: locationName.indexOf('oytour') !== -1 ? "http://reborn.oytour.com/api/common/post" : "http://192.168.2.214:8082/api/common/post",
    urlJava: locationName.indexOf('oytour') !== -1 ? "https://efficient.oytour.com/" : "http://192.168.2.215:9000/"
  }
  return url
}
String.prototype.myReplace=function(f,e){  //时间格式化 苹果手机-替换为/
  var reg=new RegExp(f,"g"); //创建正则RegExp对象
  return this.replace(reg,e);
}
function getLocalStorage() {
  var localStorageData = window.localStorage["userInfo"];
  if (localStorageData != undefined) {
      return JSON.parse(localStorageData);
  } else {
      return null;
  }
}
function getLocalStorage2() {
  var localStorageData = window.localStorage["userInfo2"];
  if (localStorageData != undefined) {
      return JSON.parse(localStorageData);
  } else {
      return null;
  }
}
function clearLocalStorage() {
  window.localStorage.removeItem('userInfo')
}
function getAjaxData(cmd, msg, tk) {
  if (msg == null || msg == "") {
      msg = {}
  }
  let timestamp = (new Date()).valueOf();
  let token = "";
  let key = "";
  if (getLocalStorage() != null) {
      token = getLocalStorage().token;
      key = getLocalStorage().SecretKey;
  }
  let encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
  let md5Str = hex_md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
  let postData = {
      "msg": msg,
      "cmd": cmd,
      "timestamp": timestamp,
      "token": tk ? tk : token,
      "sign": md5Str
  }
  return JSON.stringify(postData)
}
function getJavaData(msg) {
  if (msg == null || msg == "") {
      msg = {}
  }
  let timestamp = (new Date()).valueOf();
  let token = "";
  let key = "";
  if (getLocalStorage() != null) {
    token = getLocalStorage().token;
    key = getLocalStorage().SecretKey;
  } else if (getLocalStorage2() != null) {
    if (getLocalStorage2() != null) {
      token = getLocalStorage2().token;
      key = getLocalStorage2().secretKey;
  }
  }
  let userInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : JSON.parse(localStorage.userInfo2) ? JSON.parse(localStorage.userInfo2) : ''
  let uid = userInfo.accountId ? userInfo.accountId : 0
  let encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
  let md5Str = hex_md5(`msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
  let postData = {
      "groupId": 2,
      "msg": msg,
      "uid": uid,
      "timestamp": timestamp,
      "token": token,
      "sign": md5Str
  }
  return JSON.stringify(postData)
}

function getJavaA(msg, tk) {
    if (msg == null || msg == "") {
        msg = {}
    }
    let timestamp = (new Date()).valueOf();
    let token = "";
    let key = "";
    if (getLocalStorage() != null) {
        token = getLocalStorage().token;
        key = getLocalStorage().SecretKey;
    }
    let userInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : JSON.parse(localStorage.userInfo2) ? JSON.parse(localStorage.userInfo2) : ''
    let uid = userInfo.accountId ? userInfo.accountId : 0
    let encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
    let md5Str = hex_md5(`msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
    let postData = {
        "groupId": 2,
        "msg": msg,
        "timestamp": timestamp,
        "token": tk ? tk : token,
        "sign": md5Str,
        "uid": uid,
    }
    return JSON.stringify(postData)
}
