Last active
May 16, 2016 13:49
-
-
Save getchenge/fcf2242f8042d1ae26ac69b8ad5c0cd0 to your computer and use it in GitHub Desktop.
generate qrcode zip
This file contains 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
function testpage(req, res) { | |
const Archiver = require('archiver'); | |
const http = require('http'); | |
const Stream = require('stream').Transform; | |
const zip = Archiver('zip'); | |
const ids = [1, 2, 3]; | |
const merchant_id = 57; | |
const store_id = 278; | |
const gzid = 100123; | |
res.writeHead(200, { | |
'Content-Type': 'application/zip', | |
'Content-disposition': 'attachment; filename=iamges.zip' | |
}); | |
zip.pipe(res); | |
//zip.append('1231231231', {name: 'test_zip/1.txt'}).finalize(); | |
async.mapSeries(ids, getImage, function (err, results) { | |
// results is now an array of stats for each file | |
console.info('done', arguments); | |
zip.finalize(); | |
}); | |
function getImage(id, callback) { | |
var url = `http://xx.com/qrcode/siteno?store_id=${store_id}&siteno=${id}&gzid=${gzid}`; | |
//const content_url = encodeURIComponent(`https://wechat.web.huofu.com/weixin/meal/menu?merchant_id=${merchant_id}&store_id=${store_id}&nofetch=1&sitno=${id}`); | |
//const url = `http://test.wechat.web.huofu.com/qrcode?content=${content_url}&width=1024&margin=0`; | |
http.request(url, function (response) { | |
var data = new Stream(); | |
response.on('data', function (chunk) { | |
data.push(chunk); | |
}); | |
response.on('end', function () { | |
zip.append(data.read(), {name: `你好/${id}.png`}); | |
callback(); | |
}); | |
}).end(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment