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)) // })