import md5 from 'js-md5';
import util from '@/libs/util';
const api_sign_secret = process.env.VUE_APP_API_SIGN_SECRET;
const tagInfo = "/libs/net/sign.js";
export default function (data) {
  if (!data) {
    data = {};
  }
  const timestamp = parseInt((new Date()).getTime() / 1000);


  // console.log("timestamp,",timestamp,data);
  data._timestamp = timestamp;
  const sortData = {};
  Object.keys(data).sort().forEach((key) => {
    sortData[key] = util.string.parseString(data[key]);
  });
  console.log(tagInfo, JSON.stringify(sortData) + api_sign_secret);
  sortData._sign = md5(JSON.stringify(sortData) + api_sign_secret);
  return sortData;
};
