authentication.js 601 B

12345678910111213141516171819202122232425
  1. import crypto from 'crypto'
  2. export const getHdConfig = (data = {}) => {
  3. const client_secret = process.env.VUE_APP_HD_SECRENT
  4. const config = {
  5. client_code: process.env.VUE_APP_HD_CODE,
  6. req_time: Date.now().toString().substr(0, 10),
  7. ...data
  8. }
  9. const authData = {
  10. ...config,
  11. client_secret
  12. }
  13. const keys = Object.keys(authData).sort((a, b) => a.localeCompare(b))
  14. const authStr = keys.map(key => authData[key]).join('')
  15. const md5 = crypto.createHash('md5')
  16. const authcode = md5.update(authStr).digest('hex').toLowerCase()
  17. return {
  18. ...config,
  19. authcode
  20. }
  21. }