Last active
September 8, 2020 05:40
-
-
Save edison1105/3207f2b6784058476fea9283bec7dccc to your computer and use it in GitHub Desktop.
下载所有的公众号消息模板
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var fs = require('fs') | |
function getQueryString(begin) { | |
return `begin=${begin}&count=20&keyword=&action=tmpl_store&token=YOUR_TOKEN&lang=zh_CN&f=json&ajax=1` | |
} | |
const cookie = '' | |
const headers = { | |
'cookie': cookie, | |
'authority': 'mp.weixin.qq.com', | |
'x-requested-with': 'XMLHttpRequest', | |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36' | |
} | |
let begin = 0 | |
let pageIndex = 0 | |
function getJson() { | |
const query = getQueryString(begin) | |
request({ | |
url: 'http://mp.weixin.qq.com/advanced/tmplmsg?' + query, | |
headers | |
}, function (error, response, body) { | |
if (response.statusCode === 200) { | |
fs.writeFile('temp.json', body, { flag: 'a' }, function (err) { | |
if (err) { | |
console.log("Error") | |
} else { | |
console.log("OK pageIndex:" + pageIndex + ', begin:' + begin); | |
} | |
}) | |
begin += 20 | |
pageIndex += 1 | |
if (pageIndex > 1220) return | |
getJson() | |
} | |
}) | |
} | |
getJson() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace your token and cookie.