<address id="r9vd9"><address id="r9vd9"><listing id="r9vd9"></listing></address></address>

      歡迎您光臨深圳塔燈網絡科技有限公司!
      電話圖標 余先生:13699882642

      網站百科

      為您解碼網站建設的點點滴滴

      解析并截取小程序二維碼上的參數(轉載)

      發表日期:2019-11 文章編輯:小燈 瀏覽次數:12170

      小程序分享二維碼思路:
      a分享二維碼給b,二維碼上帶有a的標識ppid
      b接收a的二維碼打開頁面,將接收到的ppid傳遞給后臺,后臺就可以知道b是通過a的二維碼打開的頁面

      1.在后臺設置識別二維碼進入的頁面,這里用index頁面。
      2.在index頁面是接收二維碼里面的參數,解析并截取獲取。二維碼的參數格式:scene=ppid:12

      export default {
          data() {
              return {
                  ppid: "",
              }
          },
          onLoad(option) {
              // 解析二維碼里面的參數獲得ppid
              this.ppid = this.scene_decode(decodeURIComponent(option.scene)).ppid //封裝的scene_decode() 方法
              if(this.ppid) {
              //我這里是把ppid存進vuex,然后在b注冊時,把ppid傳給后臺
                  this.saveppid(this.ppid)// ppid 存進vuex
              }
          },
          methods: {
          // 截取ppid的方法
              scene_decode(scene) {
                  var _str = scene + "";
                  var _str_list = _str.split(",");
                  var res = {};
                  for (var i in _str_list) {
                      var _tmp_str = _str_list[i];
                      var _tmp_str_list = _tmp_str.split(":");
                      if (_tmp_str_list.length > 0&&_tmp_str_list[0]) {
                          res[_tmp_str_list[0]] = _tmp_str_list[1] || null;
                      }
                  }
                  return res;
              }
          }
      }

      vuex里面存ppid的方法

      import Vue from 'vue'
      import Vuex from 'vuex'
      
      Vue.use(Vuex)
      
      const store = new Vuex.Store({
          state: {
              ppid: '',
          },
          mutations: {
              // 二維碼ppid
              saveppid(state,ppid) {
                  state.ppid = ppid
                  uni.setStorage({
                      key: 'ppid',
                      data: ppid
                  })
                  // console.log(state.ppid)
              },
          },
      })
      
      export default store

      3.b登陸注冊時,從vuex里面取出ppid傳給后臺

      _getuserinfo(res) {
          console.log(store.state.ppid)
          var that = this
          var userinfoDetails = {}
          userinfoDetails = res.detail.userInfo
          uni.getUserInfo({
            provider: 'weixin',
            success: function () {
              uni.login({
                  success:function(res){
                      uni.showLoading({
                          title: '登陸中...',
                          mask: false
                      });
                      uni.request({
                          url: that.apiUrl + 'small/index/GetOpenid?code=' + res.code,
                          success: (res) => {
                              console.log(res)
                              if (res.data.openid) {
                                  uni.setStorageSync('openid', res.data.openid)
                                  userinfoDetails.openid = res.data.openid
                                  //store.state.ppid取ppid,然后賦值給userinfoDetails.ppid
                                  userinfoDetails.ppid = store.state.ppid || ''
                              }
                              if(res.data.status == 0) {
                                  that.sendInfo(userinfoDetails) // 用戶還沒注冊過需調用此方法
                                  console.log('我還沒有注冊')
                              } else if (res.data.status == 1) {
                                  uni.showToast({
                                      title: '登錄成功',
                                      icon: 'success',
                                      duration: 2000
                                  })
                                  that.getUserData() // 調用獲取用戶信息的接口
                              } else {
                                  uni.hideLoading()
                                  uni.showToast({
                                      title: '登錄失敗',
                                      duration: 2000,
                                      icon:'none'
                                  })
                              }
                          }
                      })
                  }
              })
            }
          });
      },
      sendInfo(userinfoDetails) {
          var that = this
          uni.request({
              url: this.apiUrl + 'small/index/insertvip', //注冊接口
              data: userinfoDetails,
              method: 'POST',
              success: (res) => {
                  if(res.data.userinfo == 1) {
                      uni.hideLoading()
                      uni.showToast({
                          title: '注冊成功',
                          icon: 'success',
                          duration: 2000
                      })
                      that.getUserData() // 調用獲取用戶信息的接口
                  } else {
                      uni.hideLoading()
                      uni.showToast({
                          title: res.data.msg,
                          duration: 2000
                      })
                  }
              }
          })
      },

      本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶學習參考,本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.webpost.com.cn/25262.html
      相關小程序
       八年  行業經驗

      多一份參考,總有益處

      聯系深圳網站公司塔燈網絡,免費獲得網站建設方案及報價

      咨詢相關問題或預約面談,可以通過以下方式與我們聯系

      業務熱線:余經理:13699882642

      Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.    

      国产成人精品综合在线观看