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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| const cloud = require('wx-server-sdk') const rp = require('request-promise')
cloud.init()
exports.main = async (event, context) => {
const page = event.page const scene = event.scene
const appid = '***', secret = '***';
const AccessToken_options = { method: 'GET', url: 'https://api.weixin.qq.com/cgi-bin/token', qs: { appid, secret, grant_type: 'client_credential' }, json: true
};
const resultValue = await rp(AccessToken_options); const token = resultValue.access_token;
const code_options = { method: 'POST', url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + token, body: { 'page': page, 'width': 430, 'scene': scene }, json: true, encoding: null };
const buffer = await rp(code_options);
const upload = await cloud.uploadFile({ cloudPath: 'wxacode.png', fileContent: buffer, }) return { wxacodefileID: upload.fileID }
}
|