verifyApi

  1. 小程序里面如果使用,window.$appNavs需要替换为对应的
  2. verifyApi() 传递给headers参数 XverifyApi

//,_security
import {
  encryptByDES
} from "./crypto";
//通过节点获取所有底下树形数据
export function newGuid() {
  let guid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    let r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });

  if (window.$appNavs && window.$appNavs.project && window.$appNavs.project.ownerId) {
    let len = window.$appNavs.project.ownerId.length;
    guid = window.$appNavs.project.ownerId + '010' + guid.substr(0, guid.length - len - 3);
  }
  return guid;
}
//获取 VerifyApi 2分钟内有效
export function verifyApi() {
  /* eslint-disable */
  let result = null;
  if (
    window.$appNavs.auth.verifyApi === "only-guid") {
    result = encryptByDES(`${newGuid()}`);
  } else {
    result = encryptByDES(`${newGuid()}|${dayjs().add(110, 'second').valueOf()}`);
  }
  /* eslint-disable */
  return result;
}
// guid 参数
export function verifyGuid() {
  /* eslint-disable */
  let result = encryptByDES(`${newGuid()}`);
  /* eslint-disable */
  return result;

}

//控制特殊接口不受_menuId控制,只用于站内
export function verifyMenuId(menuId, userId, mkey, field) {
  return encryptByDES(`${userId}|${menuId}|${mkey}|${field}|${dayjs().add(6, 'second').valueOf()}`);
}


/**
 * 验证 number
 * @param {*} str 
 */
export function isNumber(str) {
  return Number.isNumber(str);
}

/**
 * 验证string
 * @param {*} str 
 */
export function isString(str) {
  return typeof str == "string" && str.constructor == String;
}


/**
 * 验证 array
 * @param {*} str 
 */
export function isArray(str) {
  return Array.isArray(str)
}


/**
 * 验证 object
 * @param {*} str 
 */
export function isObject(str) {
  return typeof str == "string" && str.constructor == String;
}
文档更新时间: 2022-04-13 06:59   作者:admin