diff --git a/src/main/ets/utils/ToolsHelper.ets b/src/main/ets/utils/ToolsHelper.ets index 20600ba..b7a8e53 100644 --- a/src/main/ets/utils/ToolsHelper.ets +++ b/src/main/ets/utils/ToolsHelper.ets @@ -1,6 +1,6 @@ import promptAction from '@ohos.promptAction'; import { BusinessError, deviceInfo } from '@kit.BasicServicesKit'; -import { HashMap, util } from '@kit.ArkTS'; +import { buffer, HashMap, util } from '@kit.ArkTS'; import { DeviceInfo } from '../bean/DeviceInfo'; import { common } from '@kit.AbilityKit'; import { md5_hex } from '../util/md5'; @@ -433,6 +433,11 @@ export class ToolsHelper { return decoder.decodeToString(new Uint8Array(arrayBuffer)) } + static stringToArrayBuffer(str: string): ArrayBuffer { + let buf = buffer.from(str, 'utf-8'); // 使用 UTF-8 编码 + return buf.buffer; + } + private static setTimeOutMap: Map = new Map() private static uniqueIdMap = new WeakMap();