授权登录

作者: web小哥MrYang | 来源:发表于2019-04-11 09:24 被阅读0次

    getUserInfoFun: function (e) {

        if (e == undefined) {

        } else {

          if (e.detail.errMsg == "getUserInfo:ok") {

            var S = this;

            wx.getUserInfo({

              success: function (res) {

                app.information.personInfo = res;

                S.showPrePage();

              }

            })

            app.information.userInfo = e.detail.userInfo

          } else {

          }

        }

      },

      showPrePage: function (e) {

        var utilMd5 = require('../../utils/util.js');

        var that = this;

        var timestamp = Date.parse(new Date());

        timestamp = timestamp / 1000;

        var password = utilMd5.hexMD5(app.information.code + timestamp);

        wx.request({

          url: '' + app.information.host + '/api/json/member/member.ashx?action=otherlogin&companyid=' + app.information.companyid+'&code=' + password + '&timestamp=' + timestamp + '&type=wxlogin&openid=' + app.information.openid + '&nickname=' + app.information.userInfo.nickName + '&sex=' + app.information.userInfo.gender + '&headimgurl= ' + app.information.userInfo.avatarUrl,

          header: {

            'content-type': 'application/json',

          },

          //存储cookie

          success: res => {

            console.log(res)

            if (res.header["Set-Cookie"].length > 200) {

              app.information.cookie = res.header["Set-Cookie"];

              that.setData({

                eye: "0",

              })

              var e={id:that.data.id}

              that.onLoad(e),

              wx.showToast({

                // 提示内容

                title: "登录成功",

                icon: "none",

                duration: 2000,

                mask: false,

              })

            } else {

              wx.showToast({

                // 提示内容

                title: "登录失败",

                icon: "none",

                duration: 2000,

                mask: false,

              })

            }

          },

        });

      },

    <view style='display:{{eye==1?"flex":"none"}}' class='jiazai'>

      <button class='dl_xx' open-type="getUserInfo" bindgetuserinfo="getUserInfoFun">登录</button>

    </view>

    .jiazai{width: 100vw;height: 100vh;position: fixed;z-index: 99;background: rgba(0,0,0,0)}

    .jiazai button{border-radius: 0;border: none;width: 80vw;height: 13.33vw;position: fixed;bottom: 0;right: 0;background: #FF302D;line-height: 14vw;color: #fff;font-size: 4vw;font-weight: 600}

    相关文章

      网友评论

        本文标题:授权登录

        本文链接:https://www.haomeiwen.com/subject/jojqbqtx.html