# @ohos.secureElement (安全å•元的通é“管ç†) 本模å—主è¦ç”¨äºŽæ“作åŠç®¡ç†å®‰å…¨å•元(SecureElement,简称SE),电å设备上å¯èƒ½å˜åœ¨çš„安全å•元有eSE(Embedded SE)å’ŒSIMå¡ã€‚文档ä¸å‡ºçŽ°çš„SEæœåŠ¡ä¸ºSEService实例,å‚è§[newSEService](#omapinewseservice)。 对于文档ä¸å‡ºçŽ°ä»¥ä¸‹ç±»åž‹è¯´æ˜Žï¼š | 类型 | 说明 | | ------- | ---------------------------------------------- | | Reader | æ¤ç±»çš„实例表示该设备支æŒçš„SE,如果支æŒeSEå’ŒSIM,则返回两个实例。 | | Session | æ¤ç±»çš„实例表示在æŸä¸ªSE Reader实例上创建连接会è¯ã€‚ | | Channel | æ¤ç±»çš„实例表示在æŸä¸ªSession实例上创建通é“,å¯èƒ½ä¸ºåŸºç¡€é€šé“或逻辑通é“。 | > **说明:** > > 本模å—首批接å£ä»ŽAPI version 10开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„æ–°å¢žæŽ¥å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 ## **导入模å—** ```js import { omapi } from '@kit.ConnectivityKit'; ``` ## ServiceState 定义ä¸åŒçš„SEæœåŠ¡çŠ¶æ€å€¼ã€‚ **系统能力:** SystemCapability.Communication.SecureElement | åç§° | 值 | 说明 | | ------------ | ---- | ------------------ | | DISCONNECTED | 0 | SEæœåŠ¡çŠ¶æ€å·²æ–开。 | | CONNECTED | 1 | SEæœåŠ¡çŠ¶æ€å·²è¿žæŽ¥ã€‚ | ## omapi.newSEService newSEService(type: 'serviceState', callback: Callback\<ServiceState>): SEService 建立一个å¯ç”¨äºŽè¿žæŽ¥åˆ°ç³»ç»Ÿä¸æ‰€æœ‰å¯ç”¨SE的新连接(æœåŠ¡ï¼‰ã€‚è¿žæŽ¥è¿‡ç¨‹è¾ƒä¸ºè€—æ—¶ï¼Œæ‰€ä»¥æ¤æ–¹æ³•ä»…æä¾›å¼‚æ¥æ–¹å¼è¿›è¡Œçš„。使用callback异æ¥å›žè°ƒã€‚ 仅当指定的回调或者当[isConnected](#seserviceisconnected)方法返回true时,该返回SEService对象是å¯ç”¨çš„。 > **说明:** > 从 API version 10 开始支æŒï¼Œä»Ž API version 12 开始废弃,建议使用[createService](#omapicreateservice12)替代。 **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ---------------------------------------------------- | ------ | -------------------- | | type | string | 是 | 固定填'serviceState' 。 | | callback | Callback<[ServiceState](#servicestate)> | 是 | 返回SEæœåŠ¡çŠ¶æ€çš„回调 。| **返回值:** | **类型** | **说明** | | -------- | --------- | | SEService | SEæœåŠ¡å®žä¾‹ã€‚ | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | 错误信æ¯| | ------- | -------| | 401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | | 801 | Capability not supported. | **示例:** ```js import { omapi } from '@kit.ConnectivityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; function secureElementDemo() { // get the service try { seService = omapi.newSEService("serviceState", (state) => { hilog.info(0x0000, 'testTag', 'se service state = %{public}s', JSON.stringify(state)); }); } catch (error) { hilog.error(0x0000, 'testTag', 'newSEService error %{public}s', JSON.stringify(error)); } if (seService == undefined || !seService.isConnected()) { hilog.error(0x0000, 'testTag', 'secure element service disconnected.'); return; } } ``` ## omapi.createService<sup>12+</sup> createService(): Promise\<SEService>; 建立一个å¯ç”¨äºŽè¿žæŽ¥åˆ°ç³»ç»Ÿä¸æ‰€æœ‰å¯ç”¨SE的新连接(æœåŠ¡ï¼‰ã€‚è¿žæŽ¥è¿‡ç¨‹è¾ƒä¸ºè€—æ—¶ï¼Œæ‰€ä»¥æ¤æ–¹æ³•ä»…æä¾›å¼‚æ¥æ–¹å¼ã€‚使用Promise异æ¥å›žè°ƒã€‚ 仅当[isConnected](#seserviceisconnected)方法返回true时,该返回SEService对象是å¯ç”¨çš„。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | :-------- | :--------- | | Promise\<[SEService](#seservice)> | 以Promiseå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„SEæœåŠ¡å®žä¾‹ã€‚ | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** ```js import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; function secureElementDemo() { omapi.createService().then((data) => { seService = data; if (seService == undefined || !seService.isConnected()) { hilog.error(0x0000, 'testTag', 'seservice state disconnected'); return; } hilog.info(0x0000, 'testTag', 'seservice state connected'); }).catch((error : BusinessError)=> { hilog.error(0x0000, 'testTag', 'createService error %{public}s', JSON.stringify(error)); }); } ``` ## SEService SEService表示å¯ç”¨äºŽè¿žæŽ¥åˆ°ç³»ç»Ÿä¸æ‰€æœ‰å¯ç”¨SE的连接(æœåŠ¡ï¼‰ï¼Œé€šè¿‡[createService](#omapicreateservice12)获å–SEService实例。 ### SEService.getReaders getReaders(): Reader[] 返回å¯ç”¨SE Reader的数组,包å«è¯¥è®¾å¤‡ä¸Šæ”¯æŒçš„æ‰€æœ‰çš„安全å•元。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | :------- | :--------------------- | | [Reader](#reader)[] | 返回å¯ç”¨Reader对象数组。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { omapi } from '@kit.ConnectivityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; let seReaders : omapi.Reader[]; // Before use seService, initialization for seService is required function secureElementDemo() { // get readers try { seReaders = seService.getReaders(); } catch (error) { hilog.error(0x0000, 'testTag', 'getReaders error %{public}s', JSON.stringify(error)); } if (seReaders == undefined || seReaders.length == 0) { hilog.error(0x0000, 'testTag', 'no valid reader found.'); return; } } ``` ### SEService.isConnected isConnected(): boolean 检查SEæœåŠ¡æ˜¯å¦å·²è¿žæŽ¥ã€‚ **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | :------- | :--------------------------------------------- | | boolean | true: SEæœåŠ¡çŠ¶æ€å·²è¿žæŽ¥ï¼Œfalse: SEæœåŠ¡çŠ¶æ€å·²æ–开。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** ```JS import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; function secureElementDemo() { // get the service try { seService = omapi.newSEService("serviceState", (state) => { hilog.info(0x0000, 'testTag', 'se service state = %{public}s', JSON.stringify(state)); }); } catch (error) { hilog.error(0x0000, 'testTag', 'newSEService error %{public}s', JSON.stringify(error)); } if (seService == undefined || !seService.isConnected()) { hilog.error(0x0000, 'testTag', 'secure element service disconnected.'); return; } } ``` ### SEService.shutdown shutdown(): void 释放该Service分é…的所有SE资æºã€‚æ¤åŽ[isConnected](#seserviceisconnected)将返回false。 **系统能力:** SystemCapability.Communication.SecureElement **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; // Before use seService, initialization for seService is required try { seService.shutdown(); } catch (error) { hilog.error(0x0000, 'testTag', 'shutdown error %{public}s', JSON.stringify(error)); } ``` ### SEService.getVersion getVersion(): string 返回æ¤å®žçŽ°æ‰€åŸºäºŽçš„Open Mobile API规范的版本å·ã€‚ **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | -------------------------------------------------- | | string | OMA版本å·ï¼ˆä¾‹å¦‚,“3.3â€è¡¨ç¤ºOpen Mobile API规范版本3.3) | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```JS import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let seService : omapi.SEService; // Before use seService, initialization for seService is required try { let version = seService.getVersion(); hilog.error(0x0000, 'testTag', 'version %{public}s', JSON.stringify(version)); } catch (error) { hilog.error(0x0000, 'testTag', 'getVersion error %{public}s', JSON.stringify(error)); } ``` ## Reader Reader的实例表示该设备支æŒçš„SE,如果支æŒeSEå’ŒSIM,则返回两个实例。通过[SEService.getReaders](#seservicegetreaders)获å–Reader实例。 ### Reader.getName getName(): string 返回æ¤Readerçš„å称。如果æ¤è¯»å¡å™¨æ˜¯SIM Reader,则其å称必须为“SIMâ€ã€‚如果读å¡å™¨æ˜¯eSE,则其å称须为“eSEâ€ã€‚ **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ---------- | | string | [Reader](#reader)å称。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[NFC错误ç ](errorcode-nfc.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seReaders : omapi.Reader[]; // Before use seReaders, initialization for seReaders is required try { let reader = seReaders[0]; // change it to the selected reader, ese or sim. let name = reader.getName(); hilog.info(0x0000, 'testTag', 'name %{public}s', JSON.stringify(name)); } catch (error) { hilog.error(0x0000, 'testTag', 'getName error %{public}s', JSON.stringify(error)); } ``` ### Reader.isSecureElementPresent isSecureElementPresent(): boolean 检查当å‰Reader所对应的安全å•元是å¦å¯ç”¨ã€‚ **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | -------------------------------------------- | | boolean | true: 安全å•å…ƒå¯ç”¨ï¼Œ false: 安全å•å…ƒä¸å¯ç”¨ã€‚ | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | | 801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seReaders : omapi.Reader[]; // Before use seReaders, initialization for seReaders is required try { let reader = seReaders[0]; // change it to the selected reader, ese or sim. let isPresent = reader.isSecureElementPresent(); hilog.info(0x0000, 'testTag', 'isPresent %{public}s', JSON.stringify(isPresent)); } catch (error) { hilog.error(0x0000, 'testTag', 'isSecureElementPresent error %{public}s', JSON.stringify(error)); } ``` ### Reader.openSession openSession(): Session 在SE Reader实例上创建连接会è¯ï¼Œè¿”回Session实例。在一个Reader上å¯èƒ½åŒæ—¶æ‰“开多个会è¯ã€‚ **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ------------------------------ | | [Session](#session) | 连接会è¯Session实例。| **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | | 801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seReaders : omapi.Reader[]; let seSession : omapi.Session; // Before use seReaders, initialization for seReaders is required function secureElementDemo() { try { let reader = seReaders[0]; // change it to the selected reader, ese or sim. seSession = reader.openSession(); } catch (error) { hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); } if (seSession == undefined) { hilog.error(0x0000, 'testTag', 'seSession invalid.'); return; } } ``` ### Reader.closeSessions closeSessions(): void å…³é—在æ¤Reader上打开的所有Session。所有这些Session打开的所有Channel都将关é—。 **系统能力:** SystemCapability.Communication.SecureElement **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | | 801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seReaders : omapi.Reader[]; let seSession : omapi.Session; let reader : omapi.Reader; // Before use seReaders, initialization for seReaders is required function secureElementDemo() { try { reader = seReaders[0]; // change it to the selected reader, ese or sim. seSession = reader.openSession(); } catch (error) { hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); } if (seSession == undefined) { hilog.error(0x0000, 'testTag', 'seSession invalid.'); return; } try { reader.closeSessions(); } catch (error) { hilog.error(0x0000, 'testTag', 'closeSessions error %{public}s', JSON.stringify(error)); } } ``` ## Session Session的实例表示在æŸä¸ªSE Reader实例上创建连接会è¯ã€‚通过[Reader.openSession](#readeropensession)获å–Session实例。 ### Session.getReader getReader(): Reader èŽ·å–æä¾›æ¤Sessionçš„Reader实例。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | --------------------------- | | [Reader](#reader) | 返回æ¤Sessionçš„Reader实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seReaders : omapi.Reader[]; let seSession : omapi.Session; let reader : omapi.Reader; // Before use seReaders, initialization for seReaders is required function secureElementDemo() { try { reader = seReaders[0]; // change it to the selected reader, ese or sim. seSession = reader.openSession(); } catch (error) { hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); } if (seSession == undefined) { hilog.error(0x0000, 'testTag', 'seSession invalid.'); return; } try { let sessionReader = seSession.getReader(); } catch (error) { hilog.error(0x0000, 'testTag', 'getReader error %{public}s', JSON.stringify(error)); } } ``` ### Session.getATR getATR(): number[] 获å–该SEçš„ATR。如果该SEçš„ATRä¸å¯ç”¨ï¼Œåˆ™åº”返回空数组。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | -------------------------------------------- | | number[] | 返回SEçš„ATR,SEçš„ATRä¸å¯ç”¨æ—¶ï¼Œè¿”回空的数组。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | | 801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; // Before use seSession, initialization for seSession is required try { let atr = seSession.getATR(); hilog.info(0x0000, 'testTag', 'atr %{public}s', JSON.stringify(atr)); } catch (error) { hilog.error(0x0000, 'testTag', 'getATR error %{public}s', JSON.stringify(error)); } ``` ### Session.close close(): void å…³é—与SE的当å‰ä¼šè¯è¿žæŽ¥ã€‚è¿™å°†å…³é—æ¤Session打开的所有Channel。 **系统能力:** SystemCapability.Communication.SecureElement **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | | 801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; // Before use seSession, initialization for seSession is required try { seSession.close(); } catch (error) { hilog.error(0x0000, 'testTag', 'close error %{public}s', JSON.stringify(error)); } ``` ### Session. isClosed isClosed(): boolean 检查Session是å¦å…³é—。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ------------------------------------ | | boolean | true:Session状æ€å·²å…³é—,false:Session是打开的。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```Js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; // Before use seSession, initialization for seSession is required try { let isClosed = seSession.isClosed(); hilog.info(0x0000, 'testTag', 'isClosed %{public}s', JSON.stringify(isClosed)); } catch (error) { hilog.error(0x0000, 'testTag', 'isClosed error %{public}s', JSON.stringify(error)); } ``` ### Session.closeChannels closeChannels(): void 关闿¤Session上打开的所有Channel。 **系统能力:** SystemCapability.Communication.SecureElement **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |801 | Capability not supported. | | 3300101 | IllegalStateError, service state exception. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; // Before use seSession, initialization for seSession is required try { seSession.closeChannels(); } catch (error) { hilog.error(0x0000, 'testTag', 'closeChannels error %{public}s', JSON.stringify(error)); } ``` ### Session.openBasicChannel openBasicChannel(aid: number[]): Promise\<Channel> 打开基础通é“,å‚考[ISO 7816-4]å议,返回基础Channel实例对象。SEä¸èƒ½æä¾›åŸºç¡€Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用Promise异æ¥å›žè°ƒ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | -------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 |在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。| **返回值:** | **类型** | **说明** | | -------- | --------------------- | | Promise\<[Channel](#channel)> | 以Promiseå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„基础Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openBasicChannel(aidArray).then((data) => { seChannel = data; }).catch((error : BusinessError)=> { hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openBasicChannel openBasicChannel(aid: number[], callback: AsyncCallback\<Channel>): void 打开基础通é“,å‚考[ISO 7816-4]å议,返回基础Channel实例对象。SEä¸èƒ½æä¾›åŸºç¡€Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callbackå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„基础Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openBasicChannel(aidArray, (error, data) => { if (error) { hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); } else { seChannel = data; } }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openBasicChannel openBasicChannel(aid: number[], p2: number): Promise\<Channel> 打开基础通é“,å‚考[ISO 7816-4]å议,返回基础Channel实例对象。SEä¸èƒ½æä¾›åŸºç¡€Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用Promise异æ¥å›žè°ƒ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | -------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | p2 | number | 是 |在该Channel上执行的SELECT APDUçš„P2傿•°ã€‚ | **返回值:** | **类型** | **说明** | | -------- | --------------------- | | Promise\<[Channel](#channel)> | 以Promiseå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„基础Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; let p2 : number = 0x00; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openBasicChannel(aidArray, p2).then((data) => { seChannel = data; }).catch((error : BusinessError)=> { hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openBasicChannel openBasicChannel(aid: number[], p2:number, callback: AsyncCallback\<Channel>): void 打开基础通é“,å‚考[ISO 7816-4]å议,返回基础Channel实例对象。SEä¸èƒ½æä¾›åŸºç¡€Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | p2 | number | 是 | æ¤Channel上执行SELECT APDU命令的P2傿•°ã€‚ | | callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callbackå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„基础Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; let p2 : number = 0x00; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openBasicChannel(aidArray, p2, (error, data) => { if (error) { hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); } else { seChannel = data; } }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openLogicalChannel openLogicalChannel(aid: number[]): Promise\<Channel> 打开逻辑通é“,å‚考[ISO 7816-4]å议,返回逻辑Channel实例对象。SEä¸èƒ½æä¾›é€»è¾‘Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用Promise异æ¥å›žè°ƒ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | -------- | ------ | --------------------------------------- | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | **返回值:** | **类型** | **说明** | | -------- | ------------------------------------------------------------ | | Promise\<[Channel](#channel)> | 以Promiseå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„逻辑Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected or a logical channel is already open to a non-multi-selectable applet. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openLogicalChannel(aidArray).then((data) => { seChannel = data; }).catch((error : BusinessError)=> { hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openLogicalChannel openLogicalChannel(aid: number[], callback: AsyncCallback\<Channel>): void 打开逻辑通é“,å‚考[ISO 7816-4]å议,返回逻辑Channel实例对象。SEä¸èƒ½æä¾›é€»è¾‘Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callbackå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„逻辑Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected or a logical channel is already open to a non-multi-selectable applet. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openLogicalChannel(aidArray, (error, data) => { if (error) { hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); } else { seChannel = data; } }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openLogicalChannel openLogicalChannel(aid: number[], p2: number): Promise\<Channel> 打开逻辑通é“,å‚考[ISO 7816-4]å议,返回逻辑Channel实例对象。SEä¸èƒ½æä¾›é€»è¾‘Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用Promise异æ¥å›žè°ƒ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | -------- | ------ | ----------------------------------------- | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | p2 | number | 是 | æ¤Channel上执行SELECT APDU命令的P2傿•°ã€‚ | **返回值:** | **类型** | **说明** | | -------- | -------------- | | Promise\<[Channel](#channel)> | 以Promiseå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„逻辑Channel实例对象。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected or a logical channel is already open to a non-multi-selectable applet. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; let p2 : number = 0x00; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openLogicalChannel(aidArray, p2).then((data) => { seChannel = data; }).catch((error : BusinessError)=> { hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ### Session.openLogicalChannel openLogicalChannel(aid: number[], p2: number, callback: AsyncCallback\<Channel>):void 打开逻辑通é“,å‚考[ISO 7816-4]å议,返回Channel实例对象。SEä¸èƒ½æä¾›é€»è¾‘Channelæˆ–åº”ç”¨ç¨‹åºæ²¡æœ‰è®¿é—®SEçš„æƒé™æ—¶ï¼Œè¿”回null。使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ | | aid | number[] | 是 | 在æ¤Channel上选择的Appletçš„AID或如果没有Applet被选择时空的数组。 | | p2 | number | 是 | æ¤Channel上执行SELECT APDU命令的P2傿•°ã€‚ | | callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callbackå½¢å¼å¼‚æ¥è¿”回å¯ç”¨çš„逻辑Channel对象实例。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | | 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected or a logical channel is already open to a non-multi-selectable applet. | | 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; let p2 : number = 0x00; // Before use seSession, initialization for seSession is required function secureElementDemo() { try { // change the aid value for open channel. seSession.openLogicalChannel(aidArray, p2, (error, data) => { if (error) { hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); } else { seChannel = data; } }); } catch (exception) { hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); } if (seChannel == undefined) { hilog.error(0x0000, 'testTag', 'seChannel invalid.'); return; } } ``` ## Channel Channel的实例表示在æŸä¸ªSession实例上创建通é“,å¯èƒ½ä¸ºåŸºç¡€é€šé“或逻辑通é“。通过[Session.openBasicChannel](#sessionopenbasicchannel)或[Session.openLogicalChannel](#sessionopenlogicalchannel)获å–Channel实例。 ### Channel.getSession getSession(): Session èŽ·å–æ‰“开该Channelçš„Session对象。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ----------------------------- | | [Session](#session) | 该Channel绑定的Session 对象。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seSession : omapi.Session; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required try { seSession = seChannel.getSession(); } catch (exception) { hilog.error(0x0000, 'testTag', 'getSession exception %{public}s', JSON.stringify(exception)); } ``` ### Channel.close close(): void å…³é—Channel。 **系统能力:** SystemCapability.Communication.SecureElement **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required try { seChannel.close(); } catch (exception) { hilog.error(0x0000, 'testTag', 'close exception %{public}s', JSON.stringify(exception)); } ``` ### Channel.isBasicChannel isBasicChannel(): boolean 检查该Channel是å¦ä¸ºåŸºç¡€Channel。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ------------------------------------------------------------ | | boolean | true: 该Channel是基础Channel, false:该Channel逻辑Channel 。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required try { let isBasic = seChannel.isBasicChannel(); hilog.info(0x0000, 'testTag', 'isBasic = %{public}s', JSON.stringify(isBasic)); } catch (exception) { hilog.error(0x0000, 'testTag', 'isBasicChannel exception %{public}s', JSON.stringify(exception)); } ``` ### Channel.isClosed isClosed(): boolean 检查该Channel是å¦å·²è¢«å…³é—。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | --------------------------------------------- | | boolean | true: Channel是关é—的,false: 䏿˜¯å…³é—的。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required try { let isClosed = seChannel.isClosed(); hilog.info(0x0000, 'testTag', 'isClosed = %{public}s', JSON.stringify(isClosed)); } catch (exception) { hilog.error(0x0000, 'testTag', 'isClosed exception %{public}s', JSON.stringify(exception)); } ``` ### Channel.getSelectResponse getSelectResponse(): number[] 获å–SELECT Appletæ—¶çš„å“应数æ®ï¼ŒåŒ…å«çжæ€å—。 **系统能力:** SystemCapability.Communication.SecureElement **返回值:** | **类型** | **说明** | | -------- | ------------------------------------------------------------ | | number[] | SELECT Appletæ—¶çš„å“应数æ®ï¼ŒåŒ…å«çжæ€å—。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ----------------------------------------- | | 801 | Capability not supported. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required try { let response = seChannel.getSelectResponse(); hilog.info(0x0000, 'testTag', 'response = %{public}s', JSON.stringify(response)); } catch (exception) { hilog.error(0x0000, 'testTag', 'getSelectResponse exception %{public}s', JSON.stringify(exception)); } ``` ### Channel.transmit transmit(command: number[]): Promise\<number[]> å‘SEå‘é€APDUæ•°æ®ï¼Œæ•°æ®ç¬¦åˆISO/IEC 7816规范。使用Promise异æ¥å›žè°ƒ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | -------- | ------ | ------------------------------------- | | command | number[] | 是 | 需è¦å‘é€åˆ°SEçš„APDUæ•°æ®ã€‚ | **返回值:** | **类型** | **说明** | | -------- | -------------- | | Promise\<number[]> | 以Promiseå½¢å¼å¼‚æ¥è¿”回接收到的å“应APDUæ•°æ®ï¼Œnumber数组。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. | | 3300103 | SecurityError, the command is filtered by the security policy. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required let cmdData = [0x01, 0x02, 0x03, 0x04]; // please change the raw data to be correct. try { seChannel.transmit(cmdData).then((response) => { hilog.info(0x0000, 'testTag', 'transmit response = %{public}s.', JSON.stringify(response)); }).catch((error : BusinessError) => { hilog.error(0x0000, 'testTag', 'transmit error = %{public}s.', JSON.stringify(error)); }); } catch (exception) { hilog.error(0x0000, 'testTag', 'transmit exception = %{public}s.', JSON.stringify(exception)); } ``` ### Channel.transmit transmit(command: number[], callback: AsyncCallback\<number[]>): void å‘SEå‘é€APDUæ•°æ®ï¼Œæ•°æ®ç¬¦åˆISO/IEC 7816规范。使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Communication.SecureElement **傿•°ï¼š** | **傿•°å** | **类型** | **å¿…å¡«** | **说明** | | ---------- | ----------------------- | ------ | ------------------------------------- | | command | number[] | 是 | 需è¦å‘é€åˆ°SEçš„APDUæ•°æ®ã€‚ | | callback | AsyncCallback\<number[]> | 是 | 返回接收到的å“应APDUæ•°æ®ï¼Œnumber数组。 | **错误ç :** 错误ç 的详细介ç»è¯·å‚è§[SE错误ç ](errorcode-se.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | -------------------------------- | |401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | |801 | Capability not supported. | | 3300101 | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. | | 3300103 | SecurityError, the command is filtered by the security policy. | | 3300104 | IOError, there is a communication problem to the reader or the SE. | **示例:** <!--code_no_check--> ```js import { hilog } from '@kit.PerformanceAnalysisKit'; import { omapi } from '@kit.ConnectivityKit'; let seChannel : omapi.Channel; // Before use seChannel, initialization for seChannel is required let cmdData = [0x01, 0x02, 0x03, 0x04]; // please change the raw data to be correct. try { seChannel.transmit(cmdData, (error, response) => { if (error) { hilog.error(0x0000, 'testTag', 'transmit error %{public}s', JSON.stringify(error)); } else { hilog.info(0x0000, 'testTag', 'transmit response = %{public}s.', JSON.stringify(response)); } }); } catch (exception) { hilog.error(0x0000, 'testTag', 'transmit exception %{public}s', JSON.stringify(exception)); } ```