diff --git a/pages/index/index.js b/pages/index/index.js index 7db75a4..4e0d575 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -81,59 +81,54 @@ Page({ }, scanCodeEvent(){ var that = this; - var DEV_CODE = "34ADE4201285" + var DEV_CODE = "" //扫码代码 wx.scanCode({ onlyFromCamera: true,// 只允许从相机扫码 success(res){ console.log("扫码成功:"+JSON.stringify(res)) DEV_CODE = res.result - }, - fail (err) { - // console.log(err) - wx.showToast({ - title:'扫描失败', - icon: 'none', - duration: 1000 - }) - } - }) - - - - - var PUBLIC_KEY = "" - req.getRequest('/api/dict/value/login-public-key',{}).then((res)=>{ - if(res.data.code==200){//扫码登录成功 - PUBLIC_KEY = res.data.data - console.log(PUBLIC_KEY) - // 实例化rsa - const rsa = new WxmpRsa() - // 设置公钥 - rsa.setPublicKey(PUBLIC_KEY) - // 加密 - const mac = rsa.encryptLong(DEV_CODE) - console.log('加密后的结果:', mac) - // 此处执行登录获取token操作 - req.postRequest('/api/user/login',{'mac':mac}).then((res)=>{ - wx.setStorageSync('token', res.data.data) - console.log('token是:'+res.data.data) + var PUBLIC_KEY = "" + req.getRequest('/api/dict/value/login-public-key',{}).then((res)=>{ + if(res.data.code==200){//扫码登录成功 + PUBLIC_KEY = res.data.data + console.log(PUBLIC_KEY) + // 实例化rsa + const rsa = new WxmpRsa() + // 设置公钥 + rsa.setPublicKey(PUBLIC_KEY) + // 加密 + const mac = rsa.encryptLong(DEV_CODE) + console.log('加密后的结果:', mac) + // 此处执行登录获取token操作 + req.postRequest('/api/user/login',{'mac':mac}).then((res)=>{ + wx.setStorageSync('token', res.data.data) + console.log('token是:'+res.data.data) + wx.showToast({ + title:'扫描登录成功', + icon: 'none', + duration: 1000 + }) + wx.switchTab({ + url: '/pages/home/xy/index' + }) + } + + ) + }else{ wx.showToast({ - title:'扫描登录成功', + title:'扫码失败,请确认您的二维码是否正确!', icon: 'none', duration: 1000 - }) - wx.switchTab({ - url: '/pages/home/xy/index' - }) - } - - ) - } - console.log(res); - }).catch((err)=>{ - console.log(err); - }) + }) + } + console.log(res); + }).catch((err)=>{ + console.log(err); + }) + }, + }) + //调用RSA加密 /*wx.scanCode({