diff --git a/server/src/constant/open_access.ts b/server/src/constant/enter_access.ts similarity index 89% rename from server/src/constant/open_access.ts rename to server/src/constant/enter_access.ts index 06c6a07..6596a1c 100644 --- a/server/src/constant/open_access.ts +++ b/server/src/constant/enter_access.ts @@ -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; diff --git a/server/src/iot/entrance/access.ts b/server/src/iot/entrance/access.ts index 0e2ab2f..4863c00 100644 --- a/server/src/iot/entrance/access.ts +++ b/server/src/iot/entrance/access.ts @@ -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() diff --git a/server/src/module/mp/controller/access/list.ts b/server/src/module/mp/controller/access/list.ts index 7267283..728deea 100644 --- a/server/src/module/mp/controller/access/list.ts +++ b/server/src/module/mp/controller/access/list.ts @@ -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 = { 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) }); }); diff --git a/server/src/module/mp/controller/vistor/detail.ts b/server/src/module/mp/controller/vistor/detail.ts index 2feec64..29a1c68 100644 --- a/server/src/module/mp/controller/vistor/detail.ts +++ b/server/src/module/mp/controller/vistor/detail.ts @@ -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 = { 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, diff --git a/server/src/module/mp/controller/vistor/use.ts b/server/src/module/mp/controller/vistor/use.ts index b759489..ce54a4a 100644 --- a/server/src/module/mp/controller/vistor/use.ts +++ b/server/src/module/mp/controller/vistor/use.ts @@ -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 = { .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, diff --git a/server/src/module/pc/controller/vistor/create.ts b/server/src/module/pc/controller/vistor/create.ts index 6ccc473..887561a 100644 --- a/server/src/module/pc/controller/vistor/create.ts +++ b/server/src/module/pc/controller/vistor/create.ts @@ -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 = { 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, diff --git a/server/src/module/pc/controller/vistor/detail.ts b/server/src/module/pc/controller/vistor/detail.ts index f4077b5..72c5251 100644 --- a/server/src/module/pc/controller/vistor/detail.ts +++ b/server/src/module/pc/controller/vistor/detail.ts @@ -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 = { 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, diff --git a/server/src/module/pc/controller/vistor/scan.ts b/server/src/module/pc/controller/vistor/scan.ts index 2e0c5ff..0a5564f 100644 --- a/server/src/module/pc/controller/vistor/scan.ts +++ b/server/src/module/pc/controller/vistor/scan.ts @@ -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 = { const { uid, community_id } = 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: '非法访客二维码' diff --git a/server/src/utils/access.ts b/server/src/utils/access.ts index 5489456..c0081d2 100644 --- a/server/src/utils/access.ts +++ b/server/src/utils/access.ts @@ -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 = parseInt(arr[2], 10); + const type = 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())