收藏
回答

request:fail invalid url ""

框架类型 问题类型 操作系统 工具版本
小程序 Bug Windows 1.02.1807120

我http,https也加了,也取消了“使用系统代理”,开发者工具也重启了。。为什么还是报错。

//app.js
App({
  d: {
    ceshiUrl: `https://127.0.0.1/dyxcx/public/index.php`,
    userId: 0,
    appId: "*************",
    appKey: "*************"
  },
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    this.getUserInfo();
  },
 
  getUserInfo: function(cb){
    var that = this;
    if (that.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function(res){
          var code = res.code;
          //查看是否授权
          wx.getSetting({
            success: function(res){
              if (res.authSetting['scope.userInfo']){
                 // 已经授权,可以直接调用 getUserInfo 获取头像昵称
                 wx.getUserInfo({
                   success: function(res){
                     that.globalData.userInfo = res.userInfo;
                     typeof cb == "function" && cb(that.globalData.userInfo);
                     //get user sessionKey
                     //get sessionKey
                     //再判断执行支付管理
                     that.getUserSessionKey(code);
                   }
                 })
              }
            },
            fail: function(e){
              console.log(111);
            }
          });
        },
      });
    }
  },
  getUserSessionKey: function(code){
    //用户订单状态
    var that = this;
    wx.request({
      url: that.d.ceshiUrl + '/Api/Login/getsessionkeys',
      method: 'post',
      data: {
        code : code
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function(res){
        var data = res.data;
        if(data.status == 0){
          wx.showToast({
            title: data.err,
            duration: 2000
          });
          return false;
        }
 
         
        that.globalData.userInfo['sessionId'] = data.session_key;
        that.globalData.userInfo['openid'] = data.openid;
        //将openid存入授权的用户
        that.onLoginUser();
      },
      fail: function(e){
        wx.showToast({
          title: '网络异常!err:e',
          duration: 2000
        });
      }
    })
  },
  onLoginUser: function(){
    var that = this;
    var user = that.globalData.userInfo;
    wx.request({
      url: that.d.ceshiUrl + '/Api/Login/authlogin',
      method: 'post',
      data: {
 
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function(res){
          console.log(111);
      }
    });
  },
  globalData: {
    userInfo: null
  }
})


回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容