调试阶段 获取微信小程序openid

时间:2022-09-13 20:00:19
wx.login({
          success: function(res) {
          //首先获取用户code
          //res.code
              wx.request({
                  url: 'https://api.weixin.qq.com/sns/jscode2session',
                  data: {
                  appid: appid,//填入你的id
                  secret: appsecret,//secret
                  js_code: res.code,
                  grant_type: 'authorization_code'
             }, 
              method: 'GET',
              success: function (res) {
                 console.log(res);//openid便会包含在这里
              },
              fail: function (res) { },
              complete: function (res) { },
            })
           
          
         },
          fail: function(res) {},
          complete: function(res) {},
        })