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