通过该接口生成的小程序码wxacode.getUnlimited

需求背景:当用户直接用微信扫描小程序码,需要传入不同参数进行相应的页面操作,即需要动态生成带不同参数的小程序码

wxacode.getUnlimited相关资料:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html

js代码如下

wx.request({
  //注意:下面的access_token值可以不可以直接复制使用,需要自己请求获取
	url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='+token.access_token,
	data: {
	  scene: scene,
	  page: "pages/index/index"  //这里按照需求设置值和参数   
	},
	method: "POST",
	responseType: 'arraybuffer',  //设置响应类型
	arraybuffer: true,    //转码,注意别忘了这个属性,不然会乱码
	success(res) {
	  console.log(res)
	  var imgurl ='data:image/jpeg;base64,'+ wx.arrayBufferToBase64(res.data);  //对数据进行转换操作
	  z.setData({
		imgurl
	  })
	},
	fail(e) {
	  console.log(e)
	}
})

wxml代码显示二维码 

 <image style="width:430rpx;height:430rpx" src="{{imgurl}}"></image>

 将生成的二维码用微信开发工具进行测试:选择“通过二维码编译”

在自己传入的页面"pages/index/index"用options.scene接收

 onLoad: function (options) {
    if (options.scene) {
    //options.scene必须要decodeURIComponent处理才能拿到
      let scene = decodeURIComponent(options.scene);
      //&是我们定义的参数链接方式
      console.log(scene)
    }
  },
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值