小程序二维码生成

javascript 复制代码
const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid: any, fields: any) => {
        if (valid) {
            console.log(ruleForm)
            getToken({ act: 'miniprogram', op: 'getAccessToken', type: ruleForm.name }).then((res: any) => {
                const ACCESS_TOKEN = res.data.token
                // 根据选择循环生成多张
                selectData[0].children.forEach((element: { children: any; label: any; value: any }) => {
                    console.log(element.children[0].value)
                    const params = {
                        scene: element.children[0].value,
                        page: ruleForm.page,
                        width: 430,
                        env_version: 'develop',
                    }
                    const label = element.label
                    generateMiniProgramQR(params, ACCESS_TOKEN, label)
                })
            })
        } else {
            console.log('error submit!', fields)
        }
    })
}
javascript 复制代码
const generateMiniProgramQR = async (
    params: { scene: any; page?: any; width?: number; label?: any },
    ACCESS_TOKEN: any,
    label: any
) => {
    try {
        const url = `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${ACCESS_TOKEN}`
        const response = await axios.post(url, params, { responseType: 'arraybuffer' })
        const blob = new Blob([response.data], { type: 'image/jpeg' })
        const imageUrl = URL.createObjectURL(blob)
        const link = document.createElement('a')
        link.href = imageUrl
        link.download = `${label}.jpg`
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
        URL.revokeObjectURL(imageUrl)
    } catch (error) {
        // 错误处理
    }
}
相关推荐
徐礼昭|商派软件市场负责人1 天前
从“多、老、旧”到“4i焕新”:品牌官方商城(小程序/官网/APP···)的范式跃迁与增长再想象
小程序·商城系统·零售
胡西风_foxww1 天前
微信小程序转Vue2组件智能提示词
微信小程序·小程序·提示词·智能体·vue2组件
七七软件开发1 天前
一对一交友小程序 / APP 系统架构分析
java·python·小程序·系统架构·php
2501_916007471 天前
iPhone查看App日志和系统崩溃日志的完整实用指南
android·ios·小程序·https·uni-app·iphone·webview
说私域2 天前
基于开源链动2+1模式AI智能名片S2B2C商城小程序的私域流量拉新策略研究
人工智能·小程序·开源
2501_915918412 天前
iOS 抓不到包怎么办?全流程排查思路与替代引导
android·ios·小程序·https·uni-app·iphone·webview
七七软件开发2 天前
团购商城 app 系统架构分析
java·python·小程序·eclipse·系统架构·php
七七软件开发2 天前
打车小程序 app 系统架构分析
java·python·小程序·系统架构·交友
说私域2 天前
从渠道渗透到圈层渗透:开源链动2+1模式、AI智能名片与S2B2C商城小程序的协同创新路径研究
人工智能·小程序·开源
一匹电信狗3 天前
【Linux我做主】进程优先级
linux·运维·服务器·c++·ubuntu·小程序·unix