index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const OperatorID = '730998640' // Requester ID
  2. const payload = {
  3. OperatorID: OperatorID,
  4. Data: undefined,
  5. TimeStamp: getUTCFormatTime(),
  6. Seq: '0001',
  7. Sig: undefined,
  8. }
  9. const data = {
  10. OperatorID: OperatorID,
  11. OperatorSecret: secret.operatorSecret, // Servicer Secret
  12. }
  13. const aesCipher = new AESCipher()
  14. const hmacCipher = new HmacCipher()
  15. const encryptData = aesCipher.encrypt(
  16. JSON.stringify(data),
  17. secret.dataSecret,
  18. secret.dataSecretIV
  19. )
  20. payload.Data = encryptData
  21. const constructHashText =
  22. payload.OperatorID + payload.Data + payload.TimeStamp + payload.Seq
  23. const sign = hmacCipher.hmacMD5Sign(constructHashText, secret.sigSecret)
  24. payload.Sig = sign
  25. console.log('Payload:', payload)
  26. const targetUrl = 'https://evtry.qihui.net/evnet/evcs/equipment/v1/query_token'
  27. fetch(targetUrl, {
  28. body: JSON.stringify(payload),
  29. headers: {
  30. 'Content-Type': 'application/json;charset=UTF-8',
  31. Accept: 'application/json, text/plain',
  32. },
  33. method: 'POST',
  34. mode: 'no-cors'
  35. }).then(async (resp) => {
  36. console.log(await resp.text())
  37. })