index.js 513 B

123456789101112131415161718
  1. const cloud = require('wx-server-sdk');
  2. cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
  3. exports.main = async (event, context) => {
  4. const pagePath = event.pagePath;
  5. // 获取小程序二维码的buffer
  6. const resp = await cloud.openapi.wxacode.get({
  7. path: pagePath,
  8. });
  9. const { buffer } = resp;
  10. // 将图片上传云存储空间
  11. const upload = await cloud.uploadFile({
  12. cloudPath: String(pagePath).replace(/\//g, '_') + '.png',
  13. fileContent: buffer
  14. });
  15. return upload.fileID;
  16. };