app内扫码执行内部逻辑,app外扫码下载app

最开始的想法是写个html,挂到外网,在html中写下载逻辑

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>App下载</title>
</head>
<body>
</body>
<script>
    window.open('www.demo.com/demo.apk);
</script>

app文件网络地址 www.demo.com/demo.apk

html本身地址 www.demo.com/test.html

生成的二维码链接 则是 www.demo.com/test.html?id=1

如果是浏览器扫码便会执行js也就是会下载文件,而app只是会返回www.demo.com/test?id=1这样的一个链接,我只需要解析链接读取后面的参数就行。

后面想了一下不对啊,我不需要写html文件,直接把app所需要的参数拼接到 www.demo.com/demo.apk后面就行,而效果跟上面写个html的效果一样

所以最后二维码生成了链接就成了 www.demo.com/demo.apk?id=1

附上相关代码 (uniapp)

    methods: {
      // 扫一扫
      scanCode () {
        uni.scanCode({
          scanType: ['qrCode'],
          success: (res) => {
            try {
              console.log('res :>> ', res.result);
              const id= res.result.split('id=')[1]
              // id不能为空以及要为数字
              if (!(id&& id> 0)) return uni.showToast({ title: '二维码不合法', icon: "none" })
              const params = {
                id
              }
              Api(params).then(res => {
                ..
              })
            } catch (e) {
              console.log('e :>> ', e);
              uni.showToast({ title: '二维码不合法', icon: "none" })
            }
          }
        })
      },
}

uniapp生成二维码 生成二维码

猜你喜欢

转载自blog.csdn.net/weixin_49070128/article/details/127899077