optimize ower and vitstor access
This commit is contained in:
parent
fb2b08aed3
commit
9d9a2cb59d
@ -10,5 +10,5 @@
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
export const SELF_ACCESS_QRCODE = 1;
|
||||
export const VISTOR_ACCESS_QRCODE = 2;
|
||||
export const SELF_ACCESS_CODE = 1;
|
||||
export const VISTOR_ACCESS_CODE = 2;
|
@ -13,7 +13,7 @@
|
||||
import moment from 'moment';
|
||||
import Knex from 'Knex';
|
||||
import { EjyyIotEntrance } from '~/types/model';
|
||||
import { SELF_ACCESS_QRCODE, VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { SELF_ACCESS_CODE, VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
import utils from '~/utils';
|
||||
import { IOT_METHOD_QRCODE, IOT_METHOD_NFC, IOT_METHOD_ICCARD } from '~/constant/iot';
|
||||
|
||||
@ -104,8 +104,8 @@ async function accessMethod(params: AccessParams, entranceInfo: EjyyIotEntrance,
|
||||
}
|
||||
|
||||
await model.from('ejyy_iot_entrance_log').insert({
|
||||
wechat_mp_user_id: reuslt.type === SELF_ACCESS_QRCODE ? reuslt.id : null,
|
||||
vistor_id: reuslt.type === VISTOR_ACCESS_QRCODE ? reuslt.id : null,
|
||||
wechat_mp_user_id: reuslt.type === SELF_ACCESS_CODE ? reuslt.id : null,
|
||||
vistor_id: reuslt.type === VISTOR_ACCESS_CODE ? reuslt.id : null,
|
||||
entrance_id: entranceInfo.id,
|
||||
method,
|
||||
created_at: mom.valueOf()
|
||||
|
@ -13,7 +13,7 @@
|
||||
import { Action } from '~/types/action';
|
||||
import { SUCCESS } from '~/constant/code';
|
||||
import utils from '~/utils';
|
||||
import { SELF_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { SELF_ACCESS_CODE } from '~/constant/enter_access';
|
||||
|
||||
interface RequestBody {
|
||||
building_ids: number[];
|
||||
@ -58,7 +58,7 @@ const MpAccessListAction = <Action>{
|
||||
buildings.forEach(({ building_id }) => {
|
||||
cardList.push({
|
||||
building_id,
|
||||
uid: utils.access.encrypt(ctx.mpUserInfo.id, building_id, SELF_ACCESS_QRCODE)
|
||||
uid: utils.access.encrypt(ctx.mpUserInfo.id, building_id, SELF_ACCESS_CODE)
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
import { Action } from '~/types/action';
|
||||
import { SUCCESS } from '~/constant/code';
|
||||
import { VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
import utils from '~/utils';
|
||||
|
||||
interface RequestParams {
|
||||
@ -67,7 +67,7 @@ const MpVistorDetailAction = <Action>{
|
||||
|
||||
detail.vistor_phone = utils.phone.hide(detail.vistor_phone);
|
||||
|
||||
const uid = utils.access.encrypt(detail.id, detail.building_id, VISTOR_ACCESS_QRCODE);
|
||||
const uid = utils.access.encrypt(detail.id, detail.building_id, VISTOR_ACCESS_CODE);
|
||||
|
||||
ctx.body = {
|
||||
code: SUCCESS,
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
import { Action } from '~/types/action';
|
||||
import { SUCCESS } from '~/constant/code';
|
||||
import { VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
import utils from '~/utils';
|
||||
|
||||
interface RequestParams {
|
||||
@ -62,7 +62,7 @@ const MpVistorUseAction = <Action>{
|
||||
.where('ejyy_vistor.id', id)
|
||||
.first();
|
||||
|
||||
const uid = utils.access.encrypt(detail.id, detail.building_id, VISTOR_ACCESS_QRCODE);
|
||||
const uid = utils.access.encrypt(detail.id, detail.building_id, VISTOR_ACCESS_CODE);
|
||||
|
||||
ctx.body = {
|
||||
code: SUCCESS,
|
||||
|
@ -13,7 +13,7 @@
|
||||
import { Action } from '~/types/action';
|
||||
import { SUCCESS, STATUS_ERROR } from '~/constant/code';
|
||||
import { TRUE, FALSE } from '~/constant/status';
|
||||
import { VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
import utils from '~/utils';
|
||||
import * as vistorService from '~/service/vistor';
|
||||
import moment from 'moment';
|
||||
@ -114,7 +114,7 @@ const PcVistorCreateAction = <Action>{
|
||||
vistorService.pushAccessToVistor(ctx.model, vistorInfo, id, expire);
|
||||
}
|
||||
|
||||
const uid = utils.access.encrypt(id, building_id, VISTOR_ACCESS_QRCODE);
|
||||
const uid = utils.access.encrypt(id, building_id, VISTOR_ACCESS_CODE);
|
||||
|
||||
ctx.body = {
|
||||
code: SUCCESS,
|
||||
|
@ -13,7 +13,7 @@
|
||||
import { Action } from '~/types/action';
|
||||
import { SUCCESS, QUERY_ILLEFAL } from '~/constant/code';
|
||||
import * as ROLE from '~/constant/role_access';
|
||||
import { VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
import utils from '~/utils';
|
||||
|
||||
interface RequestBody {
|
||||
@ -96,7 +96,7 @@ const PcVistorDetailAction = <Action>{
|
||||
|
||||
delete info.property_company_user_id;
|
||||
|
||||
const uid = utils.access.encrypt(info.id, info.building_id, VISTOR_ACCESS_QRCODE);
|
||||
const uid = utils.access.encrypt(info.id, info.building_id, VISTOR_ACCESS_CODE);
|
||||
|
||||
ctx.body = {
|
||||
code: SUCCESS,
|
||||
|
@ -14,7 +14,7 @@ import { Action } from '~/types/action';
|
||||
import { SUCCESS, VISTOR_QRCODE_ERROR, VISTOR_QRCODE_EXPIRED, VISTOR_QRCODE_USED } from '~/constant/code';
|
||||
import * as ROLE from '~/constant/role_access';
|
||||
import utils from '~/utils';
|
||||
import { VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
|
||||
interface RequestBody {
|
||||
community_id: number;
|
||||
@ -47,7 +47,7 @@ const PcVistorScanAction = <Action>{
|
||||
const { uid, community_id } = <RequestBody>ctx.request.body;
|
||||
const { id, building_id, type, success } = utils.access.decrypt(uid);
|
||||
|
||||
if (!success || type !== VISTOR_ACCESS_QRCODE) {
|
||||
if (!success || type !== VISTOR_ACCESS_CODE) {
|
||||
return (ctx.body = {
|
||||
code: VISTOR_QRCODE_ERROR,
|
||||
message: '非法访客二维码'
|
||||
|
@ -12,12 +12,12 @@
|
||||
|
||||
import * as crypto from './crypto';
|
||||
|
||||
import { SELF_ACCESS_QRCODE, VISTOR_ACCESS_QRCODE } from '~/constant/open_access';
|
||||
import { SELF_ACCESS_CODE, VISTOR_ACCESS_CODE } from '~/constant/enter_access';
|
||||
|
||||
interface DecryptResult {
|
||||
id?: number;
|
||||
building_id?: number;
|
||||
type?: typeof SELF_ACCESS_QRCODE | typeof VISTOR_ACCESS_QRCODE;
|
||||
type?: typeof SELF_ACCESS_CODE | typeof VISTOR_ACCESS_CODE;
|
||||
stamp?: number;
|
||||
success: boolean;
|
||||
}
|
||||
@ -27,7 +27,7 @@ interface DecryptResult {
|
||||
export function encrypt(
|
||||
id: number,
|
||||
building_id: number,
|
||||
type: typeof SELF_ACCESS_QRCODE | typeof VISTOR_ACCESS_QRCODE
|
||||
type: typeof SELF_ACCESS_CODE | typeof VISTOR_ACCESS_CODE
|
||||
): string {
|
||||
return crypto.encrypt(`${id}#${building_id}#${type}${Date.now()}`);
|
||||
}
|
||||
@ -42,12 +42,12 @@ export function decrypt(uid: string): DecryptResult {
|
||||
const arr = origin.split('#');
|
||||
const id = parseInt(arr[0], 10);
|
||||
const building_id = parseInt(arr[1], 10);
|
||||
const type = <typeof SELF_ACCESS_QRCODE | typeof VISTOR_ACCESS_QRCODE>parseInt(arr[2], 10);
|
||||
const type = <typeof SELF_ACCESS_CODE | typeof VISTOR_ACCESS_CODE>parseInt(arr[2], 10);
|
||||
const stamp = parseInt(arr[3], 10);
|
||||
let success = true;
|
||||
|
||||
if (
|
||||
(type !== SELF_ACCESS_QRCODE && type !== VISTOR_ACCESS_QRCODE) ||
|
||||
(type !== SELF_ACCESS_CODE && type !== VISTOR_ACCESS_CODE) ||
|
||||
building_id === NaN ||
|
||||
id === NaN ||
|
||||
/^\d{13}$/.test(stamp.toString())
|
||||
|
Loading…
x
Reference in New Issue
Block a user