生成二维码

利用JavaScript生成二维码并且中间有logo





该二维码支持中文和LOGO
 




 


    

该二维码支持中文和LOGO

最后我采用的这个啦,很好用哦~
qr-image 在 Egg.js 中的使用

安装

  npm i qr-image --save

使用
前端:

二维码

后端:

'use strict';

const qr = require('qr-image');


class CelebrationController extends Controller {

  async qrcode() {
    // const { id } = this.ctx.query;
    const id = 1;
    try {
      // 大小默认5,二维码周围间距默认1
      const img = qr.image(`https://h5celebration.woody.club?id=${id}`, { type: 'png', size: 4, margin: 1 });
      this.ctx.status = 200;
      this.ctx.type = 'image/png';
      this.ctx.body = img;
    } catch (e) {
      this.ctx.status = 414;
      this.ctx.set('Content-Type', 'text/html');
      this.ctx.body = '

414 Request-URI Too Large

'; } } } module.exports = CelebrationController;

你可能感兴趣的:(生成二维码)