RT
新建createwxaqrcode.js
:
const request = require('request')
const fs = require('fs')
// eg:生成購物車列表圓形二維碼圖片
createwxaqrcode({
appid: your appid,
secret: your secret,
url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token=',
postParams: {
path: '/pages/cart/list',
is_hyaline: true
}
})
/**
* 生成微信小程序二維碼
*
* @param {Object} {
* appid,
* secret,
* url, // 詳見https://developers.weixin.qq.com/miniprogram/dev/api/qrcode.html,
* postParams: {
* path: String, // 路徑
* is_hyaline: Boolean // 圖片是否透明
* },
* qrname = 'wxqr.jpg' // 生成的二維碼圖片名,可選
* }
* @return null
*/
function createwxaqrcode({
appid,
secret,
url,
postParams,
qrname = 'wxqr.jpg'
}) {
return request.get(
`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
(err,httpResponse,body) => {
let access_token = JSON.parse(body).access_token
return request.post({
url: `${url}${access_token}`,
json: postParams
})
.pipe(fs.createWriteStream(qrname))
}
)
}
需要npm install request
。
執行node createwxaqrcode.js
。
如此,就在本地得到了小程序二維碼圖片。
完結,撒花~