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

          網站百科

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

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

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

          小程序分享二維碼思路:
          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.cjxv.cn/25262.html
          相關小程序
           八年  行業經驗

          多一份參考,總有益處

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

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

          業務熱線:余經理:13699882642

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

          主站蜘蛛池模板: 人妻免费一区二区三区最新| 538国产视频| 人人洗澡人人洗澡人人| 欧美精品九九99久久在免费线| 六月丁香激情综合成人| 国产美女自慰在线观看| 无码囯产精品一区二区免费| 欧美三级电影在线| 理论片中文字幕在线观看| 色香蕉在线观看网站| 香蕉视频国产在线观看| 美女把腿扒开让男人桶免费| 在线拍揄自揄在线播放| 久久精品女人天堂av免费观看| 精品国产一区二区三区av片| 国产精品一区二区久久精品涩爱| 中文字幕三级在线不卡| 欧美性大战xxxxx久久久| 啊灬啊灬啊灬快灬深用力| 1卡二卡三卡四卡在线播放| 色噜噜狠狠色综合免费视频| 成人在线手机视频| 亚洲午夜电影一区二区三区| 老司机久久影院| 大陆年轻帅小伙飞机gay| 久久精品国产99精品最新| 特黄特色大片免费播放路01 | 精品久久久久久亚洲综合网| 国产精品亚洲片在线| 亚洲综合无码AV一区二区| 2021久久精品国产99国产精品| 日韩三级中文字幕| 叶山豪是真吃蓝燕奶| a级日本高清免费看| 自拍另类综合欧美小说| 国产后入清纯学生妹| 亚洲精品熟女国产| 亚洲综合丁香婷婷六月香| 欧美日韩精品一区二区三区视频在线| 四虎影视永久在线观看| 另类视频区第一页|