当前位置:   article > 正文

[uni-app] 小程序码转为二维码, 小程序解析此码获取数据

[uni-app] 小程序码转为二维码, 小程序解析此码获取数据

小程序码缩小后太细, 不好扫, 还是改成二维码扫

记录解析该二维码

	onLoad(e) {
			if (e.shareTimeline) { // 以单页面启动-朋友圈分享出的单页面
				this.shareTimeline = e.shareTimeline;
				let param = {
					certId: e.certId,
					uid: e.uid,
					unionid: e.unionid,
					openid: e.openid,
				}
				this.initData(param)
			} else if (e.scene) { // 以小程序码扫码方式启动, - 目前图片都是放的二维码,可能不走
				const scene = decodeURIComponent(e.scene)
				let sceneArr = scene.split("=")
				let param = {
					certId: sceneArr[1]
				}
				this.initData(param)
			} else if (e?.q) { // 以小程序码转换为二维码的方式启动, 解析q对象
				const q = decodeURIComponent(e.q) // 获取到二维码原始链接内容
				// const scancode_time = parseInt(e.scancode_time) // 获取用户扫码时间 UNIX 时间戳
				let cert_id = this.$cjs.getUrlSingleParam('cert_id', q) //调用工具函数获取url中传递的参数
				let param = {
					certId: cert_id
				}
				this.initData(param)
			} else { // 以小程序/APP的应用内跳转 进入的,直接取路由参数
				let param = e;
				this.initData(param)
			}

		},

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

直接看第三个else
e.q 就是扫码后, 必须接受的参数, 也是判断依据

getUrlSingleParam

export let getUrlSingleParam = function (key, url = location.search) {
  const reg = new RegExp("(\\?|&)" + key + "=([^&]*)(&|$)");
  const r = url.match(reg);
  if (r != null) {
    return r[2];
    // return unescape(r[2]);//unescape函数显示已经废弃
  }
  return null;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

具体看这个:enter>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/249540
推荐阅读
相关标签
  

闽ICP备14008679号