当前位置:网站首页>小程序使用二维码插件
小程序使用二维码插件
2022-06-30 07:57:00 【Dark_programmer】
以钉钉小程序为例。
1. 安装插件
npm install qr-image
2. 在组件内引入
const qrImage= require(‘qr-image’)
3. 转成base64格式的url
_arrayBufferToBase64(raw) {
var base64 = "";
var encodings =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var bytes = new Uint8Array(raw);
var byteLength = bytes.byteLength;
var byteRemainder = byteLength % 3;
var mainLength = byteLength - byteRemainder;
var a, b, c, d;
var chunk;
for (var i = 0; i < mainLength; i = i + 3) {
chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
a = (chunk & 16515072) >> 18;
b = (chunk & 258048) >> 12;
c = (chunk & 4032) >> 6;
d = chunk & 63;
base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d];
}
if (byteRemainder == 1) {
chunk = bytes[mainLength];
a = (chunk & 252) >> 2;
b = (chunk & 3) << 4;
base64 += encodings[a] + encodings[b] + "==";
} else if (byteRemainder == 2) {
chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1];
a = (chunk & 16128) >> 8;
b = (chunk & 1008) >> 4;
c = (chunk & 15) << 2;
base64 += encodings[a] + encodings[b] + encodings[c] + "=";
}
return "data:image/jpeg;base64," + base64;
}
4. 将数据通过上述方法转换
const content = '我是需要转换成二维码的内容,扫码就会看到我哦~';
const code = qrImage.imageSync( content , {
type: "png" });// 使用安装的插件
const qr_code = _arrayBufferToBase64(code); // 通过第三步将code转换为base64格式的二维码
5. 展示
<image mode="widthFix" src="{
{ qr_code }}" />
如此即可展示,二维码如下:
扫码结果:

边栏推荐
- ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
- 深度学习——特征点检测和目标检测
- Deep learning - embedding matrix and learning word embedding andword2vec
- 鲸探NFT数字臧品系统开发技术分享
- JS code case
- Directory of software
- Examen final - notes d'apprentissage PHP 5 - Tableau PHP
- 期末复习-PHP学习笔记1
- Investment and financing analysis report of Supply Chain & logistics industry in 2021
- 深度学习——序列模型and数学符号
猜你喜欢

Simple application of generating function

Development technology sharing of Jingtan NFT digital collection system

Simple application of generating function -- integer splitting 2

Recurrence relation (difference equation) -- Hanoi problem

What management improvements can CRM bring to enterprises

期末复习-PHP学习笔记4-PHP自定义函数

Common sorting methods

CRM&PM如何帮助企业创造最优销售绩效
![July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)](/img/37/ae0f7ca03ef564b029c9c709779231.jpg)
July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)

Lexicographic order -- full arrangement in bell sound
随机推荐
Final review -php learning notes 7-php and web page interaction
TP5 set direct download file
Summary and common applications of direction and angle operators in Halcon
December 4, 2021 - Introduction to macro genome analysis process tools
Final review -php learning notes 5-php array
Simple application of generating function
Spring Festival inventory of Internet giants in 2022
Go 数据类型篇之字符串及底层字符类型
深度学习——BRNN和DRNN
July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)
Armv8 (coretex-a53) debugging based on openocd and ft2232h
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
Network security and data in 2021: collection of new compliance review articles (215 pages)
CRM&PM如何帮助企业创造最优销售绩效
Efga design open source framework openlane series (I) development environment construction
min_ max_ Gray operator understanding
right four steps of SEIF SLAM
安科瑞高等学校校园建筑节能监管系统建设
Recurrence relation (difference equation) -- Hanoi problem
Introduction notes to pytorch deep learning (11) neural network pooling layer