收藏
回答

微信手机号快捷登录在测试环境获取手机好成功并且能成功发送到后台,但线上环境发送不到后台,这是什么原?

 getUserInfo:function(e) {
        if (e.detail.errMsg === 'getPhoneNumber:ok') {
            wx.request({
                url'https://api.weixin.qq.com/cgi-bin/token',
                method'GET',
                data:{
                    grant_type'client_credential',
                    appid'xxxxxxxxx',
                    secret'xxxxxxxxxxxxxxxxxxx',
                },
                success:(res)=>{
                    this.access_token = res.data.access_token
                    console.log(this.access_token)
                    wx.request({
                        url'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token='+this.access_token,
                        method'POST',
                        data:{
                            code: e.detail.code
                        },
                        success:(response)=>{
                            console.log(response.data.phone_info.phoneNumber)  //获取用户手机号
                            wx.request({
                                url: getApp().globalData.http+'/small/wx_login?nickName=&phone='+response.data.phone_info.phoneNumber+'&wx_id='+ e.detail.code,
                                method'POST',
                                header: {
                                    'content-type''application/json' // 默认值
                                },
                                success:(res)=>{                                   
                                    console.log(res)
                                    if(res.data.state == 'success'){
                                        wx.showToast({title'登录成功',icon'success'});
                                        getApp().globalData.sessionID = res.data.data
                                        console.log(getApp().globalData.sessionID)
                                        wx.switchTab({url'../searchIndex/searchIndex'})    
                                    }else{
                                        if(res.data.code=='1'){wx.showToast({title'该用户不具有产品权限',icon'none'});} 
                                        if(res.data.code=='2'){wx.showToast({title'产品被禁用',icon'none'});} 
                                        if(res.data.code=='3'){wx.showToast({title'产品过期',icon'none'});}  
                                        if(res.data.code=='14'){wx.showToast({title'不在IP范围,不允许注册',icon'none'});} 
                                        if(res.data.code=='15'){wx.showToast({title'账号超过验证日期,需在IP范围内重新登录',icon'none'});}  
                                        if(res.data.code=='16'){wx.showToast({title'手机号格式错误',icon'none'});}     
                                    }
                                }
                            }) 
                        }
                    }) 
                }
            })
        }
    },
回答关注问题邀请回答
收藏

2 个回答

  • Hlxuan.
    Hlxuan.
    06-06

    api.weixin.qq.com 相关API为服务端接口,不能在小程序内调用。你要改成在服务端调用,小程序内请求你服务端的接口。

    06-06
    有用 1
    回复 3
    • 此生皆然
      此生皆然
      06-06
      也就是说小程序只获取权限,解析什么的都在后台进行,对吗?
      06-06
      回复
    • Hlxuan.
      Hlxuan.
      06-06回复此生皆然
      是的,前端获取code传给后端,后端再调用微信接口。
      06-06
      回复
    • 此生皆然
      此生皆然
      06-09
      我改成后台了,但是依然在线上请求不到后台
      06-09
      回复
  • 智能回答 智能回答 该问答由AI生成
    06-06
    有用
登录 后发表内容