微信小程序 授权登录

1.获取用户code 传入后台 

 //登录功能

    login(e){

        wx.getUserProfile({

          desc: 'desc',

          success: (res) => {

              // console.log(res.userInfo.nickName);

              //用户名

              let nick_name = res.userInfo.nickName;

              //用户头像

              let avatar_url = res.userInfo.avatarUrl;

              wx.login({

                success:ret=>{

                    let code = ret.code;

                    // console.log(code);

                    wx.request({

                        //这里url仅为实验 并非真实url

                      url: 'http://www.essou.com/index.php/api/login',

                      data:{code,nick_name,avatar_url},

                      success:result=>{

你可能感兴趣的:(微信小程序,小程序)