12345678910111213141516171819202122232425262728293031323334 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const QRCode = require('qrcode');
- const assert = require('assert');
- // 二维码
- class QrcodeService extends CrudService {
- constructor(ctx) {
- super(ctx, 'qrcode');
- this.model = this.ctx.model.Card;
- this.uri = 'http://www.baidu.com/';
- }
- async initQRCode({ id = 'a' }) {
- // assert(id, '缺少推荐人信息');
- // const user = await this.model.findById(id);
- // if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '为找到用户信息');
- // const { mobile, name } = user;
- const mobile = '13089419810',
- name = 'liuruifeng';
- const url = `${this.uri}?id=${id}&mobile=${mobile}&name=${name}`;
- // const res = await QRCode.toDataURL(url, {
- // width: 200,
- // });
- const qrcode = await QRCode.toFile(url);
- // const qrcode = await QRCode.toString(url, { type: 'png' });
- // const qrimage = `data:image/png;base64${Buffer(qrcode).toString('base64')}`;
- return qrcode;
- }
- }
- module.exports = QrcodeService;
|