收藏
回答

如何在小程序端接收App传过来的参数

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 需求 微信安卓客户端 8.0.21 2.23.4

在App端支付时需要跳转小程序支付并将订单号传过来 path: "/pages/purchaser/adapay/adapay?orderNum=" + this.orderNum + '&TOKEN=' + token, 可以正常跳转 参数也正常传过来了, 但是在小程序不知道怎么接收,是要在adapay页面的onLoad接收吗

回答关注问题邀请回答
收藏

2 个回答

  • 胃里养了只霸王龙
    胃里养了只霸王龙
    2022-04-21
    // app.js
    onLaunch(options) {
        console.log('onLaunch', options)
        this.globalData.query = options.query || {}
        if (options.referrerInfo) {
          this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
        }
      },
      onShow(options) {
        console.log('onShow', options)
        if (Object.keys(options.query).length > 0) {
          // 解决连续扫两次带参数的码,参数丢失的问题
          this.globalData.query = options.query || {}
          // 处理通过小程序码进来的参数,包括渠道码等,放置到全局数据中
          if (options.query.scene) {
            let queryObj = {}
            var strs = decodeURIComponent(options.query.scene).split('&') //以&分割
            for (var i = 0; i < strs.length; i++) {
              queryObj[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
            }
            Object.assign(this.globalData.query, queryObj)
          }
        }
        if (options.referrerInfo) {
          this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
        }
      },
    globalData: {
      query: {}
    }
    


    // 页面js
    onLoad(options) {
      this.setData({
         参数名: options.参数名 || app.globalData.query.参数名 || ''
      })
    }
      
    
    2022-04-21
    有用 1
    回复
  • 拾忆
    拾忆
    2022-04-21

    是的

    2022-04-21
    有用
    回复 2
    • 山川.
      山川.
      2022-04-21
      直接用 this.orderNum = option.orderNum   this.TOKEN = option.TOKEN,  但是好像没接收到,接口没请求  然后页面上面页没显示,我是用的uniapp写的这个处理页面  然后转的小程序
      2022-04-21
      回复
    • 拾忆
      拾忆
      2022-04-21回复山川.
      在开发者工具中添加编译模式时候输入相同参数,然后打印option测试。
      2022-04-21
      回复
登录 后发表内容