微信小程序生成各种类型的二维码
二维码分享设计
微信接口
1、getQRCode 获取小程序码
该接口用于获取小程序码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制,详见获取小程序码。
POST
https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
2、getUnlimitedQRCode 获取不限制的小程序码
该接口用于获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
POST
https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN
3、createQRCode 获取小程序二维码
获取小程序二维码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制,详见获取二维码。
POST
https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
前端
二维码展示
<!-- 底部二维码区域 -->
<view class="qrcode-section">
<view class="qrcode-container">
<image :src="'data:image/png;base64,'+detailInfo.qrCode" class="qrcode-img" mode="widthFix" />
<text class="qrcode-text">扫描二维码查看钱币详情</text>
</view>
<!-- 新增分享按钮 open-type="share"-->
<u-button class="share-btn" @click="handleShare" open-type="share">
<u-icon name="share" :color="themeColor" size="44"></u-icon>
<text class="share-text">分享给朋友</text>
</u-button>
</view>
二维码接口调用
// 获取二维码数据
method:
async getQrCode(auctionId, envVersion) {
const res = await request.request('shareQrcode', {
auctionId,
envVersion
}, 'GET')
if (res.code === 200 && res.data.length > 0) {
// this.detailInfo.qrCode = res.data
this.$set(this.detailInfo, 'qrCode', res.data)
// console.log(this.detailInfo.qrCode);
}
},
二维码扫码回调
async onLoad(options) {
// 处理扫码进入的场景
if (options.scene) {
console.l