-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
54 lines (37 loc) · 1.48 KB
/
init.js
File metadata and controls
54 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const fs = require('fs');
var config = require('./config')
var crypto = require('crypto');
// var apiUrl = 'http://127.0.0.1:3000/v1/sys/heartbeat';
// var apiBody = JSON.stringify({"method":"server_info","params":[]});
// var appKeyObj = config.appKey;
// var apiRequest = Buffer.from(apiUrl).toString('base64') +
// Buffer.from(apiBody).toString('base64');
// var hmac = crypto.createHmac('sha512', appKeyObj);
// var data = hmac.update(apiRequest);
// var gen_hmac= data.digest('hex');
// console.log(gen_hmac);
// 1 请求监管系统接口
const request = require('request');
request(config.superVisionKeyUrl, function (error, response, body) {
console.error('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
const jsonObj = JSON.parse(body);
// 2 获取appKey
if(jsonObj.code == 0){
if(jsonObj.data != undefined && jsonObj.data.appKey != undefined){
// 3 将appKey存入配置文件
let data = JSON.stringify(jsonObj.data);
fs.writeFileSync('./config/appKey.json', data, (err) => {
if (err) throw err;
console.log('Data written to file');
});
}else{
console.error("格式错误",JSON.stringify(jsonObj));
}
}else{
console.error(jsonObj.message);
}
});
//