E企盈营销工具技术服务商 热线:4006-838-530

微信小程序php后台温州E企盈小程序实现

这里简单介绍用php后台实现获取openid并保存到数据库;

微信的登陆流程是这样的 首先前端发送请求到服务器:wx.login({        success: function (res) {          var code = res.code;//发送给服务器的code          wx.getUserInfo({            success: function (res) {              var userNick = res.userInfo.nickName;//用户昵称              var avataUrl = res.userInfo.avatarUrl;//用户头像地址              var gender = res.userInfo.gender;//用户性别              if (code) {                wx.request({                  url: 'http://localhost/test/getopenid.php',//服务器的地址,现在微信小程序只支持https请求,所以调试的时候请勾选不校监安全域名                  data: {                    code: code,                    nick: userNick,                    avaurl: avataUrl,                    sex: gender,                  },                  header: {                    'content-type': 'application/json'                  },                  success: function (res) {                    console.log(res.data);                    wx.setStorageSync('name', res.data.name);//将获取信息写入本地缓存                    wx.setStorageSync('openid', res.data.openid);                    wx.setStorageSync('imgUrl', res.data.imgurl);                    wx.setStorageSync('sex', res.data.sex);                  }                })              }              else {                console.log("获取用户登录态失败!");              }            }          })        },        fail: function (error) {          console.log('login failed ' + error);        }})    

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏