-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
94 lines (86 loc) · 2.6 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const axios = require('axios');
const async = require('async');
const fs = require('fs');
const qs = require('qs');
const bankTypes = require('../bankType');
const provinces = require('../provinces');
const cities = require('../cities');
const MERCHANT_ID = 123456; // 商户 ID
const TOKEN = '';
const COOKIE = '';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
const request = axios.create({
baseURL: 'https://pay.weixin.qq.com',
timeout: 10000,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2743.82 Safari/537.36',
'Cookie': COOKIE
}
});
let requestParamsList = [];
bankTypes.forEach((bank) => {
let data = {};
data.bankId = bank.value;
provinces.forEach((province) => {
data.provinceId = province.value;
province.children.forEach((city) => {
const { code } = cities.find(item => city.name.includes(item.name)) || { code: 0 };
requestParamsList.push(Object.assign({}, data, {
'ecc_csrf_token': TOKEN,
'merchantId': MERCHANT_ID,
'cityId': city.value,
'mode': 3,
'name': city.name,
code
}));
});
});
});
let JSONtoBeSave = [];
let errorCount = 0;
let successCount = 0;
async.eachSeries(requestParamsList, (params, cb) => {
request
.post('/index.php/core/applymentnew/query_bank_list', qs.stringify({
'ecc_csrf_token': TOKEN,
'merchantId': MERCHANT_ID,
'mode': 3,
'bankId': params.bankId,
'provinceId': params.provinceId,
'cityId': params.cityId
}))
.then(res => {
return res.data;
})
.then(res => {
if (res.errorcode !== 0) {
cb(res.msg);
}
return res.data.map(item => {
delete params.ecc_csrf_token;
delete params.merchantId;
delete params.mode;
return Object.assign({}, item, params);
});
})
.then(json => {
successCount += 1;
if (json && Array.isArray(json) && json.length > 0) {
JSONtoBeSave.concat(json);
}
cb();
})
.catch(err => {
errorCount += 1;
console.log(`出现错误 ${errorCount} 次`);
console.log(JSON.stringify(err));
})
.then(() => {
console.log(`成功请求 ${successCount} 次,还剩 ${requestParamsList.length - successCount - errorCount} 次`);
})
}, () => {
fs.appendFileSync('./data/all.json', JSON.stringify(JSONtoBeSave));
console.log(`出现错误 ${errorCount} 次`);
console.log(`成功请求 ${successCount} 次,获得 ${JSONtoBeSave.length} 条银行数据`);
console.log('done');
});