zoukankan      html  css  js  c++  java
  • 微信小程序获取手机号失败? | 邓士鹏

    1.必须先获取code
    
    在onShow中请求uni.Login({})
    
    2.
    
    <button 
    class="wrapperFooterRightBox" 
    open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">
    立即购买
    </button>
    decryptPhoneNumber(res){
                    uni.showLoading({
                        title:'登录中 ...'
                    })
                    const that = this
                    var detail = res.detail
                    
                    if (detail.errMsg != 'getPhoneNumber:ok') {
                        return
                    }
                    
                    
                    
                    
                    uni.checkSession({
                        success: (res) => {
                            const params = {
                                wechat_code:that.wxcode,
                                enData:detail.encryptedData,
                                vi:detail.iv,
                                is_scan:that.is_scan,
                            }
                            console.log(params)
                            that.$myRequest.globalRequest(that.$myRouteApi._wxLogin, params, 'POST')
                            .then((res)=>{
    
                                        console.log(res)
                                        const data = res.data
                                        console.log(data)
                                        uni.setStorageSync('access_token', data.access_token);
                                        uni.setStorageSync('refresh_token', data.refresh_token);
                                        that.is_login = 1
                                        uni.hideLoading()
                                        //    从新模拟点击
                                        that.onClickSubmit()
                                        
                                        // that.$myApi.getUserFindApi()
     
                            })
                        },
                        fail: (res) => {
                            uni.login({
                              provider: 'weixin',
                              success: function (loginRes) {
                                  const params = {
                                    wechat_code:loginRes.code,
                                    enData:detail.encryptedData,
                                    vi:detail.iv,
                                    is_scan:that.is_scan,
                                  }
                                  console.log(params)
                                  that.$myRequest.globalRequest(that.$myRouteApi._wechatLogin, params, 'POST')
                                  .then((res)=>{
    
                                        console.log(res)
                                        const data = res.data
                                        console.log(data)
                                        uni.setStorageSync('access_token', data.access_token);
                                        uni.setStorageSync('refresh_token', data.refresh_token);
                                        that.is_login = 1
                                        uni.hideLoading()
                                        //    从新模拟点击
                                        that.onClickSubmit()
                                        
                                        that.$myApi.getUserFindApi()
    
                                          
                                  })
                                  
                                  
                              }
                            })
                                
                                
                        }
                    })
                      
  • 相关阅读:
    学习完vue指令 做的一个学生信息录入系统
    vue常用指令总结
    vue介绍以及相关概念理解大全
    class类
    javascript闭包详解
    前端必看网站(一直更新中)
    微信小程序wx.getUserInfo获取用户信息
    微信小程序自定义组件注意事项
    微信小程序自定义选项卡
    uni-app开发注意事项及常用样式
  • 原文地址:https://www.cnblogs.com/vip-deng-vip/p/13299026.html
Copyright © 2011-2022 走看看