| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import { HmacCipher } from '../src/utils/cipher/hmac'
- import { AESCipher } from '../src/utils/cipher/aes'
- const secret = {
- operatorSecret: 'qhtestOS73099864',
- dataSecret: 'qhtestDS73099864',
- dataSecretIV: 'qhtestIV73099864',
- sigSecret: 'qhtestSS73099864',
- }
- /**
- * Testing query_token api
- */
- import { getUTCFormatTime } from '../src/utils/time'
- const OperatorID = '730998640' // Requester ID
- const payload = {
- OperatorID: OperatorID,
- Data: undefined,
- TimeStamp: getUTCFormatTime(), // Need util to do this
- Seq: '0001',
- Sig: undefined,
- }
- const data = {
- OperatorID: OperatorID,
- OperatorSecret: secret.operatorSecret, // Servicer Secret
- }
- const aesCipher = new AESCipher()
- const hmacCipher = new HmacCipher()
- const encryptData = aesCipher.encrypt(
- JSON.stringify(data),
- secret.dataSecret,
- secret.dataSecretIV
- )
- payload.Data = encryptData
- const constructHashText =
- payload.OperatorID + payload.Data + payload.TimeStamp + payload.Seq
- const sign = hmacCipher.hmacMD5Sign(constructHashText, secret.sigSecret)
- payload.Sig = sign
- console.log('-'.repeat(33))
- console.log(JSON.stringify(payload))
- console.log('-'.repeat(33))
- const targetUrl = 'https://evtry.qihui.net/evnet/evcs/equipment/v1/query_token'
- fetch(targetUrl, {
- body: JSON.stringify(payload),
- headers: {
- 'Content-Type': 'application/json',
- },
- method: 'POST',
- }).then(async (resp) => {
- const data = await resp.json()
- const decryptData = aesCipher.decrypt(
- data.Data,
- secret.dataSecret,
- secret.dataSecretIV
- )
- console.log('data:', data)
- console.log('decryptData:', decryptData)
- // Check Sig
- const signature = hmacCipher.hmacMD5Sign(
- data.Ret + data.Msg + data.Data,
- secret.sigSecret
- )
- console.log('signature:', signature)
- console.log('Is Sig Valid:', signature === data.Sig)
- console.log('-'.repeat(33))
- })
- // Test crazy charge query token //
- // import { HmacCipher } from '../src/utils/cipher/hmac'
- // import { AESCipher } from '../src/utils/cipher/aes'
- // const secret = {
- // operatorSecret: 'f384603e90e46168',
- // dataSecret: '1ebbf89ffaaff9c6',
- // dataSecretIV: '8fd9154b6ef6f7c1',
- // sigSecret: 'a955047992ff5096',
- // }
- // /**
- // * Testing query_token api
- // */
- // import { getUTCFormatTime } from '../src/utils/time'
- // const OperatorID = '192316877' // Requester ID
- // const payload = {
- // OperatorID: OperatorID,
- // Data: undefined,
- // TimeStamp: getUTCFormatTime(), // Need util to do this
- // Seq: '0001',
- // Sig: undefined,
- // }
- // const data = {
- // OperatorID: OperatorID,
- // OperatorSecret: secret.operatorSecret, // Servicer Secret
- // }
- // const aesCipher = new AESCipher()
- // const hmacCipher = new HmacCipher()
- // const encryptData = aesCipher.encrypt(
- // JSON.stringify(data),
- // secret.dataSecret,
- // secret.dataSecretIV
- // )
- // payload.Data = encryptData
- // const constructHashText =
- // payload.OperatorID + payload.Data + payload.TimeStamp + payload.Seq
- // const sign = hmacCipher.hmacMD5Sign(constructHashText, secret.sigSecret)
- // payload.Sig = sign
- // console.log('-'.repeat(33))
- // console.log(JSON.stringify(payload))
- // console.log('-'.repeat(33))
- // // const targetUrl = 'http://192.168.1.33:12000/api/v1/hooks/evcs/customer/v1/query_token'
- // // const targetUrl =
- // // 'http://localhost:12000/api/v1/hooks/evcs/customer/v1/query_token'
- // const targetUrl =
- // 'https://test.crazycharge.com.hk/api/v1/hooks/evcs/customer/v1/query_token'
- // fetch(targetUrl, {
- // body: JSON.stringify(payload),
- // headers: {
- // 'Content-Type': 'application/json',
- // },
- // method: 'POST',
- // }).then(async (resp) => {
- // const data = await resp.json()
- // const decryptData = aesCipher.decrypt(
- // data.Data,
- // secret.dataSecret,
- // secret.dataSecretIV
- // )
- // console.log('data:', data)
- // console.log('decryptData:', decryptData)
- // // Check Sig
- // const signature = hmacCipher.hmacMD5Sign(
- // data.Ret + data.Msg + data.Data,
- // secret.sigSecret
- // )
- // console.log('signature:', signature)
- // console.log('Is Sig Valid:', signature === data.Sig)
- // console.log('-'.repeat(33))
- // })
|