diff --git a/obfuscation-rules.txt b/obfuscation-rules.txt index ad8f6bf..48bdb06 100644 --- a/obfuscation-rules.txt +++ b/obfuscation-rules.txt @@ -35,6 +35,7 @@ # ./src/main/ets/bean/model/AgreementModel # ./src/main/ets/bean/model/CertDownModel # ./src/main/ets/bean/model/CertInfoModel +# ./src/main/ets/bean/model/QrContentModel # ./src/main/ets/bean/model/CheckStateModel # ./src/main/ets/bean/model/UserInfoModel # ./src/main/ets/bean/model/VerifyCodeModel @@ -61,6 +62,7 @@ CertEnvType # AgreementModel # CertDownModel # CertInfoModel +# QrContentModel # CheckStateModel # CertList SignModel @@ -134,6 +136,8 @@ clearPin signForSignAuto stopSignAuto getSignAutoInfo +qrDispose +qrDisposeForOauth # CertEnvType DOCTOR MASS @@ -193,6 +197,18 @@ sex startDate userName unit +# QrContentModel +scene +requestId +signProcessId +uniqueId +clientId +clientName +sysTag +userId +timestamp +grantAuth +uniqueIdList # CheckStateModel certList deviceId diff --git a/src/main/ets/bean/data/QrContentData.ets b/src/main/ets/bean/data/QrContentData.ets new file mode 100644 index 0000000..dc46449 --- /dev/null +++ b/src/main/ets/bean/data/QrContentData.ets @@ -0,0 +1,8 @@ +export class QrContentData { + id: string + + constructor(id: string) { + this.id = id + } + +} \ No newline at end of file diff --git a/src/main/ets/bean/data/SignForOAuthData.ets b/src/main/ets/bean/data/SignForOAuthData.ets new file mode 100644 index 0000000..d403682 --- /dev/null +++ b/src/main/ets/bean/data/SignForOAuthData.ets @@ -0,0 +1,13 @@ +export class SignForOAuthData { + clientId: string + uuid: string + pin: string + + constructor(clientId: string, uuid: string, pin: string) { + this.clientId = clientId + this.uuid = uuid + this.pin = pin + } + + +} \ No newline at end of file diff --git a/src/main/ets/bean/model/OAuthGrantModel.ets b/src/main/ets/bean/model/OAuthGrantModel.ets new file mode 100644 index 0000000..425a5c2 --- /dev/null +++ b/src/main/ets/bean/model/OAuthGrantModel.ets @@ -0,0 +1,12 @@ +export interface OAuthGrantItem { + grantDoctorName: string + grantedDoctorName: string + startTime: string + endTime: string + grantUniqueId: string + openId: string +} + +export interface OAuthGrantModel { + list: Array +} \ No newline at end of file diff --git a/src/main/ets/bean/model/QrContentModel.ets b/src/main/ets/bean/model/QrContentModel.ets new file mode 100644 index 0000000..6925785 --- /dev/null +++ b/src/main/ets/bean/model/QrContentModel.ets @@ -0,0 +1,124 @@ +export class QrContentModel { + // 场景 + private _scene: string | undefined + + public set scene(value: string | undefined) { + this._scene = value + } + + public get scene(): string | undefined { + return this._scene + } + + // oauth签名的唯一标识 + private _requestId: string | undefined + + public set requestId(value: string | undefined) { + this._requestId = value + } + + public get requestId(): string | undefined { + return this._requestId + } + + // oauth签名 信步云签名流水号 + private _signProcessId: string | undefined + + public set signProcessId(value: string | undefined) { + this._signProcessId = value + } + + public get signProcessId(): string | undefined { + return this._signProcessId + } + + // 扫码签名、扫码认领数据签名 数据唯一标识 + private _uniqueId: string | undefined + + public set uniqueId(value: string | undefined) { + this._uniqueId = value + } + + public get uniqueId(): string | undefined { + return this._uniqueId + } + + // 自动签名 + private _clientId: string | undefined + + public set clientId(value: string | undefined) { + this._clientId = value + } + + public get clientId(): string | undefined { + return this._clientId + } + + //自动签名厂商名称 + private _clientName: string | undefined + + public set clientName(value: string | undefined) { + this._clientName = value + } + + public get clientName(): string | undefined { + return this._clientName + } + + // 自动签名系统标识 + private _sysTag: string | undefined + + public set sysTag(value: string | undefined) { + this._sysTag = value + } + + public get sysTag(): string | undefined { + return this._sysTag + } + + // 自动签名 用户id + private _userId: string | undefined + + public set userId(value: string | undefined) { + this._userId = value + } + + public get userId(): string | undefined { + return this._userId + } + + // 扫码认领数据签名 时间戳 + private _timestamp: string | undefined + + public set timestamp(value: string | undefined) { + this._timestamp = value + } + + public get timestamp(): string | undefined { + return this._timestamp + } + + //oauth认证类型"1":授权登录,"0":普通登录 + private _grantAuth: string | undefined + + public set grantAuth(value: string | undefined) { + this._grantAuth = value + } + + public get grantAuth(): string | undefined { + return this._grantAuth + } + + private _uniqueIdList: string[] | undefined + + public set uniqueIdList(value: string[] | undefined) { + this._uniqueIdList = value + } + + public get uniqueIdList(): string[] | undefined { + return this._uniqueIdList + } + + constructor() { + } +} \ No newline at end of file diff --git a/src/main/ets/bean/model/QrJsonModel.ets b/src/main/ets/bean/model/QrJsonModel.ets new file mode 100644 index 0000000..63e3d00 --- /dev/null +++ b/src/main/ets/bean/model/QrJsonModel.ets @@ -0,0 +1,25 @@ +export class QrJsonModel { + // 场景 + private _tag: number | undefined + + public set tag(value: number | undefined) { + this._tag = value + } + + public get tag(): number | undefined { + return this._tag + } + + private _content: string | undefined + + public set content(value: string | undefined) { + this._content = value + } + + public get content(): string | undefined { + return this._content + } + + constructor() { + } +} \ No newline at end of file diff --git a/src/main/ets/common/GlobalValue.ets b/src/main/ets/common/GlobalValue.ets index 239ec2f..1910ea6 100644 --- a/src/main/ets/common/GlobalValue.ets +++ b/src/main/ets/common/GlobalValue.ets @@ -35,6 +35,7 @@ export class GlobalValue { private _signAutoPin: string | null = null private _signAutoDay: string | null = null + // 免密开启的后保存在本地的pin public set signAutoPin(value: string | null) { this._signAutoPin = value AppStorageHelper.save(StorageKeys.SIGN_AUTO_PIN, value ?? undefined) @@ -45,6 +46,7 @@ export class GlobalValue { return this._signAutoPin ?? AppStorageHelper.get(StorageKeys.SIGN_AUTO_PIN) ?? null } + // 免密时间到期时间 public set signAutoDay(value: string | null) { this._signAutoDay = value AppStorageHelper.save(StorageKeys.SIGN_AUTO_DAY, value ?? undefined) diff --git a/src/main/ets/http/ApiConfig.ets b/src/main/ets/http/ApiConfig.ets index 2ccda17..69f1fcb 100644 --- a/src/main/ets/http/ApiConfig.ets +++ b/src/main/ets/http/ApiConfig.ets @@ -139,6 +139,27 @@ export const uploadStampPic = (): ApiElem => { } +/** + * 获取二维码中的内容(不使用版本号) + */ +export const getQrContent: ApiElem = { + apiNo: 'getQrContent', + url: 'am/qrCode/getParam' +} +/** + * 获取授权人列表和被授权人列表 + */ +export const getGrantList: ApiElem = { + apiNo: 'getGrantList', + url: 'am/v3/grant/queryInfo' +} +/** + * 开启OAuth + */ +export const oauthSure: ApiElem = { + apiNo: 'oauthSure', + url: 'am/v3/bjca/authorize/authentication' +} diff --git a/src/main/ets/manager/SignManagerReal.ets b/src/main/ets/manager/SignManagerReal.ets index ac217bd..9a89fcb 100644 --- a/src/main/ets/manager/SignManagerReal.ets +++ b/src/main/ets/manager/SignManagerReal.ets @@ -3,7 +3,16 @@ import { CaManagerReal } from './CaManagerReal'; import { BJCASDK } from '../public/BJCASDK'; import { BJCACallMsg, CallBackForData } from '../public/callBack/BJCACallMsg'; import { ApiUtils } from '../http/ApiUtils'; -import { getSignAutoInfo, getSignAutoQuit, signWithServer, sureSignForSignAuto, verifyPin } from '../http/ApiConfig'; +import { + getGrantList, + getQrContent, + getSignAutoInfo, + getSignAutoQuit, + oauthSure, + signWithServer, + sureSignForSignAuto, + verifyPin +} from '../http/ApiConfig'; import { SignData } from '../bean/data/SignData'; import { GlobalValue } from '../common/GlobalValue'; import { encodeByRsa } from '../util/encodeUtil'; @@ -11,13 +20,23 @@ import { SignModel } from '../public/bean/SignModel'; import { PinData } from '../bean/data/PinData'; import { AutoData } from '../bean/data/AutoData'; import { AutoStopData } from '../bean/data/AutoStopData'; +import { QrImageBean } from '../qr/QrImageBean'; +import { QrContentData } from '../bean/data/QrContentData'; +import { QrContentModel } from '../bean/model/QrContentModel'; +import { QrDecodeV1SignUtil } from '../qr/QrDecodeV1SignUtil'; +import { QrDecodeV2JsonUtil } from '../qr/QrDecodeV2JsonUtil'; +import { QrCenterScene } from '../qr/QrCenterScene'; +import { ValueScene } from '../qr/ValueScene'; +import { OAuthGrantModel } from '../bean/model/OAuthGrantModel'; +import { SignForOAuthData } from '../bean/data/SignForOAuthData'; export class SignManagerReal { private static SIGN_BATCH_MAX_NUM = 100 public static listener: ((result: CallBackForData) => void) | null = null - public static signWithFirmId(uniqueIdList: List | Array, listener: (result: CallBackForData>) => void) { + public static signWithFirmId(uniqueIdList: List | Array, + listener: (result: CallBackForData>) => void) { if (uniqueIdList.length === 0) { listener(BJCACallMsg.ILLEGALITY) @@ -97,6 +116,67 @@ export class SignManagerReal { } } + private static signForOAuth(signId: string, uuid: string, isHandleGrantOauth: boolean, + listener: (result: CallBackForData) => void) { + + if (isHandleGrantOauth) { + ApiUtils.get(getGrantList) + .then((res: OAuthGrantModel) => { + if (!res.list || res.list.length === 0) { + listener({ + code: BJCACallMsg.QR_VERIFY_GRANT_ERROR.code, + msg: BJCACallMsg.QR_VERIFY_GRANT_ERROR.msg, + data: JSON.stringify({ uuid: uuid }) + }) + } else { + SignManagerReal.signForOAuthGetPin(uuid, listener) + } + }).catch((error: Error) => { + console.log('>>>>>', JSON.stringify(error)) + listener({ + code: BJCACallMsg.FAILED.code, + msg: error.name + }) + }) + } else { + SignManagerReal.signForOAuthGetPin(uuid, listener) + } + + } + + private static signForOAuthGetPin(uuid: string, listener: (result: CallBackForData) => void) { + + if (SignManagerReal.isPinExempt()) { + SignManagerReal.startSignForOAuth(uuid, GlobalValue.getInstance().signAutoPin!, listener) + } else { + SignManagerReal.listener = (result: CallBackForData) => { + if (result.code === BJCACallMsg.SUCCESS.code) { + SignManagerReal.startSignForOAuth(uuid, encodeByRsa(result.data), listener) + } else { + listener && listener(result) + } + } + BJCASDK.signManager().dialogController.open() + } + } + + + private static startSignForOAuth(uuid: string, pin: string, listener: (result: CallBackForData) => void) { + + ApiUtils.post(oauthSure, new SignForOAuthData(GlobalValue.getInstance().getClientId()!, uuid, pin)) + .then(res => { + listener && listener(BJCACallMsg.SUCCESS) + }) + .catch((error: Error) => { + listener && listener({ + code: 1003, + msg: `用户操作失败:${error.message}` + }) + }) + + } + + public static keepPin(keepDay: number, listener: (result: CallBackForData) => void) { if (keepDay < 1 || keepDay > 60 || !Number.isInteger(keepDay)) { @@ -194,7 +274,7 @@ export class SignManagerReal { BJCASDK.signManager().dialogController.open() } - public static stopSignAuto(sysTag: string|undefined, listener: (result: CallBackForData) => void) { + public static stopSignAuto(sysTag: string | undefined, listener: (result: CallBackForData) => void) { if (!CaManagerReal.existsCert()) { listener && listener(BJCACallMsg.CERT_NOT_EXISTS) return @@ -223,7 +303,7 @@ export class SignManagerReal { return } - // 停止自动签 + // 获取自动签信息 ApiUtils.post(getSignAutoInfo, new AutoStopData( GlobalValue.getInstance().certClientId!, GlobalValue.getInstance().userId!, @@ -239,4 +319,156 @@ export class SignManagerReal { }) }) } -} \ No newline at end of file + + public static qrDispose(qrText: string, isHandleGrantOauth: boolean, + listener: (result: CallBackForData) => void) { + if (!CaManagerReal.existsCert()) { + listener && listener(BJCACallMsg.CERT_NOT_EXISTS) + return + } + if (!qrText || qrText === '' || qrText === ' ') { + listener && listener(BJCACallMsg.RQ_NULL) + return + } + + let qrImageBean = new QrImageBean(qrText) + if (qrImageBean.qrCenter) { + // 调用中控平台根据id获取二维码中保存的内容 + ApiUtils.get(getQrContent, new QrContentData(qrImageBean.id ?? '')) + .then((res: QrContentModel) => { + SignManagerReal.decodeQrSuccess(res, isHandleGrantOauth, listener) + }).catch((error: Error) => { + console.log('>>>>>', JSON.stringify(error)) + listener && listener({ + code: 1003, + msg: error.message + }) + }) + + return + } + + let qrContentModel: QrContentModel | undefined = QrDecodeV1SignUtil.getQrContentBeanByImageText(qrText) + if (qrContentModel !== undefined) { + SignManagerReal.decodeQrSuccess(qrContentModel, isHandleGrantOauth, listener) + return + } + + qrContentModel = QrDecodeV2JsonUtil.getQrContentBeanByImageText(qrText) + if (qrContentModel !== undefined) { + SignManagerReal.decodeQrSuccess(qrContentModel, isHandleGrantOauth, listener) + return + } + listener && listener(BJCACallMsg.RQ_FAILED) + + } + + private static decodeQrSuccess(qrContentModel: QrContentModel, isHandleGrantOauth: boolean, + listener: (result: CallBackForData) => void) { + console.log('>>>>>', qrContentModel.scene) + switch (qrContentModel.scene) { + case QrCenterScene.PC_QR_SIGN: + if (qrContentModel.userId) { + // v1版本的二维码上没有userId,在中控版本中,pc二维码签名中有userId,先判断二维码内容中的用户userId和证书的userId是否一致¬ + if (qrContentModel.userId !== GlobalValue.getInstance().userId) { + listener && listener(BJCACallMsg.USER_DIFFERENT) + return; + } + } + let uniqueId = qrContentModel.uniqueId + let uniqueIdList: string[] = [] + uniqueIdList.push(uniqueId ?? '') + SignManagerReal.signWithFirmId(uniqueIdList, res => { + if (res.code === BJCACallMsg.SUCCESS.code) { + listener && listener(BJCACallMsg.SUCCESS) + } else { + listener && listener({ + code: res.code, + msg: res.msg + }) + } + }) + break; + case QrCenterScene.OAUTH: + let uuid = qrContentModel.requestId + let signId = qrContentModel.signProcessId + let grantAuth = qrContentModel.grantAuth + if (isHandleGrantOauth && grantAuth === ValueScene.OAUTH_WAY) { //授权登录需查询授权列表信息 + SignManagerReal.signForOAuth(signId ?? '', uuid ?? '', true, res => { + if (res.code === BJCACallMsg.SUCCESS.code) { + listener && listener(BJCACallMsg.SUCCESS) + } else { + listener && listener({ + code: res.code, + msg: res.msg + }) + } + }); + } else { //isHandleGrantOauth==false或者grantAuth=="0"||""直接输入pin码授权 + SignManagerReal.signForOAuth(signId ?? '', uuid ?? '', false, res => { + if (res.code === BJCACallMsg.SUCCESS.code) { + listener && listener(BJCACallMsg.SUCCESS) + } else { + listener && listener({ + code: res.code, + msg: res.msg + }) + } + }); + } + break; + case QrCenterScene.OAUTH_SIGN: + // SignBindManage.qrSignBind(activity, clientId, qrContentModel.getClientId(), + // qrContentModel.getUniqueId(), qrContentModel.getTimestamp(), listener); + break; + case QrCenterScene.OAUTH_SIGN_BATCH: + // SignBindManage.qrSignBindBatch(activity, clientId, qrContentModel.getClientId(), + // qrContentModel.getUniqueIdList(), qrContentModel.getTimestamp(), listener); + break; + case QrCenterScene.SELF_SIGN: + if (qrContentModel.userId === GlobalValue.getInstance().userId) { + if (!qrContentModel.sysTag) { + listener && listener(BJCACallMsg.ILLEGALITY) + } + SignManagerReal.signForSignAuto(qrContentModel.sysTag!, listener); + } else { + listener && listener(BJCACallMsg.USER_DIFFERENT) + } + break; + default: + listener && listener(BJCACallMsg.RQ_FAILED) + break; + } + + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/ets/public/SignManager.ets b/src/main/ets/public/SignManager.ets index 872e326..47d85e8 100644 --- a/src/main/ets/public/SignManager.ets +++ b/src/main/ets/public/SignManager.ets @@ -1,7 +1,7 @@ import { SignManagerReal } from '../manager/SignManagerReal'; import { List } from '@kit.ArkTS'; import { XDialogController } from '@szyx/sdk_base/Index'; -import { CallBackForData } from './callBack/BJCACallMsg'; +import { CallBackForData, CallBackMsg } from './callBack/BJCACallMsg'; import { SignModel } from './bean/SignModel'; export class SignManager { @@ -12,7 +12,8 @@ export class SignManager { * @param uniqueIdList 待签数据 * @param listener */ - public signWithFirmId(uniqueIdList: List | Array, listener: (result: CallBackForData>) => void) { + public signWithFirmId(uniqueIdList: List | Array, + listener: (result: CallBackForData>) => void) { SignManagerReal.signWithFirmId(uniqueIdList, listener) @@ -70,4 +71,22 @@ export class SignManager { public getSignAutoInfo(listener: (result: CallBackForData) => void) { SignManagerReal.getSignAutoInfo(listener) } + + /** + * 识别二维码信息 + * @param qrText 二维码内容 + * @param listener + */ + public qrDispose(qrText: string, listener: (result: CallBackMsg) => void) { + SignManagerReal.qrDispose(qrText, false, listener) + } + /** + * + * @param qrText 二维码内容 + * @param isHandleGrantOauth 是否处理授权Oauth登录 + * @param listener + */ + public qrDisposeForOauth(qrText: string, isHandleGrantOauth:boolean, listener: (result: CallBackMsg) => void) { + SignManagerReal.qrDispose(qrText, isHandleGrantOauth, listener) + } } \ No newline at end of file diff --git a/src/main/ets/public/callBack/BJCACallMsg.ets b/src/main/ets/public/callBack/BJCACallMsg.ets index 42885dd..0de491f 100644 --- a/src/main/ets/public/callBack/BJCACallMsg.ets +++ b/src/main/ets/public/callBack/BJCACallMsg.ets @@ -1,3 +1,4 @@ +import { QrContentModel } from '../../bean/model/QrContentModel' import { UserInfoModel } from '../bean/UserInfoModel' export interface CallBackMsg { @@ -45,6 +46,10 @@ export class BJCACallMsg { code: 10002, msg: '手机号格式错误' } + public static USER_DIFFERENT: CallBackMsg = { + code: 10003, + msg: '您不能操作其他用户的数据' + } // 证书相关 public static CERT_NOT_EXISTS: CallBackMsg = { code: 10003, @@ -78,7 +83,7 @@ export class BJCACallMsg { public static DRAW_SUCCESS: CallBackForData = { code: 1001, msg: '手写签名修改成功', - data:'' + data: '' } // 签名相关 public static SIGN_CANCEL: CallBackForData = { @@ -93,4 +98,17 @@ export class BJCACallMsg { code: 10011, msg: '重置密码' } + // 二维码相关 + public static RQ_NULL: CallBackForData = { + code: 30001, + msg: '二维码数据为空' + } + public static RQ_FAILED: CallBackForData = { + code: 30002, + msg: '当前二维码业务医网信无法处理,请检查后重试' + } + public static QR_VERIFY_GRANT_ERROR: CallBackForData = { + code: 30003, + msg: '需要选择登录人信息' + } } \ No newline at end of file diff --git a/src/main/ets/qr/QrCenterScene.ets b/src/main/ets/qr/QrCenterScene.ets new file mode 100644 index 0000000..9e60c41 --- /dev/null +++ b/src/main/ets/qr/QrCenterScene.ets @@ -0,0 +1,14 @@ +export class QrCenterScene { + // 授权签名--在app中才有使用 + public static GRANT_SIGN: string = "GRANT_SIGN"; + // 自动签名授权 + public static SELF_SIGN: string = "SELF_SIGN"; + // auth签名(扫码认领订单) + public static OAUTH_SIGN: string = "AUTH_SIGN"; + // auth批量签名 + public static OAUTH_SIGN_BATCH: string = "AUTH_SIGN_BATCH"; + // oauth认证 + public static OAUTH: string = "OAUTH"; + // 扫码签名 + public static PC_QR_SIGN: string = "PC_QRCODE"; +} \ No newline at end of file diff --git a/src/main/ets/qr/QrDecodeV1SignUtil.ets b/src/main/ets/qr/QrDecodeV1SignUtil.ets new file mode 100644 index 0000000..acc4724 --- /dev/null +++ b/src/main/ets/qr/QrDecodeV1SignUtil.ets @@ -0,0 +1,59 @@ +import { QrContentModel } from '../bean/model/QrContentModel'; +import { QrCenterScene } from './QrCenterScene'; + +export class QrDecodeV1SignUtil { + private static KEY_OAUTH = "b" + private static KEY_SiGN = "c" + private static keyIndex = 5 + + static getQrContentBeanByImageText(qrText: string): QrContentModel | undefined { + let qrContentModel: QrContentModel | undefined = new QrContentModel() + let key = qrText.substring(QrDecodeV1SignUtil.keyIndex - 1, QrDecodeV1SignUtil.keyIndex) + switch (key) { + case QrDecodeV1SignUtil.KEY_OAUTH: + qrContentModel = QrDecodeV1SignUtil.getOAuthContentBean(qrContentModel, qrText) + break + case QrDecodeV1SignUtil.KEY_SiGN: + qrContentModel = QrDecodeV1SignUtil.getSignContentBean(qrContentModel, qrText); + break; + default: + qrContentModel = undefined; + break; + } + + return qrContentModel + } + + private static getOAuthContentBean(qrContentModel: QrContentModel, qrText: string): QrContentModel | undefined { + let values = qrText.split("##"); + if (values.length < 3) { + return undefined; + } + let length = values.length; + + let signId = values[length - 1]; + let requestId = values[length - 2]; + + qrContentModel.scene = QrCenterScene.OAUTH + qrContentModel.requestId = requestId + qrContentModel.signProcessId = signId + + return qrContentModel + } + + private static getSignContentBean(qrContentModel: QrContentModel, qrText: string): QrContentModel | undefined { + let endLocation = qrText.lastIndexOf("="); + if (endLocation < 1) { + return undefined; + } + let uniqueId = qrText.substring(endLocation + 1); + if ("clientId-" === qrText.substring(endLocation - 25, endLocation - 16)) { + let clientId = qrText.substring(endLocation - 16, endLocation); + qrContentModel.clientId = clientId + } + qrContentModel.scene = QrCenterScene.PC_QR_SIGN + + qrContentModel.uniqueId = uniqueId + return qrContentModel; + } +} \ No newline at end of file diff --git a/src/main/ets/qr/QrDecodeV2JsonUtil.ets b/src/main/ets/qr/QrDecodeV2JsonUtil.ets new file mode 100644 index 0000000..4f48b27 --- /dev/null +++ b/src/main/ets/qr/QrDecodeV2JsonUtil.ets @@ -0,0 +1,104 @@ +import { QrContentModel } from '../bean/model/QrContentModel' +import { QrJsonModel } from '../bean/model/QrJsonModel' +import { QrCenterScene } from './QrCenterScene' + +export class QrDecodeV2JsonUtil { + private static TAG_SELF_SIGN = 1 + private static TAG_AUTH_SIGN = 2 + private static SLICE_PARAM = "&" + private static SLICE_PARAM_KEY = "=" + private static qrKeyword1 = "tag" + private static qrKeyword2 = "content" + + static getQrContentBeanByImageText(qrText: string): QrContentModel | undefined { + if (qrText.indexOf(QrDecodeV2JsonUtil.qrKeyword1) === -1 || qrText.indexOf(QrDecodeV2JsonUtil.qrKeyword2) === -1) { + return undefined; + } + + let qrContentModel: QrContentModel | undefined = new QrContentModel() + + let qrJsonBean: QrJsonModel = JSON.parse(qrText); + + if (!qrJsonBean) { + return undefined; + } + + + let key = qrJsonBean.tag + let content = qrJsonBean.content + if (!content) { + return undefined + } + switch (key) { + case QrDecodeV2JsonUtil.TAG_SELF_SIGN: + qrContentModel = QrDecodeV2JsonUtil.getSelfSignContentBean(qrContentModel, content); + break; + case QrDecodeV2JsonUtil.TAG_AUTH_SIGN: + qrContentModel = QrDecodeV2JsonUtil.getOAuthSignContentBean(qrContentModel, content); + break; + default: + qrContentModel = undefined; + break; + } + + return qrContentModel; + } + + private static getSelfSignContentBean(qrContentModel: QrContentModel, content: string): QrContentModel | undefined { + let keyValueMap = QrDecodeV2JsonUtil.getContentKeyValue(content) + if (keyValueMap.size === 0) { + return undefined + } + let keys = keyValueMap.keys() + for (const key of keys) { + let value = keyValueMap.get(key); + // 此处由于二维码内容将要修正,因此不对字符串进行变量声明 2020-09-24 + if (key === "clientId") { + qrContentModel.clientId = value + } else if (key === "clientName") { + qrContentModel.clientName = value + } else if (key === "userId") { + qrContentModel.userId = value + } else if (key === "sysTag") { + qrContentModel.sysTag = value + } + } + qrContentModel.scene = QrCenterScene.SELF_SIGN + return qrContentModel + } + + private static getOAuthSignContentBean(qrContentModel: QrContentModel, content: string): QrContentModel | undefined { + let keyValueMap = QrDecodeV2JsonUtil.getContentKeyValue(content) + if (keyValueMap.size === 0) { + return undefined + } + let keys = keyValueMap.keys() + for (const key of keys) { + let value = keyValueMap.get(key); + if (key === "clientId") { + qrContentModel.clientId = value + } else if (key === "timestamp") { + qrContentModel.timestamp = value + } else if (key === "uniqueId") { + qrContentModel.uniqueId = value + } + } + qrContentModel.scene = QrCenterScene.SELF_SIGN + return qrContentModel + } + + private static getContentKeyValue(content: string): Map { + let map = new Map() + + let params = content.split(QrDecodeV2JsonUtil.SLICE_PARAM) + for (let i = 0; i < params.length; i++) { + let keyWithValue = params[i] + let param = keyWithValue.split(QrDecodeV2JsonUtil.SLICE_PARAM_KEY) + if (param.length < 2) { + continue; + } + map.set(param[0], param[1]) + } + return map + } +} \ No newline at end of file diff --git a/src/main/ets/qr/QrImageBean.ets b/src/main/ets/qr/QrImageBean.ets new file mode 100644 index 0000000..82a2bad --- /dev/null +++ b/src/main/ets/qr/QrImageBean.ets @@ -0,0 +1,70 @@ +import { QrCenterScene } from './QrCenterScene' + +export class QrImageBean { + private qrText: string + private _scene?: string | undefined + + public get scene(): string | undefined { + return this._scene + } + + private _id?: string | undefined + + public get id(): string | undefined { + return this._id + } + + private _qrCenter: boolean = false + + public get qrCenter(): boolean { + return this._qrCenter + } + + private _qrYwx: boolean = false + + public get qrYwx(): boolean { + return this._qrYwx + } + private mYwxSceneList: string[] = + [QrCenterScene.GRANT_SIGN, QrCenterScene.SELF_SIGN, QrCenterScene.OAUTH_SIGN, QrCenterScene.OAUTH, + QrCenterScene.PC_QR_SIGN] + private QR_CENTER_KEY = "51trust.com" + private QR_CENTER_SLICE = "?" + private QR_CENTER_PARAM_SLICE = "&" + private QR_CENTER_PARAM_KEY_SLICE = "=" + private keyScene = "scene" + private keyId = "id" + + public constructor(qrText: string) { + this.qrText = qrText + this._qrCenter = this.checkIsQrCenter(); + this._qrYwx = this.mYwxSceneList.indexOf(this._scene ?? '') > -1 + } + + + private checkIsQrCenter(): boolean { + if (this.qrText.indexOf(this.QR_CENTER_KEY) > -1) { + let scheme = this.qrText.split(this.QR_CENTER_SLICE); + if (scheme.length < 2) { + return false; + } + let paramsStr = scheme[1]; + + let params = paramsStr.split(this.QR_CENTER_PARAM_SLICE); + for (let i = 0; i < params.length; i++) { + let keyWithValue = params[i] + let param = keyWithValue.split(this.QR_CENTER_PARAM_KEY_SLICE) + if (param.length < 2) { + continue; + } + if (this.keyScene === param[0]) { + this._scene = param[1]; + } else if (this.keyId === param[0]) { + this._id = param[1]; + } + } + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/ets/qr/ValueScene.ets b/src/main/ets/qr/ValueScene.ets new file mode 100644 index 0000000..7e9d79e --- /dev/null +++ b/src/main/ets/qr/ValueScene.ets @@ -0,0 +1,4 @@ +export class ValueScene { + // oauth认证 授权方式 "1":授权登录,"0":普通登录(或空也是普通登录) + public static OAUTH_WAY: string = "1"; +} \ No newline at end of file