Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
wxmp-qrcode
Advanced tools
适用于微信小程序的二维码生成器,基于Canvas生成,支持中文的输入。可在原生小程序,mpvue,taro中使用。
npm install wxmp-qrcode
id
,与canvas-id
, 并设置canvas的样式,二维码基于其大小生成并居中<canvas id="cav-qrcode" canvas-id="cav-qrcode"></canvas>
import QR from 'wxmp-qrcode'
QR.draw(str, canvasId, () => {
console.log('draw success!')
})
/**
* 根据canvas尺寸,画出合适居中的qrcode
* @param {Object} str 二维码的内容 (必须)
* @param {Object} canvasId canvasId的值 (必须)
* @param {Object} $this 传入组件的this,兼容在组件中生成二维码 (可选,可省略该参数)
* @param {Object} callback 回调函数 (可选)
*/
draw: function (str, canvasId, $this, callback)
/**
* 清除canvas内容
* @param {Object} canvasId canvasId (必须)
* @param {Object} callback 回调函数 (可选)
*/
clear: function (canvasId, callback)
draw(str, canvasId, componentThis)
createQrCode: function (content, canvasId) {
QR.api.draw(content, canvasId)
this.canvasToTempImage(canvasId)
},
//获取临时缓存图片路径
canvasToTempImage: function (canvasId) {
wx.canvasToTempFilePath({
canvasId,
success: function (res) {
let tempFilePath = res.tempFilePath; // 临时图片地址,可在放入图片src中使用
}
})
}
使用npm模块
npm init
, 之后再安装模块 npm i wxmp-qrcode
构建npm
<view class="container">
<canvas id="{{canvasId}}" canvas-id="{{canvasId}}"></canvas>
<button bindtap="creatQRCode"> 生成二维码 </button>
</view>
canvas {
border: 1rpx solid #eee;
width: 400rpx;
height: 400rpx;
}
button {
margin-top: 100rpx;
}
import QR from './qrcode'
Page({
data: {
canvasId: 'canvasId',
QRdata: '你好 wxmp-qrcode'
},
creatQRCode () {
let str = this.data.QRdata
let canvasId = this.data.canvasId
QR.draw(str, canvasId)
}
})
npm i wxmp-qrcode
<template>
<div class="container">
<canvas id="canvasId" canvas-id="canvasId"></canvas>
<button @tap="creatQRCode"> 生成二维码 </button>
</div>
</template>
<script>
import QR from 'wxmp-qrcode'
export default {
data () {
return {
canvasId: 'canvasId',
QRdata: '你好 wxmp-qrcode'
}
},
methods: {
creatQRCode () {
let str = this.QRdata
let canvasId = this.canvasId
QR.draw(str, canvasId)
}
}
}
</script>
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
}
canvas {
border: 1rpx solid #eee;
width: 400rpx;
height: 400rpx;
}
button {
margin-top: 100rpx;
}
</style>
npm i wxmp-qrcode
import Taro, { Component } from '@tarojs/taro'
import { View, Button } from '@tarojs/components'
import QR from 'wxmp-qrcode'
import './index.css'
export default class Index extends Component {
constructor(props) {
super(props)
this.state = {
canvasId: 'canvasId',
QRdata: '你好 wxmp-qrcode'
}
}
createQRcode = () => {
let canvasId = this.state.canvasId
let QRdata = this.state.QRdata
QR.draw(QRdata, canvasId)
}
render () {
return (
<View className='container' >
<canvas id={this.state.canvasId} canvas-id={this.state.canvasId}></canvas>
<Button onClick={this.createQRcode}> 生成二维码 </Button>
</View>
)
}
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
canvas {
border: 1rpx solid #eee;
width: 600rpx;
height: 400rpx;
}
button {
margin-top: 100rpx;
}
FAQs
QR Code Generator for wxmp
We found that wxmp-qrcode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.