index.js
1.59 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
54
55
56
57
58
59
60
61
62
63
64
65
const path = require('path');
var fetch = require('node-fetch');
var fs = require('fs');
var file = path.join(process.cwd(),'/data.csv');
var json2csv = require('json2csv');
var csvFields = ['accessToken','expires','updateTime'];
//console.log(fetch);
var accessToken = '9FrII2SMyfSQqMgTKXBc2CBE_c-O8MW4Hc1SCO9o7pK3k-BLr-x4oGhWMG_Bzr7Or7xnFr1nx-gGdlorAGUAh6Vtisdusb7gq9bbO_byzYOGUoQ8FZZncgZ3JCvI6ov1AXNcAIDQND';
var getUsersUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token='+accessToken;
console.log(getUsersUrl);
var ss = function(url,param){
return recordWxUsers()
};
var testUrl = 'http://thirdparty.qingger.com/auth/accessToken/MPShop';
recordWxUsers(testUrl).then(function(response){
console.log(response);
if(typeof response.call=='function') {
response.call(testUrl,response.param);
}
},function(rejResponse){
console.log(rejResponse);
});
//
// var openids = json.data.openid;
// var openidLength = openids.length;
// var lastOpenId = openidLength?openids[openidLength-1]:null;
var result = json2csv({data:json.data,fields:csvFields});
console.log(result);
fs.writeFile(file,result,'utf8',function(err){
if(err) throw err;
console.log('Saved.');
});
function recordWxUsers(url,nextOpenId=null){
return new Promise(function(resolve,reject){
fetch(url)
.then(function(res) {
return res.json();
})
.then(function(json) {
// 处理json
return new Promise(function(resolve,reject){
fetch(url)
})
});
});
}