获取手机号偶尔会失败?
发布于 6 年前 作者 yongyu 10121 次浏览 来自 官方Issues

getPhoneNumber(e) {

            let vm = this

            wx.login({

                success: (res=> {

                    let code = res.code

                    // wx.setStorageSync('code', code)

                    if (e.detail.iv) {

                        let data = {

                            code: code,

                            iv: e.detail.iv,

                            from_openid: wx.getStorageSync('user_id'),

                            encryptedData: e.detail.encryptedData

                        }

                        vm.$showLoading('手机号获取中...')

                        vm.$post({url: `${service.host}/wechat`data}, {

                        success: ({codedata}) => {

                            let {phoneNumberunionidopenid} = data

                            vm.hideModal()

                            wx.navigateTo({

                                url: `/pages/userInfo/basicData?phoneNumber=${phoneNumber}&unionid=${unionid}&openid=${openid}`

                            })

                            vm.$apply()

                            wx.setStorageSync('openid'data.openid)

                            wx.hideLoading()

                        }

                        })

                    }

                },

                fail: (res=> {

                    wx.showToast({

                        title: '获取手机号失败',

                        icon: 'error',

                        duration: 2000

                    })

                }

            })

        },

尝试过很多办法,都无法解决,求各位大佬帮忙。。

2 回复

别在getPhoneNumber回调里调wx.login

onLoad里调用wx.login,code有效期5分钟,可以用 setInterval 来刷新code

回到顶部