index.js 497 B

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