• <ul id="cgeq2"></ul>
  • 歡迎您光臨深圳塔燈網(wǎng)絡(luò)科技有限公司!
    電話圖標(biāo) 余先生:13699882642

    網(wǎng)站百科

    為您解碼網(wǎng)站建設(shè)的點點滴滴

    解析并截取小程序二維碼上的參數(shù)(轉(zhuǎn)載)

    發(fā)表日期:2019-11 文章編輯:小燈 瀏覽次數(shù):12206

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

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

    export default {
        data() {
            return {
                ppid: "",
            }
        },
        onLoad(option) {
            // 解析二維碼里面的參數(shù)獲得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) // 用戶還沒注冊過需調(diào)用此方法
                                console.log('我還沒有注冊')
                            } else if (res.data.status == 1) {
                                uni.showToast({
                                    title: '登錄成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                                that.getUserData() // 調(diào)用獲取用戶信息的接口
                            } 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() // 調(diào)用獲取用戶信息的接口
                } else {
                    uni.hideLoading()
                    uni.showToast({
                        title: res.data.msg,
                        duration: 2000
                    })
                }
            }
        })
    },

    本頁內(nèi)容由塔燈網(wǎng)絡(luò)科技有限公司通過網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶學(xué)習(xí)參考,本站不擁有所有權(quán),如您認為本網(wǎng)頁中由涉嫌抄襲的內(nèi)容,請及時與我們聯(lián)系,并提供相關(guān)證據(jù),工作人員會在5工作日內(nèi)聯(lián)系您,一經(jīng)查實,本站立刻刪除侵權(quán)內(nèi)容。本文鏈接:http://www.juherenli.com/25262.html
    相關(guān)小程序
     八年  行業(yè)經(jīng)驗

    多一份參考,總有益處

    聯(lián)系深圳網(wǎng)站公司塔燈網(wǎng)絡(luò),免費獲得網(wǎng)站建設(shè)方案及報價

    咨詢相關(guān)問題或預(yù)約面談,可以通過以下方式與我們聯(lián)系

    業(yè)務(wù)熱線:余經(jīng)理:13699882642

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

    精品乱码久久久久久中文字幕 | 国产一精品一AV一免费孕妇| 久久精品成人免费观看97| 无码国内精品久久综合88| 国产区精品一区二区不卡中文| 国产精品嫩草影院线路| 91精品国产91热久久久久福利| 自拍偷在线精品自拍偷| 久久亚洲av无码精品浪潮| 日韩国产精品亚洲а∨天堂免| 久热青青青在线视频精品| 国产精品午夜免费观看网站| 久久久无码精品午夜| 久久亚洲精品无码VA大香大香| 韩日美无码精品无码| 国产免费69成人精品视频| 国产精品扒开腿做爽爽爽视频| 一区二区日韩国产精品| 亚洲精品无码成人| 亚洲精品第一国产综合精品| 国产AV午夜精品一区二区三区| 精品成人一区二区三区四区| 国产精品无码免费视频二三区| 久久亚洲精品国产精品婷婷| 97精品人人妻人人| 九九在线观看精品视频6| 中文无码精品A∨在线观看不卡| 久久精品九九亚洲精品| 国产精品三级国产电影| 国产综合免费精品久久久| 无码国模国产在线无码精品国产自在久国产 | 久久99热久久99精品| 国产cosplay精品视频| 精品无码日韩一区二区三区不卡 | 2022国产成人精品福利网站| 国产成人精品免费久久久久| 97人妻精品全国免费视频| 国产成人精品大尺度在线观看| 国产精品久久久久9999| 91精品国产入口| 91精品国产闺蜜国产在线闺蜜|