-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
39 lines (38 loc) · 1.23 KB
/
test.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
let https = require('https');
let fs =require('fs')
let getSync = () => {
return new Promise((resolve,reject) => {
https.get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxfe86c090e3d88f8c&secret=83ce792f93bab7df544fecae73725859',(res) => {
res.on('data',(d)=>{
resolve(d)
})
.on('err',(err)=>{
reject(err)
})
})
})
}
async function fn() {
let value = await function() {
return new Promise((resolve,reject) => {
https.get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxfe86c090e3d88f8c&secret=83ce792f93bab7df544fecae73725859',(res) => {
res.on('data',(d)=>{
resolve(d)
})
.on('err',(err)=>{
reject(err)
})
})
})
}()
return value
}
fn()
.then((data)=>{
// console.log(data.toString())
fs.writeFileSync('./access_token.txt',data)
let info = fs.readFileSync('./access_token.txt')
info = info.toString()
console.log(info)
})
.catch(err=>console.log(err))