Skip to content

Instantly share code, notes, and snippets.

@edison1105
Last active September 8, 2020 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edison1105/3207f2b6784058476fea9283bec7dccc to your computer and use it in GitHub Desktop.
Save edison1105/3207f2b6784058476fea9283bec7dccc to your computer and use it in GitHub Desktop.
下载所有的公众号消息模板
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()
@edison1105
Copy link
Author

replace your token and cookie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment