import { ref, reactive } from 'vue' //import { PlatformSettings } from '../../platfrom/common/RunningParameters/PlatformSettings' import PlatformLogger from "@/views/front/platfrom/common/LogSystem/PlatformLogger"; //import { BitMapInstance } from './BitMapInstance' import { MsgBitMap } from '../../develop/Communication/MessageHelper/MsgBitMap' import { TransitType } from './MessageHelper/TransitType' /** * 报文通讯域定义,交易调用 */ export enum BitMap { /// /// 核心定义 /// Server, /// /// 渠道定义 /// Agn, /// /// 二代支付定义 /// Cnaps2 } export default class Message { static cconv(fileData: string): string { throw new Error("Method not implemented."); } integrateFd(bitMapByte: Uint8Array): Uint8Array { throw new Error("Method not implemented."); } InitGateway2CBS(txCode: string, arg1: string, arg2: string, predicate2retCode: (code: string) => boolean) { throw new Error("Method not implemented.") } InitHfmsApp(url: string, predicate2retCode: (code: string) => boolean) { throw new Error("Method not implemented.") } DoTransit(): boolean { throw new Error("Method not implemented.") } /// /// 创建Message对象 /// /// Message(type?: BitMap) { this.IsMainTrade = false; if (type === undefined) { this.TransitNode = TransitType.CallServer; this.Init(BitMap.Server); } else { this.Init(type); } } // 交易附件数据 private _fileData = ref('') public _filename = ref('') private _fdDict: Record private _BigFds_: Record = {} BitMapType: BitMap static BitMap: any _transitNode: TransitType TransitName: string CustomizeTransitEntry: null IsMainTrade = false; /** * 交易文件附件传送标志 */ get fileFlag(): boolean { return this._fileData.value !== '' } set fileFlag(value: boolean) { if (!value) this._fileData.value = '' } // public Message() { // this.IsMainTrade = false; // this.TransitNode = TransitType.CallServer; // this.Init(BitMap.Server); // } /** * 传入的文件名 */ get filename(): string { return this._filename.value } set filename(value: string) { this._filename.value = value } /** * 交易文件附件数据 */ get fileData(): string { return this._fileData.value } set fileData(value: string) { this._fileData.value = value } /** * 获取Fd域值 */ public getFdVaule(fdName: string): any { let result = '' if (this._fdDict[fdName]) { const decoder = new TextDecoder() //result = this.BitMapInstance.FdBitMap[fdName].RealValue(decoder.decode(this._fdDict[fdName])) //hulei先注销 } return result } /** * 获取参数指定域的组包数据 * @param fdName - 域名称 * @returns 指定域的组包数据 */ public getFdFormatValue(fdName: string): string { let result = ''; if (this._fdDict[fdName]) { const decoder = new TextDecoder(); // result = decoder.decode(this._fdDict[fdName]);//hulei zheg fdDict属性不明确 } return result; } /** * 设置Fd域值 */ public setFdValue(fdName: string, value: any): void { this.setFdFormatValue(fdName, value) if (!fdName.endsWith('0')) { const bigFdName = `${fdName.substring(0, 3)}0` //const fds = this.BitMapInstance.FdBitMap[bigFdName] // delete this._BigFds_[fds.Code] // for (const fd of fds.Children) { // if (fd.Code === fdName) break // if (!this._fdDict[fd.Code]) { // this.setFdFormatValue(fd.Code, null) // } // } } } // private BitMapInstance(BitMapType: any): MsgBitMap { // switch (BitMapType) { // case BitMap.Server: // return MsgBitMap.Instance_Server; // case BitMap.Agn: // return MsgBitMap.Instance_Agn; // case BitMap.Cnaps2: // return MsgBitMap.Instance_Cnaps2; // default: // return MsgBitMap.Instance_Server; // } // } get BitMapInstance(): MsgBitMap { switch (this.BitMapType) { case BitMap.Server: return MsgBitMap.Instance_Server; case BitMap.Agn: return MsgBitMap.Instance_Agn; case BitMap.Cnaps2: return MsgBitMap.Instance_Cnaps2; default: return MsgBitMap.Instance_Server; } } /** * 根据域类型格式化输入数据 */ private setFdFormatValue(fdName: string, value: any): void { // if (this.BitMapInstance.FdBitMap[fdName]) { // // const item = this.BitMapInstance.FdBitMap[fdName] // const encoder = new TextEncoder() // const formatValue = encoder.encode()//item.FormatValue(value) // this._fdDict[fdName] = formatValue // } //hulei 报错了需要处理 } /** * 初始化,清空所有域和附件 * @param type 位图类型 */ public Init(type?: BitMap): void { if (type === undefined) { // this._fdDict.Clear();hulei 这里情况的操作是Dictionary的方法 需要寻找代替的类型 this._fileData = null; // //TransitNode = TransitType.CallServer; //初始化默认为CallServer // //BitMapType = type; this.CustomizeTransitEntry = null; // Extra = new Dictionary(); } else { // this._fdDict = {}; // this._fileData = ''; // this.TransitNode = TransitType.CallServer; // 初始化默认为 CallServer this.BitMapType = type; } } public anilyzeFd(msgData: Uint8Array): boolean { // 拆解位图,报文数据区格式为 5位报文类型+8/16位位图区域+有效数据区 // 标志位,是否采用128位位图 const isBitmap128 = msgData[5].toString(2).padStart(8, '0').startsWith('1'); let bitMap = ''; const msgBit = new Uint8Array(isBitmap128 ? 16 : 8); msgBit.set(msgData.slice(5, 5 + msgBit.length)); // 扩展16位字符串转换为128位01格式的位图字符串 for (const bytes of msgBit) { bitMap += bytes.toString(2).padStart(8, '0'); } // 拆解数据部分 const startIndex = 5 + (isBitmap128 ? 16 : 8); const data = new Uint8Array(msgData.length - startIndex); data.set(msgData.slice(startIndex)); let curPosition = 0; // 日志内容 const logInfo: string[] = []; logInfo.push("解包数据:"); logInfo.push(`解包位图:[${bitMap}]`); try { // 循环解包 for (let i = 0; i < bitMap.length; i++) { if (bitMap[i] === '1') { // 第一位为标志位 if (i + 1 === 1) { continue; } const fdName = (i + 1).toString().padStart(3, '0') + "0"; if (!this.BitMapInstance.FdBitMap[fdName]) { continue; } // 先清理组包数据,否则解析子域会产生数据交错 clearFd(i + 1); const item = this.BitMapInstance.FdBitMap[fdName]; let tmp: Uint8Array | null = null; switch (item.FieldType) { case "-1": break; case "0": // 定长域 tmp = new Uint8Array(item.Length); // 截取数据区域,判定新位置 tmp.set(data.slice(curPosition, curPosition + item.Length)); curPosition += item.Length; break; default: // 变长域 // 获取数据长度 const len = parseInt(item.FieldType, 10); tmp = new Uint8Array(len); tmp.set(data.slice(curPosition, curPosition + len)); curPosition += len; // 获取数据部分 const length = parseInt(encodingToString(tmp), 10); tmp = new Uint8Array(length); tmp.set(data.slice(curPosition, curPosition + length)); curPosition += length; break; } if (!tmp) continue; // 记录日志 const value = encodingToString(tmp); logInfo.push(`第${(i + 1).toString().padStart(3, '0')}域:[${value}]`); if (!item.Children || item.Children.length === 0) { // // 生僻字处理,字符类型FD需要检查 // if ("056".includes(item.Type) && hasCconvKey(value)) { // const val = item.RealValue ? item.RealValue(value) : value; // const newVal = item.FormatValue ? item.FormatValue(cconv(val as string, false)) : val; // tmp = encodingGetBytes(newVal); // }//hulei 生僻字处理暂时放弃 // if (fdDict.hasOwnProperty(item.Code)) { //hulei typescript中是否有类似于wpf的 Dictionary类型 // fdDict[item.Code] = tmp; // } else { // fdDict[item.Code] = tmp; // } } else { // 循环给子域赋值,子域暂时只存在定长域 let index = 0; for (const child of item.Children) { if (index >= tmp.length) break; // 子域为定长 const childLen = Math.min(index + child.Length, tmp.length) - index; const childData = new Uint8Array(childLen); childData.set(tmp.slice(index, index + childLen)); index += childData.length; const chindValue = encodingToString(childData); // // 生僻字处理,字符类型FD需要检查 // if ("056".includes(child.Type) && hasCconvKey(chindValue)) { // const val = child.RealValue ? child.RealValue(chindValue) : chindValue; // const newVal = child.FormatValue ? child.FormatValue(cconv(val as string, false)) : val; // childData = encodingGetBytes(newVal); // }hulei 生僻字处理暂时放弃 // if (fdDict.hasOwnProperty(child.Code)) {//hulei typescript中是否有类似于wpf的 Dictionary类型 // fdDict[child.Code] = childData; // } else { // fdDict[child.Code] = childData; // } } } } } // 解包完成后将解析数据写入交易日志文件 communicationInfo(logInfo.join('\n')); return true; } catch (e) { // 解包失败 logInfo.push(`解包出错:${(e as Error).message}`); communicationInfo(logInfo.join('\n')); return false; } } // 以下是各域的定义,保持与C#代码相同的命名规范 get Fd1(): string { return this.getFdVaule('0010').toString() } set Fd1(value: string) { this.setFdValue('0010', value) } get Fd2(): string { return this.getFdVaule('0020').toString() } set Fd2(value: string) { this.setFdValue('0020', value) } get Fd3(): string { return this.getFdVaule('0030').toString() } set Fd3(value: string) { this.setFdValue('0030', value) } get Fd4(): string { return this.getFdVaule('0040').toString() } set Fd4(value: string) { this.setFdValue('0040', value) } get Fd5(): string { return this.getFdVaule('0050').toString() } set Fd5(value: string) { this.setFdValue('0050', value) } get Fd6(): string { return this.getFdVaule('0060').toString() } set Fd6(value: string) { this.setFdValue('0060', value) } get Fd7(): string { return this.getFdVaule('0070').toString() } set Fd7(value: string) { this.setFdValue('0070', value) } get Fd8(): string { return this.getFdVaule('0080').toString() } set Fd8(value: string) { this.setFdValue('0080', value) } get Fd9_1(): string { return this.getFdVaule('0091').toString() } set Fd9_1(value: string) { this.setFdValue('0091', value) } get Fd9_2(): string { return this.getFdVaule('0092').toString() } set Fd9_2(value: string) { this.setFdValue('0092', value) } get Fd9_3(): string { return this.getFdVaule('0093').toString() } set Fd9_3(value: string) { this.setFdValue('0093', value) } get Fd9_4(): string { return this.getFdVaule('0094').toString() } set Fd9_4(value: string) { this.setFdValue('0094', value) } get Fd10(): string { return this.getFdVaule('0100').toString() } set Fd10(value: string) { this.setFdValue('0100', value) } // 继续实现其他域... get Fd11(): string { return this.getFdVaule('0110').toString() } set Fd11(value: string) { this.setFdValue('0110', value) } get Fd12(): string { return this.getFdVaule('0120').toString() } set Fd12(value: string) { this.setFdValue('0120', value) } get Fd13(): string { return this.getFdVaule('0130').toString() } set Fd13(value: string) { this.setFdValue('0130', value) } get Fd14(): string { return this.getFdVaule('0140').toString() } set Fd14(value: string) { this.setFdValue('0140', value) } get Fd15_1(): string { return this.getFdVaule('0151').toString() } set Fd15_1(value: string) { this.setFdValue('0151', value) } get Fd15_2(): string { return this.getFdVaule('0152').toString() } set Fd15_2(value: string) { this.setFdValue('0152', value) } get Fd15_3(): string { return this.getFdVaule('0153').toString() } set Fd15_3(value: string) { this.setFdValue('0153', value) } get Fd15_4(): string { return this.getFdVaule('0154').toString() } set Fd15_4(value: string) { this.setFdValue('0154', value) } get Fd15_5(): string { return this.getFdVaule('0155').toString() } set Fd15_5(value: string) { this.setFdValue('0155', value) } get Fd15_6(): string { return this.getFdVaule('0156').toString() } set Fd15_6(value: string) { this.setFdValue('0156', value) } get Fd15_7(): string { return this.getFdVaule('0157').toString() } set Fd15_7(value: string) { this.setFdValue('0157', value) } get Fd15_8(): string { return this.getFdVaule('0158').toString() } set Fd15_8(value: string) { this.setFdValue('0158', value) } get Fd15_9(): string { return this.getFdVaule('0159').toString() } set Fd15_9(value: string) { this.setFdValue('0159', value) } get Fd15_A(): string { return this.getFdVaule('015A').toString() } set Fd15_A(value: string) { this.setFdValue('015A', value) } get Fd15_B(): string { return this.getFdVaule('015B').toString() } set Fd15_B(value: string) { this.setFdValue('015B', value) } get Fd15_C(): string { return this.getFdVaule('015C').toString() } set Fd15_C(value: string) { this.setFdValue('015C', value) } get Fd15_D(): string { return this.getFdVaule('015D').toString() } set Fd15_D(value: string) { this.setFdValue('015D', value) } get Fd15_E(): string { return this.getFdVaule('015E').toString() } set Fd15_E(value: string) { this.setFdValue('015E', value) } get Fd15_F(): string { return this.getFdVaule('015F').toString() } set Fd15_F(value: string) { this.setFdValue('015F', value) } get Fd15_G(): string { return this.getFdVaule('015G').toString() } set Fd15_G(value: string) { this.setFdValue('015G', value) } get Fd15_H(): string { return this.getFdVaule('015H').toString() } set Fd15_H(value: string) { this.setFdValue('015H', value) } get Fd15_I(): string { return this.getFdVaule('015I').toString() } set Fd15_I(value: string) { this.setFdValue('015I', value) } get Fd15_J(): string { return this.getFdVaule('015J').toString() } set Fd15_J(value: string) { this.setFdValue('015J', value) } // 继续实现剩余域... get Fd16(): string { return this.getFdVaule('0160').toString() } set Fd16(value: string) { this.setFdValue('0160', value) } get Fd17(): string { return this.getFdVaule('0170').toString() } set Fd17(value: string) { this.setFdValue('0170', value) } get Fd18(): string { return this.getFdVaule('0180').toString() } set Fd18(value: string) { this.setFdValue('0180', value) } get Fd19_1(): string { return this.getFdVaule('0191').toString() } set Fd19_1(value: string) { this.setFdValue('0191', value) } get Fd19_2(): string { return this.getFdVaule('0192').toString() } set Fd19_2(value: string) { this.setFdValue('0192', value) } get Fd19_3(): string { return this.getFdVaule('0193').toString() } set Fd19_3(value: string) { this.setFdValue('0193', value) } get Fd19_4(): string { return this.getFdVaule('0194').toString() } set Fd19_4(value: string) { this.setFdValue('0194', value) } get Fd19_5(): string { return this.getFdVaule('0195').toString() } set Fd19_5(value: string) { this.setFdValue('0195', value) } get Fd20(): string { return this.getFdVaule('0200').toString() } set Fd20(value: string) { this.setFdValue('0200', value) } get Fd21(): string { return this.getFdVaule('0210').toString() } set Fd21(value: string) { this.setFdValue('0210', value) } get Fd22(): string { return this.getFdVaule('0220').toString() } set Fd22(value: string) { this.setFdValue('0220', value) } get Fd30(): string { return this.getFdVaule('0300').toString() } set Fd30(value: string) { this.setFdValue('0300', value) } get Fd66(): string { return this.getFdVaule('0660').toString() } set Fd66(value: string) { this.setFdValue('0660', value) } get Fd23(): string { return this.getFdVaule('0100').toString() } set Fd23(value: string) { this.setFdValue('0100', value) } get Fd24(): string { return this.getFdVaule('0100').toString() } set Fd24(value: string) { this.setFdValue('0100', value) } get Fd25(): string { return this.getFdVaule('0100').toString() } set Fd25(value: string) { this.setFdValue('0100', value) } get Fd26(): string { return this.getFdVaule('0100').toString() } set Fd26(value: string) { this.setFdValue('0100', value) } get Fd27(): string { return this.getFdVaule('0100').toString() } set Fd27(value: string) { this.setFdValue('0100', value) } get Fd28(): string { return this.getFdVaule('0100').toString() } set Fd28(value: string) { this.setFdValue('0100', value) } get Fd29(): string { return this.getFdVaule('0100').toString() } set Fd29(value: string) { this.setFdValue('0100', value) } get Fd31(): string { return this.getFdVaule('0100').toString() } set Fd31(value: string) { this.setFdValue('0100', value) } get Fd32(): string { return this.getFdVaule('0100').toString() } set Fd32(value: string) { this.setFdValue('0100', value) } get Fd33(): string { return this.getFdVaule('0100').toString() } set Fd33(value: string) { this.setFdValue('0100', value) } get Fd34(): string { return this.getFdVaule('0100').toString() } set Fd34(value: string) { this.setFdValue('0100', value) } get Fd35(): string { return this.getFdVaule('0100').toString() } set Fd35(value: string) { this.setFdValue('0100', value) } get Fd36(): string { return this.getFdVaule('0100').toString() } set Fd36(value: string) { this.setFdValue('0100', value) } get Fd37(): string { return this.getFdVaule('0100').toString() } set Fd37(value: string) { this.setFdValue('0100', value) } get Fd38(): string { return this.getFdVaule('0100').toString() } set Fd38(value: string) { this.setFdValue('0100', value) } get Fd39(): string { return this.getFdVaule('0100').toString() } set Fd39(value: string) { this.setFdValue('0100', value) } get Fd40(): string { return this.getFdVaule('0100').toString() } set Fd40(value: string) { this.setFdValue('0100', value) } get Fd41(): string { return this.getFdVaule('0100').toString() } set Fd41(value: string) { this.setFdValue('0100', value) } get Fd42(): string { return this.getFdVaule('0100').toString() } set Fd42(value: string) { this.setFdValue('0100', value) } get Fd43(): string { return this.getFdVaule('0100').toString() } set Fd43(value: string) { this.setFdValue('0100', value) } get Fd44(): string { return this.getFdVaule('0100').toString() } set Fd44(value: string) { this.setFdValue('0100', value) } get Fd45(): string { return this.getFdVaule('0100').toString() } set Fd45(value: string) { this.setFdValue('0100', value) } get Fd46(): string { return this.getFdVaule('0100').toString() } set Fd46(value: string) { this.setFdValue('0100', value) } get Fd47(): string { return this.getFdVaule('0100').toString() } set Fd47(value: string) { this.setFdValue('0100', value) } get Fd48(): string { return this.getFdVaule('0100').toString() } set Fd48(value: string) { this.setFdValue('0100', value) } get Fd49(): string { return this.getFdVaule('0100').toString() } set Fd49(value: string) { this.setFdValue('0100', value) } get Fd50(): string { return this.getFdVaule('0100').toString() } set Fd50(value: string) { this.setFdValue('0100', value) } get Fd51(): string { return this.getFdVaule('0100').toString() } set Fd51(value: string) { this.setFdValue('0100', value) } get Fd52(): string { return this.getFdVaule('0100').toString() } set Fd52(value: string) { this.setFdValue('0100', value) } get Fd53(): string { return this.getFdVaule('0100').toString() } set Fd53(value: string) { this.setFdValue('0100', value) } get Fd54(): string { return this.getFdVaule('0100').toString() } set Fd54(value: string) { this.setFdValue('0100', value) } get Fd55(): string { return this.getFdVaule('0100').toString() } set Fd55(value: string) { this.setFdValue('0100', value) } get Fd56(): string { return this.getFdVaule('0100').toString() } set Fd56(value: string) { this.setFdValue('0100', value) } get Fd57(): string { return this.getFdVaule('0100').toString() } set Fd57(value: string) { this.setFdValue('0100', value) } get Fd58(): string { return this.getFdVaule('0100').toString() } set Fd58(value: string) { this.setFdValue('0100', value) } get Fd59(): string { return this.getFdVaule('0100').toString() } set Fd59(value: string) { this.setFdValue('0100', value) } get Fd92(): string { return this.getFdVaule('0100').toString() } set Fd92(value: string) { this.setFdValue('0100', value) } get Fd98(): string { return this.getFdVaule('0100').toString() } set Fd98(value: string) { this.setFdValue('0100', value) } /** * 通讯外端 */ get TransitNode(): TransitType { return this._transitNode; } set TransitNode(value: TransitType) { this._transitNode = value; this.TransitName = value.toString(); } // 实现剩余所有域... // 按照相同模式实现Fd21到Fd47的所有域 } function clearFd(arg0: number) { throw new Error('Function not implemented.'); } function encodingToString(tmp: Uint8Array): string { throw new Error('Function not implemented.'); } function communicationInfo(arg0: string) { throw new Error('Function not implemented.'); }