import crypto from 'crypto'


export const getHdConfig = (data = {}) => {
  const client_secret = process.env.VUE_APP_HD_SECRENT
  const config = {
    client_code: process.env.VUE_APP_HD_CODE,
    req_time: Date.now().toString().substr(0, 10),
    ...data
  }
  const authData = {
    ...config,
    client_secret
  }
  const keys = Object.keys(authData).sort((a, b) => a.localeCompare(b))

  const authStr = keys.map(key => authData[key]).join('')
  const md5 = crypto.createHash('md5')
  const authcode = md5.update(authStr).digest('hex').toLowerCase()

  return {
    ...config,
    authcode
  }
}