diff --git a/src/store/modules/imouPlayerToken.js b/src/store/modules/imouPlayerToken.js index 9f556c3..0041c95 100644 --- a/src/store/modules/imouPlayerToken.js +++ b/src/store/modules/imouPlayerToken.js @@ -1,4 +1,11 @@ +import CryptoJS from 'crypto-js'; import { getAccessToken, getKitToken } from '@/api/imouPlayerApi'; // 部门 +import modal from '@/plugins/modal'; + +let imouUser = { + appId: 'lc9878202a35844ac8', + appSecret: 'd87fe493037a47669c0ea5ffdaeae0', +}; let accessParam = { system: { @@ -17,18 +24,75 @@ return { kitToken: '', access_token: '', + msg: '', }; }, - actions: {}, + actions: { + getAccess() { + let paramsVal = changeParams(accessParam, imouUser.appId, imouUser.appSecret); + getAccessToken(paramsVal).then(res => { + // console.log('access_token', res.result.data.accessToken); + this.access_token = res.result.data.accessToken; + }); + }, + getKit(val) { + let paramsVal = changeParams(accessParam, imouUser.appId, imouUser.appSecret); + paramsVal.params = val; + getKitToken(paramsVal).then(res => { + console.log('kitToken', res.result); + if (res.result.code == '0') { + this.kitToken = res.result.data.kitToken; + this.msg = res.result.msg; + } else if (res.result.code == 'OP1009') { + modal.msgWarning('设备未被当前用户绑定'); + this.msg = res.result.msg; + } + // this.kitToken = res.result.data.kitToken; + }); + }, + + clear_kit() { + this.kitToken = ''; + }, + }, persist: { enabled: true, // 自定义持久化参数 strategies: [ { storage: sessionStorage, - paths: ['deptList', 'systemDeptList', 'userList'], + paths: ['kitToken', 'access_token', 'msg'], }, ], }, }); export default useImouPlayerStore; + +function changeParams(params, appId, appSecret) { + params.system.appId = appId; + var timestamp = getTime(); + // pm.environment.set('time', timestamp); + params.system.time = timestamp; + var nonce = Math.random().toString(36).substr(2); + // pm.environment.set('nonce', nonce); + params.system.nonce = nonce; + // var appSecret = pm.environment.get('appSecret'); + var sign = calcSign(timestamp, nonce, appSecret); + // pm.environment.set('sign', sign); + params.system.sign = sign; + var id = Math.floor(Math.random() * (50 - 1 + 1) + 1); + // pm.environment.set('id', id); + params.id = id; + return params; +} + +function getTime() { + var timestamp = Math.round(new Date().getTime() / 1000); + return timestamp; +} + +function calcSign(timestamp, nonce, appSecret) { + var str = 'time:' + timestamp + ',nonce:' + nonce + ',appSecret:' + appSecret; + var sign = CryptoJS.MD5(str).toString(); + return sign; +} diff --git a/src/store/modules/imouPlayerToken.js b/src/store/modules/imouPlayerToken.js index 9f556c3..0041c95 100644 --- a/src/store/modules/imouPlayerToken.js +++ b/src/store/modules/imouPlayerToken.js @@ -1,4 +1,11 @@ +import CryptoJS from 'crypto-js'; import { getAccessToken, getKitToken } from '@/api/imouPlayerApi'; // 部门 +import modal from '@/plugins/modal'; + +let imouUser = { + appId: 'lc9878202a35844ac8', + appSecret: 'd87fe493037a47669c0ea5ffdaeae0', +}; let accessParam = { system: { @@ -17,18 +24,75 @@ return { kitToken: '', access_token: '', + msg: '', }; }, - actions: {}, + actions: { + getAccess() { + let paramsVal = changeParams(accessParam, imouUser.appId, imouUser.appSecret); + getAccessToken(paramsVal).then(res => { + // console.log('access_token', res.result.data.accessToken); + this.access_token = res.result.data.accessToken; + }); + }, + getKit(val) { + let paramsVal = changeParams(accessParam, imouUser.appId, imouUser.appSecret); + paramsVal.params = val; + getKitToken(paramsVal).then(res => { + console.log('kitToken', res.result); + if (res.result.code == '0') { + this.kitToken = res.result.data.kitToken; + this.msg = res.result.msg; + } else if (res.result.code == 'OP1009') { + modal.msgWarning('设备未被当前用户绑定'); + this.msg = res.result.msg; + } + // this.kitToken = res.result.data.kitToken; + }); + }, + + clear_kit() { + this.kitToken = ''; + }, + }, persist: { enabled: true, // 自定义持久化参数 strategies: [ { storage: sessionStorage, - paths: ['deptList', 'systemDeptList', 'userList'], + paths: ['kitToken', 'access_token', 'msg'], }, ], }, }); export default useImouPlayerStore; + +function changeParams(params, appId, appSecret) { + params.system.appId = appId; + var timestamp = getTime(); + // pm.environment.set('time', timestamp); + params.system.time = timestamp; + var nonce = Math.random().toString(36).substr(2); + // pm.environment.set('nonce', nonce); + params.system.nonce = nonce; + // var appSecret = pm.environment.get('appSecret'); + var sign = calcSign(timestamp, nonce, appSecret); + // pm.environment.set('sign', sign); + params.system.sign = sign; + var id = Math.floor(Math.random() * (50 - 1 + 1) + 1); + // pm.environment.set('id', id); + params.id = id; + return params; +} + +function getTime() { + var timestamp = Math.round(new Date().getTime() / 1000); + return timestamp; +} + +function calcSign(timestamp, nonce, appSecret) { + var str = 'time:' + timestamp + ',nonce:' + nonce + ',appSecret:' + appSecret; + var sign = CryptoJS.MD5(str).toString(); + return sign; +} diff --git a/src/views/DialogTabs/component/ImouPlayer.vue b/src/views/DialogTabs/component/ImouPlayer.vue index 7f2f23a..eb03201 100644 --- a/src/views/DialogTabs/component/ImouPlayer.vue +++ b/src/views/DialogTabs/component/ImouPlayer.vue @@ -4,13 +4,14 @@