有人窃斧者
有人窃斧者
  • 发布:2022-01-12 17:11
  • 更新:2022-01-13 22:50
  • 阅读:704

uni-app项目转为H5项目,session一直变化导致登录不了

分类:uni-app

uni-app项目转为H5项目时,调用登录接口,response-header的session与获取验证码接口时获取的session不一致,导致虽然输入正确的验证码,登录接口仍会报验证错误,且点击验证码刷新时,每次接口的session都会变化

下面是封装的部分请求

const Request = (url, method = 'GET', params, contentType = 1) => {  
    let token = uni.getStorageSync('token')  
    let cookie = uni.getStorageSync('cookie')  
    // console.log(state)  
    let header = {  
        'Content-Type': contentType === 1 ? 'application/json' : 'application/x-www-form-urlencoded',  
        'Set-Cookie': token,  
        // 'Cookie': token  
    }  
    if (method == 'GET') {  
        url = url + formatGetUri(params)  
    }  
    // console.log(url)  
    return new Promise((resolve, reject) => {  
        uni.request({  
            url:baseUrl + url,  
            data: method == 'GET' ? {} : params,  
            method: method,  
            header: header,  
            timeout: 1000000,  
            success: (res) => {  
                 // console.log(res)  
                 store.dispatch('setErrState',true)  
                store.dispatch('setBtnLoading',false)  
                if (res.statusCode==200) {  
                    if(res.data.success){  
                        resolve(res.data.data)  
                    }else{  
                        if(res.data.errorMessage||res.data.message){  
                            uni.showToast({  
                                icon: 'none',  
                                title: res.data.errorMessage||res.data.message  
                            });  
                        }  
                        resolve(res.data)  
                        store.dispatch('setErrState',false)  
                        store.dispatch('log', {  
                            url: url,  
                            time: new Date(),  
                            res  
                        })  
                    }  

                } else {  
                    store.dispatch('log', {  
                        url: url,  
                        time: new Date(),  
                        res  
                    })  
                    if(res.data.resultCode=='A00003'){  
                        uni.setStorageSync('token','')  
                        utils.router('login',null,3)  
                    }else{  
                        uni.showToast({  
                            icon: 'none',  
                            title: '服务异常,请稍后再试'  
                        });  
                    }  
                }  
            },  
            fail: (err) => {  
                console.log('request fail', err)  
                store.dispatch('setBtnLoading',false)  
                reject(err)  
                uni.showToast({  
                    icon: 'none',  
                    title: '服务连接异常,请稍后再试'  
                });  
            }  
        })  
    })  
}  
2022-01-12 17:11 负责人:无 分享
已邀请:
小枫叶

小枫叶 - 外包接单加v:wlmk1234567 注明来意

是存到本地的数据跟着变化么?有没有考虑是后端返给你的问题i呢

有人窃斧者

有人窃斧者 (作者)

pc端后台和app前端都对应同一个后端工程,pc端前端点击验证码刷新时这个session不会变化,到了uni-app-->H5时,这个session会变化,是不是前端哪里写法出了问题

小枫叶

小枫叶 - 外包接单加v:wlmk1234567 注明来意

看是否附带了其他请求,验证码应该只是一个单独的接口才可以吧

该问题目前已经被锁定, 无法添加新回复