小程序受權登陸

小程序受權登陸

<button class="l_btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="bindGetUserInfo" @click="getUserInfoClick">微信登陸 </button>小程序

getUserInfoClick() {}, //不要刪除
            bindGetUserInfo: function (e) {
                var that = this;
                var sessionId  =  wx.getStorageSync("sessionId");
                if (e.mp.detail.userInfo) {
                    var userInfo = e.mp.detail.userInfo;
                    userInfo.encryptedData = e.mp.detail.encryptedData;
                    userInfo.iv = e.mp.detail.iv;
                    wx.setStorageSync("userInfo", userInfo);
                    wx.switchTab({
                        url: "/pages/home/main"
                    });
                } else {
                    wx.showModal({
                        content: '請容許使用微信登陸',
                        confirmText: "確認",
                        cancelText: "取消",
                        success: function (res) {
                            //點擊「確認」時打開設置頁面
                            if (res.confirm) {
                                wx.openSetting({
                                    success: (data) => {
                                        if (data.authSetting["scope.userInfo"] == true){
                                            wx.getUserInfo({
                                                // withCredentials: false,
                                                lang:"zh_CN",
                                                success: function (datares) {
                                                    var userInfo = datares.userInfo;
                                                    userInfo.encryptedData = datares.encryptedData;
                                                    userInfo.iv = datares.iv;
                                                    wx.setStorageSync("userInfo", userInfo);
                                                        wx.switchTab({
                                                            url: "/pages/home/main"
                                                        });
                                                }})
                                        }
                                    }
                                })
                            } else {
                                console.log('用戶點擊取消')
                            }
                        }
                    });
                }
            },
相關文章
相關標籤/搜索