当前位置:网站首页>小程序使用二维码插件
小程序使用二维码插件
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 }}" />
如此即可展示,二维码如下:
扫码结果:
边栏推荐
- Efga design open source framework fabulous series (I) establishment of development environment
- 期末複習-PHP學習筆記3-PHP流程控制語句
- Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]
- Calculate Euler angle according to rotation matrix R yaw, pitch, roll source code
- 直击产业落地 | 飞桨重磅推出业界首个模型选型工具
- Deep learning - bounding box prediction
- 深度学习——序列模型and数学符号
- Multi whale capital: report on China's education intelligent hardware industry in 2022
- Global digital industry strategy and policy observation in 2021 (China Academy of ICT)
- 2021.11.20 [reading notes] | differential variable splicing events and DTU analysis
猜你喜欢
Deep learning vocabulary representation
深度学习——LSTM
National technology n32g45x series about timer timing cycle calculation
Deep learning - LSTM
Introduction notes to pytorch deep learning (XII) neural network - nonlinear activation
深度学习——目标定位
November 19, 2021 [reading notes] a summary of common problems of sneakemake (Part 2)
25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了
【花雕体验】14 行空板pinpong库测试外接传感器模块(之一)
2021.11.20 [reading notes] | differential variable splicing events and DTU analysis
随机推荐
想问问,炒股怎么选择证券公司?网上开户安全么?
Construction of module 5 of actual combat Battalion
期末复习-PHP学习笔记4-PHP自定义函数
AcrelEMS能效管理平台为高层小区用电安全保驾护航
MySQL cannot connect to the intranet database
At the age of 25, I started to work in the Tiankeng industry with buckets. After going through a lot of hardships to become a programmer, my spring finally came
December 4, 2021 - Introduction to macro genome analysis process tools
December 13, 2021 [reading notes] | understanding of chain specific database building
Deep learning -- using word embedding and word embedding features
期末複習-PHP學習筆記3-PHP流程控制語句
right four steps of SEIF SLAM
Lodash filter collection using array of values
Wangbohua: development situation and challenges of photovoltaic industry
Final review -php learning notes 1
Why don't you know what to do after graduation from university?
Palindrome substring, palindrome subsequence
What management improvements can CRM bring to enterprises
期末複習-PHP學習筆記5-PHP數組
2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)
深度学习——语言模型和序列生成