1# @ohos.secureElement (安全单元的通道管理) 2 3本模块主要用于操作及管理安全单元(SecureElement,简称SE),电子设备上可能存在的安全单元有eSE(Embedded SE)和SIM卡。文档中出现的SE服务为SEService实例,参见[newSEService](#omapinewseservice)。 4 5对于文档中出现以下类型说明: 6 7| 类型 | 说明 | 8| ------- | ---------------------------------------------- | 9| Reader | 此类的实例表示该设备支持的SE,如果支持eSE和SIM,则返回两个实例。 | 10| Session | 此类的实例表示在某个SE Reader实例上创建连接会话。 | 11| Channel | 此类的实例表示在某个Session实例上创建通道,可能为基础通道或逻辑通道。 | 12 13> **说明:** 14> 15> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 16 17## **导入模块** 18 19```js 20import { omapi } from '@kit.ConnectivityKit'; 21``` 22 23## ServiceState 24 25定义不同的SE服务状态值。 26 27**系统能力:** SystemCapability.Communication.SecureElement 28 29| 名称 | 值 | 说明 | 30| ------------ | ---- | ------------------ | 31| DISCONNECTED | 0 | SE服务状态已断开。 | 32| CONNECTED | 1 | SE服务状态已连接。 | 33 34## omapi.newSEService 35 36newSEService(type: 'serviceState', callback: Callback\<ServiceState>): SEService 37 38建立一个可用于连接到系统中所有可用SE的新连接(服务)。连接过程较为耗时,所以此方法仅提供异步方式进行的。使用callback异步回调。 39 40仅当指定的回调或者当[isConnected](#seserviceisconnected)方法返回true时,该返回SEService对象是可用的。 41 42> **说明:** 43> 从 API version 10 开始支持,从 API version 12 开始废弃,建议使用[createService](#omapicreateservice12)替代。 44 45**系统能力:** SystemCapability.Communication.SecureElement 46 47**参数:** 48 49| **参数名** | **类型** | **必填** | **说明** | 50| ---------- | ---------------------------------------------------- | ------ | -------------------- | 51| type | string | 是 | 固定填'serviceState' 。 | 52| callback | Callback<[ServiceState](#servicestate)> | 是 | 返回SE服务状态的回调 。| 53 54**返回值:** 55 56| **类型** | **说明** | 57| -------- | --------- | 58| SEService | SE服务实例。 | 59 60**错误码:** 61 62错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 63 64| 错误码ID | 错误信息| 65| ------- | -------| 66| 401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 67| 801 | Capability not supported. | 68 69**示例:** 70 71```js 72import { omapi } from '@kit.ConnectivityKit'; 73import { hilog } from '@kit.PerformanceAnalysisKit'; 74 75let seService : omapi.SEService; 76 77function secureElementDemo() { 78 // get the service 79 try { 80 seService = omapi.newSEService("serviceState", (state) => { 81 hilog.info(0x0000, 'testTag', 'se service state = %{public}s', JSON.stringify(state)); 82 }); 83 } catch (error) { 84 hilog.error(0x0000, 'testTag', 'newSEService error %{public}s', JSON.stringify(error)); 85 } 86 if (seService == undefined || !seService.isConnected()) { 87 hilog.error(0x0000, 'testTag', 'secure element service disconnected.'); 88 return; 89 } 90} 91``` 92 93## omapi.createService<sup>12+</sup> 94 95createService(): Promise\<SEService>; 96 97建立一个可用于连接到系统中所有可用SE的新连接(服务)。连接过程较为耗时,所以此方法仅提供异步方式。使用Promise异步回调。 98 99仅当[isConnected](#seserviceisconnected)方法返回true时,该返回SEService对象是可用的。 100 101**系统能力:** SystemCapability.Communication.SecureElement 102 103**返回值:** 104 105| **类型** | **说明** | 106| :-------- | :--------- | 107| Promise\<[SEService](#seservice)> | 以Promise形式异步返回可用的SE服务实例。 | 108 109**错误码:** 110 111错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 112 113| 错误码ID | 错误信息 | 114| -------- | ----------------------------------------- | 115| 801 | Capability not supported. | 116 117**示例:** 118 119```js 120import { omapi } from '@kit.ConnectivityKit'; 121import { BusinessError } from '@kit.BasicServicesKit'; 122import { hilog } from '@kit.PerformanceAnalysisKit'; 123 124let seService : omapi.SEService; 125 126function secureElementDemo() { 127 omapi.createService().then((data) => { 128 seService = data; 129 if (seService == undefined || !seService.isConnected()) { 130 hilog.error(0x0000, 'testTag', 'seservice state disconnected'); 131 return; 132 } 133 hilog.info(0x0000, 'testTag', 'seservice state connected'); 134 }).catch((error : BusinessError)=> { 135 hilog.error(0x0000, 'testTag', 'createService error %{public}s', JSON.stringify(error)); 136 }); 137} 138``` 139 140## SEService 141 142SEService表示可用于连接到系统中所有可用SE的连接(服务),通过[createService](#omapicreateservice12)获取SEService实例。 143 144### SEService.getReaders 145 146getReaders(): Reader[] 147 148返回可用SE Reader的数组,包含该设备上支持的所有的安全单元。 149 150**系统能力:** SystemCapability.Communication.SecureElement 151 152**返回值:** 153 154| **类型** | **说明** | 155| :------- | :--------------------- | 156| [Reader](#reader)[] | 返回可用Reader对象数组。 | 157 158**错误码:** 159 160错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 161 162| 错误码ID | 错误信息 | 163| -------- | ----------------------------------------- | 164| 801 | Capability not supported. | 165 166**示例:** 167 168<!--code_no_check--> 169```js 170import { omapi } from '@kit.ConnectivityKit'; 171import { hilog } from '@kit.PerformanceAnalysisKit'; 172 173let seService : omapi.SEService; 174let seReaders : omapi.Reader[]; 175 176// Before use seService, initialization for seService is required 177function secureElementDemo() { 178 // get readers 179 try { 180 seReaders = seService.getReaders(); 181 } catch (error) { 182 hilog.error(0x0000, 'testTag', 'getReaders error %{public}s', JSON.stringify(error)); 183 } 184 if (seReaders == undefined || seReaders.length == 0) { 185 hilog.error(0x0000, 'testTag', 'no valid reader found.'); 186 return; 187 } 188} 189``` 190 191### SEService.isConnected 192 193isConnected(): boolean 194 195检查SE服务是否已连接。 196 197**系统能力:** SystemCapability.Communication.SecureElement 198 199**返回值:** 200 201| **类型** | **说明** | 202| :------- | :--------------------------------------------- | 203| boolean | true: SE服务状态已连接,false: SE服务状态已断开。 | 204 205**错误码:** 206 207错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 208 209| 错误码ID | 错误信息 | 210| -------- | ----------------------------------------- | 211| 801 | Capability not supported. | 212 213**示例:** 214 215 216```JS 217import { omapi } from '@kit.ConnectivityKit'; 218import { BusinessError } from '@kit.BasicServicesKit'; 219import { hilog } from '@kit.PerformanceAnalysisKit'; 220 221let seService : omapi.SEService; 222 223function secureElementDemo() { 224 // get the service 225 try { 226 seService = omapi.newSEService("serviceState", (state) => { 227 hilog.info(0x0000, 'testTag', 'se service state = %{public}s', JSON.stringify(state)); 228 }); 229 } catch (error) { 230 hilog.error(0x0000, 'testTag', 'newSEService error %{public}s', JSON.stringify(error)); 231 } 232 if (seService == undefined || !seService.isConnected()) { 233 hilog.error(0x0000, 'testTag', 'secure element service disconnected.'); 234 return; 235 } 236} 237``` 238 239### SEService.shutdown 240 241shutdown(): void 242 243释放该Service分配的所有SE资源。此后[isConnected](#seserviceisconnected)将返回false。 244 245**系统能力:** SystemCapability.Communication.SecureElement 246 247**错误码:** 248 249错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 250 251| 错误码ID | 错误信息 | 252| -------- | ----------------------------------------- | 253| 801 | Capability not supported. | 254 255**示例:** 256 257<!--code_no_check--> 258```js 259import { omapi } from '@kit.ConnectivityKit'; 260import { BusinessError } from '@kit.BasicServicesKit'; 261import { hilog } from '@kit.PerformanceAnalysisKit'; 262 263let seService : omapi.SEService; 264 265// Before use seService, initialization for seService is required 266 267try { 268 seService.shutdown(); 269} catch (error) { 270 hilog.error(0x0000, 'testTag', 'shutdown error %{public}s', JSON.stringify(error)); 271} 272``` 273 274### SEService.getVersion 275 276getVersion(): string 277 278返回此实现所基于的Open Mobile API规范的版本号。 279 280**系统能力:** SystemCapability.Communication.SecureElement 281 282**返回值:** 283 284| **类型** | **说明** | 285| -------- | -------------------------------------------------- | 286| string | OMA版本号(例如,“3.3”表示Open Mobile API规范版本3.3) | 287 288**错误码:** 289 290错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 291 292| 错误码ID | 错误信息 | 293| -------- | ----------------------------------------- | 294| 801 | Capability not supported. | 295 296**示例:** 297 298<!--code_no_check--> 299```JS 300import { omapi } from '@kit.ConnectivityKit'; 301import { BusinessError } from '@kit.BasicServicesKit'; 302import { hilog } from '@kit.PerformanceAnalysisKit'; 303 304let seService : omapi.SEService; 305 306// Before use seService, initialization for seService is required 307 308try { 309 let version = seService.getVersion(); 310 hilog.error(0x0000, 'testTag', 'version %{public}s', JSON.stringify(version)); 311} catch (error) { 312 hilog.error(0x0000, 'testTag', 'getVersion error %{public}s', JSON.stringify(error)); 313} 314``` 315## Reader 316 317Reader的实例表示该设备支持的SE,如果支持eSE和SIM,则返回两个实例。通过[SEService.getReaders](#seservicegetreaders)获取Reader实例。 318 319### Reader.getName 320 321getName(): string 322 323返回此Reader的名称。如果此读卡器是SIM Reader,则其名称必须为“SIM”。如果读卡器是eSE,则其名称须为“eSE”。 324 325**系统能力:** SystemCapability.Communication.SecureElement 326 327**返回值:** 328 329| **类型** | **说明** | 330| -------- | ---------- | 331| string | [Reader](#reader)名称。 | 332 333**错误码:** 334 335以下错误码的详细介绍请参见[NFC错误码](errorcode-nfc.md)。 336 337| 错误码ID | 错误信息 | 338| -------- | ----------------------------------------- | 339| 801 | Capability not supported. | 340 341**示例:** 342 343<!--code_no_check--> 344```js 345import { hilog } from '@kit.PerformanceAnalysisKit'; 346import { omapi } from '@kit.ConnectivityKit'; 347 348let seReaders : omapi.Reader[]; 349 350// Before use seReaders, initialization for seReaders is required 351 352try { 353 let reader = seReaders[0]; // change it to the selected reader, ese or sim. 354 let name = reader.getName(); 355 hilog.info(0x0000, 'testTag', 'name %{public}s', JSON.stringify(name)); 356} catch (error) { 357 hilog.error(0x0000, 'testTag', 'getName error %{public}s', JSON.stringify(error)); 358} 359``` 360 361### Reader.isSecureElementPresent 362 363isSecureElementPresent(): boolean 364 365检查当前Reader所对应的安全单元是否可用。 366 367**系统能力:** SystemCapability.Communication.SecureElement 368 369**返回值:** 370 371| **类型** | **说明** | 372| -------- | -------------------------------------------- | 373| boolean | true: 安全单元可用, false: 安全单元不可用。 | 374 375**错误码:** 376 377错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 378 379| 错误码ID | 错误信息 | 380| -------- | -------------------------------- | 381| 801 | Capability not supported. | 382| 3300101 | IllegalStateError, service state exception. | 383 384**示例:** 385 386<!--code_no_check--> 387```js 388import { hilog } from '@kit.PerformanceAnalysisKit'; 389import { omapi } from '@kit.ConnectivityKit'; 390 391let seReaders : omapi.Reader[]; 392 393// Before use seReaders, initialization for seReaders is required 394 395try { 396 let reader = seReaders[0]; // change it to the selected reader, ese or sim. 397 let isPresent = reader.isSecureElementPresent(); 398 hilog.info(0x0000, 'testTag', 'isPresent %{public}s', JSON.stringify(isPresent)); 399} catch (error) { 400 hilog.error(0x0000, 'testTag', 'isSecureElementPresent error %{public}s', JSON.stringify(error)); 401} 402``` 403 404### Reader.openSession 405 406 openSession(): Session 407 408在SE Reader实例上创建连接会话,返回Session实例。在一个Reader上可能同时打开多个会话。 409 410**系统能力:** SystemCapability.Communication.SecureElement 411 412**返回值:** 413 414| **类型** | **说明** | 415| -------- | ------------------------------ | 416| [Session](#session) | 连接会话Session实例。| 417 418**错误码:** 419 420错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 421 422| 错误码ID | 错误信息 | 423| -------- | -------------------------------- | 424| 801 | Capability not supported. | 425| 3300101 | IllegalStateError, service state exception. | 426| 3300104 | IOError, there is a communication problem to the reader or the SE. | 427 428**示例:** 429 430<!--code_no_check--> 431```js 432import { hilog } from '@kit.PerformanceAnalysisKit'; 433import { omapi } from '@kit.ConnectivityKit'; 434 435let seReaders : omapi.Reader[]; 436let seSession : omapi.Session; 437 438// Before use seReaders, initialization for seReaders is required 439function secureElementDemo() { 440 try { 441 let reader = seReaders[0]; // change it to the selected reader, ese or sim. 442 seSession = reader.openSession(); 443 } catch (error) { 444 hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); 445 } 446 if (seSession == undefined) { 447 hilog.error(0x0000, 'testTag', 'seSession invalid.'); 448 return; 449 } 450} 451``` 452 453### Reader.closeSessions 454 455 closeSessions(): void 456 457关闭在此Reader上打开的所有Session。所有这些Session打开的所有Channel都将关闭。 458 459**系统能力:** SystemCapability.Communication.SecureElement 460 461**错误码:** 462 463错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 464 465| 错误码ID | 错误信息 | 466| -------- | -------------------------------- | 467| 801 | Capability not supported. | 468| 3300101 | IllegalStateError, service state exception. | 469 470**示例:** 471 472<!--code_no_check--> 473```js 474import { hilog } from '@kit.PerformanceAnalysisKit'; 475import { omapi } from '@kit.ConnectivityKit'; 476 477let seReaders : omapi.Reader[]; 478let seSession : omapi.Session; 479let reader : omapi.Reader; 480 481// Before use seReaders, initialization for seReaders is required 482function secureElementDemo() { 483 try { 484 reader = seReaders[0]; // change it to the selected reader, ese or sim. 485 seSession = reader.openSession(); 486 } catch (error) { 487 hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); 488 } 489 if (seSession == undefined) { 490 hilog.error(0x0000, 'testTag', 'seSession invalid.'); 491 return; 492 } 493 try { 494 reader.closeSessions(); 495 } catch (error) { 496 hilog.error(0x0000, 'testTag', 'closeSessions error %{public}s', JSON.stringify(error)); 497 } 498} 499``` 500 501## Session 502 503Session的实例表示在某个SE Reader实例上创建连接会话。通过[Reader.openSession](#readeropensession)获取Session实例。 504 505### Session.getReader 506 507getReader(): Reader 508 509获取提供此Session的Reader实例。 510 511**系统能力:** SystemCapability.Communication.SecureElement 512 513**返回值:** 514 515| **类型** | **说明** | 516| -------- | --------------------------- | 517| [Reader](#reader) | 返回此Session的Reader实例。 | 518 519**错误码:** 520 521错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 522 523| 错误码ID | 错误信息 | 524| -------- | ----------------------------------------- | 525| 801 | Capability not supported. | 526 527**示例:** 528 529<!--code_no_check--> 530```js 531import { hilog } from '@kit.PerformanceAnalysisKit'; 532import { omapi } from '@kit.ConnectivityKit'; 533 534let seReaders : omapi.Reader[]; 535let seSession : omapi.Session; 536let reader : omapi.Reader; 537 538// Before use seReaders, initialization for seReaders is required 539function secureElementDemo() { 540 try { 541 reader = seReaders[0]; // change it to the selected reader, ese or sim. 542 seSession = reader.openSession(); 543 } catch (error) { 544 hilog.error(0x0000, 'testTag', 'openSession error %{public}s', JSON.stringify(error)); 545 } 546 if (seSession == undefined) { 547 hilog.error(0x0000, 'testTag', 'seSession invalid.'); 548 return; 549 } 550 try { 551 let sessionReader = seSession.getReader(); 552 } catch (error) { 553 hilog.error(0x0000, 'testTag', 'getReader error %{public}s', JSON.stringify(error)); 554 } 555} 556``` 557 558### Session.getATR 559 560getATR(): number[] 561 562获取该SE的ATR。如果该SE的ATR不可用,则应返回空数组。 563 564**系统能力:** SystemCapability.Communication.SecureElement 565 566**返回值:** 567 568| **类型** | **说明** | 569| -------- | -------------------------------------------- | 570| number[] | 返回SE的ATR,SE的ATR不可用时,返回空的数组。 | 571 572**错误码:** 573 574错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 575 576| 错误码ID | 错误信息 | 577| -------- | -------------------------------- | 578| 801 | Capability not supported. | 579| 3300101 | IllegalStateError, service state exception. | 580 581**示例:** 582 583<!--code_no_check--> 584```js 585import { hilog } from '@kit.PerformanceAnalysisKit'; 586import { omapi } from '@kit.ConnectivityKit'; 587 588let seSession : omapi.Session; 589 590// Before use seSession, initialization for seSession is required 591 592try { 593 let atr = seSession.getATR(); 594 hilog.info(0x0000, 'testTag', 'atr %{public}s', JSON.stringify(atr)); 595} catch (error) { 596 hilog.error(0x0000, 'testTag', 'getATR error %{public}s', JSON.stringify(error)); 597} 598``` 599 600### Session.close 601 602close(): void 603 604关闭与SE的当前会话连接。这将关闭此Session打开的所有Channel。 605 606**系统能力:** SystemCapability.Communication.SecureElement 607 608**错误码:** 609 610错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 611 612| 错误码ID | 错误信息 | 613| -------- | -------------------------------- | 614| 801 | Capability not supported. | 615| 3300101 | IllegalStateError, service state exception. | 616 617**示例:** 618 619<!--code_no_check--> 620```js 621import { hilog } from '@kit.PerformanceAnalysisKit'; 622import { omapi } from '@kit.ConnectivityKit'; 623 624let seSession : omapi.Session; 625 626// Before use seSession, initialization for seSession is required 627 628try { 629 seSession.close(); 630} catch (error) { 631 hilog.error(0x0000, 'testTag', 'close error %{public}s', JSON.stringify(error)); 632} 633``` 634 635### Session. isClosed 636 637isClosed(): boolean 638 639检查Session是否关闭。 640 641**系统能力:** SystemCapability.Communication.SecureElement 642 643**返回值:** 644 645| **类型** | **说明** | 646| -------- | ------------------------------------ | 647| boolean | true:Session状态已关闭,false:Session是打开的。 | 648 649**错误码:** 650 651错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 652 653| 错误码ID | 错误信息 | 654| -------- | ----------------------------------------- | 655| 801 | Capability not supported. | 656 657**示例:** 658 659<!--code_no_check--> 660```Js 661import { hilog } from '@kit.PerformanceAnalysisKit'; 662import { omapi } from '@kit.ConnectivityKit'; 663 664let seSession : omapi.Session; 665 666// Before use seSession, initialization for seSession is required 667 668try { 669 let isClosed = seSession.isClosed(); 670 hilog.info(0x0000, 'testTag', 'isClosed %{public}s', JSON.stringify(isClosed)); 671} catch (error) { 672 hilog.error(0x0000, 'testTag', 'isClosed error %{public}s', JSON.stringify(error)); 673} 674``` 675 676### Session.closeChannels 677 678closeChannels(): void 679 680关闭此Session上打开的所有Channel。 681 682**系统能力:** SystemCapability.Communication.SecureElement 683 684**错误码:** 685 686错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 687 688| 错误码ID | 错误信息 | 689| -------- | -------------------------------- | 690|801 | Capability not supported. | 691| 3300101 | IllegalStateError, service state exception. | 692 693**示例:** 694 695<!--code_no_check--> 696```js 697import { hilog } from '@kit.PerformanceAnalysisKit'; 698import { omapi } from '@kit.ConnectivityKit'; 699 700let seSession : omapi.Session; 701 702// Before use seSession, initialization for seSession is required 703 704try { 705 seSession.closeChannels(); 706} catch (error) { 707 hilog.error(0x0000, 'testTag', 'closeChannels error %{public}s', JSON.stringify(error)); 708} 709``` 710 711### Session.openBasicChannel 712 713openBasicChannel(aid: number[]): Promise\<Channel> 714 715打开基础通道,参考[ISO 7816-4]协议,返回基础Channel实例对象。SE不能提供基础Channel或应用程序没有访问SE的权限时,返回null。使用Promise异步回调 716 717**系统能力:** SystemCapability.Communication.SecureElement 718 719**参数:** 720 721| **参数名** | **类型** | **必填** | **说明** | 722| ---------- | -------- | ------ | ------------------------------------------------------------ | 723| aid | number[] | 是 |在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。| 724 725**返回值:** 726 727| **类型** | **说明** | 728| -------- | --------------------- | 729| Promise\<[Channel](#channel)> | 以Promise形式异步返回可用的基础Channel对象实例。 | 730 731**错误码:** 732 733错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 734 735| 错误码ID | 错误信息 | 736| -------- | -------------------------------- | 737|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 738|801 | Capability not supported. | 739| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 740| 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | 741| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 742| 3300104 | IOError, there is a communication problem to the reader or the SE. | 743 744**示例:** 745 746<!--code_no_check--> 747```js 748import { hilog } from '@kit.PerformanceAnalysisKit'; 749import { omapi } from '@kit.ConnectivityKit'; 750 751let seSession : omapi.Session; 752let seChannel : omapi.Channel; 753let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 754 755// Before use seSession, initialization for seSession is required 756function secureElementDemo() { 757 try { 758 // change the aid value for open channel. 759 seSession.openBasicChannel(aidArray).then((data) => { 760 seChannel = data; 761 }).catch((error : BusinessError)=> { 762 hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); 763 }); 764 } catch (exception) { 765 hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); 766 } 767 if (seChannel == undefined) { 768 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 769 return; 770 } 771} 772``` 773 774### Session.openBasicChannel 775 776 openBasicChannel(aid: number[], callback: AsyncCallback\<Channel>): void 777 778打开基础通道,参考[ISO 7816-4]协议,返回基础Channel实例对象。SE不能提供基础Channel或应用程序没有访问SE的权限时,返回null。使用callback异步回调。 779 780**系统能力:** SystemCapability.Communication.SecureElement 781 782**参数:** 783 784| **参数名** | **类型** | **必填** | **说明** | 785| ---------- | ---------------------- | ------ | ------------------------------------------------------------ | 786| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 787| callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callback形式异步返回可用的基础Channel对象实例。 | 788 789**错误码:** 790 791错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 792 793| 错误码ID | 错误信息 | 794| -------- | -------------------------------- | 795|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 796|801 | Capability not supported. | 797| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 798| 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | 799| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 800| 3300104 | IOError, there is a communication problem to the reader or the SE. | 801 802**示例:** 803 804<!--code_no_check--> 805```js 806import { hilog } from '@kit.PerformanceAnalysisKit'; 807import { omapi } from '@kit.ConnectivityKit'; 808 809let seSession : omapi.Session; 810let seChannel : omapi.Channel; 811let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 812 813// Before use seSession, initialization for seSession is required 814function secureElementDemo() { 815 try { 816 // change the aid value for open channel. 817 seSession.openBasicChannel(aidArray, (error, data) => { 818 if (error) { 819 hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); 820 } else { 821 seChannel = data; 822 } 823 }); 824 } catch (exception) { 825 hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); 826 } 827 if (seChannel == undefined) { 828 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 829 return; 830 } 831} 832``` 833 834### Session.openBasicChannel 835 836openBasicChannel(aid: number[], p2: number): Promise\<Channel> 837 838打开基础通道,参考[ISO 7816-4]协议,返回基础Channel实例对象。SE不能提供基础Channel或应用程序没有访问SE的权限时,返回null。使用Promise异步回调 839 840**系统能力:** SystemCapability.Communication.SecureElement 841 842**参数:** 843 844| **参数名** | **类型** | **必填** | **说明** | 845| ---------- | -------- | ------ | ------------------------------------------------------------ | 846| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 847| p2 | number | 是 |在该Channel上执行的SELECT APDU的P2参数。 | 848 849**返回值:** 850 851| **类型** | **说明** | 852| -------- | --------------------- | 853| Promise\<[Channel](#channel)> | 以Promise形式异步返回可用的基础Channel对象实例。 | 854 855**错误码:** 856 857错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 858 859| 错误码ID | 错误信息 | 860| -------- | -------------------------------- | 861|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 862|801 | Capability not supported. | 863| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 864| 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | 865| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 866| 3300104 | IOError, there is a communication problem to the reader or the SE. | 867 868**示例:** 869 870<!--code_no_check--> 871```js 872import { hilog } from '@kit.PerformanceAnalysisKit'; 873import { omapi } from '@kit.ConnectivityKit'; 874 875let seSession : omapi.Session; 876let seChannel : omapi.Channel; 877let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 878let p2 : number = 0x00; 879 880// Before use seSession, initialization for seSession is required 881function secureElementDemo() { 882 try { 883 // change the aid value for open channel. 884 seSession.openBasicChannel(aidArray, p2).then((data) => { 885 seChannel = data; 886 }).catch((error : BusinessError)=> { 887 hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); 888 }); 889 } catch (exception) { 890 hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); 891 } 892 if (seChannel == undefined) { 893 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 894 return; 895 } 896} 897``` 898 899### Session.openBasicChannel 900 901openBasicChannel(aid: number[], p2:number, callback: AsyncCallback\<Channel>): void 902 903打开基础通道,参考[ISO 7816-4]协议,返回基础Channel实例对象。SE不能提供基础Channel或应用程序没有访问SE的权限时,返回null。使用callback异步回调。 904 905**系统能力:** SystemCapability.Communication.SecureElement 906 907**参数:** 908 909| **参数名** | **类型** | **必填** | **说明** | 910| ---------- | ---------------------- | ------ | ------------------------------------------------------------ | 911| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 912| p2 | number | 是 | 此Channel上执行SELECT APDU命令的P2参数。 | 913| callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callback形式异步返回可用的基础Channel对象实例。 | 914 915**错误码:** 916 917错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 918 919| 错误码ID | 错误信息 | 920| -------- | -------------------------------- | 921|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 922|801 | Capability not supported. | 923| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 924| 3300102 | NoSuchElementError, the AID on the SE is not available or cannot be selected. | 925| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 926| 3300104 | IOError, there is a communication problem to the reader or the SE. | 927 928**示例:** 929 930<!--code_no_check--> 931```js 932import { hilog } from '@kit.PerformanceAnalysisKit'; 933import { omapi } from '@kit.ConnectivityKit'; 934 935let seSession : omapi.Session; 936let seChannel : omapi.Channel; 937let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 938let p2 : number = 0x00; 939 940// Before use seSession, initialization for seSession is required 941function secureElementDemo() { 942 try { 943 // change the aid value for open channel. 944 seSession.openBasicChannel(aidArray, p2, (error, data) => { 945 if (error) { 946 hilog.error(0x0000, 'testTag', 'openBasicChannel error %{public}s', JSON.stringify(error)); 947 } else { 948 seChannel = data; 949 } 950 }); 951 } catch (exception) { 952 hilog.error(0x0000, 'testTag', 'openBasicChannel exception %{public}s', JSON.stringify(exception)); 953 } 954 if (seChannel == undefined) { 955 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 956 return; 957 } 958} 959``` 960 961### Session.openLogicalChannel 962 963openLogicalChannel(aid: number[]): Promise\<Channel> 964 965打开逻辑通道,参考[ISO 7816-4]协议,返回逻辑Channel实例对象。SE不能提供逻辑Channel或应用程序没有访问SE的权限时,返回null。使用Promise异步回调 966 967**系统能力:** SystemCapability.Communication.SecureElement 968 969**参数:** 970 971| **参数名** | **类型** | **必填** | **说明** | 972| ---------- | -------- | ------ | --------------------------------------- | 973| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 974 975**返回值:** 976 977| **类型** | **说明** | 978| -------- | ------------------------------------------------------------ | 979| Promise\<[Channel](#channel)> | 以Promise形式异步返回可用的逻辑Channel对象实例。 | 980 981**错误码:** 982 983错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 984 985| 错误码ID | 错误信息 | 986| -------- | -------------------------------- | 987|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 988|801 | Capability not supported. | 989| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 990| 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. | 991| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 992| 3300104 | IOError, there is a communication problem to the reader or the SE. | 993 994**示例:** 995 996<!--code_no_check--> 997```js 998import { hilog } from '@kit.PerformanceAnalysisKit'; 999import { omapi } from '@kit.ConnectivityKit'; 1000 1001let seSession : omapi.Session; 1002let seChannel : omapi.Channel; 1003let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 1004 1005// Before use seSession, initialization for seSession is required 1006function secureElementDemo() { 1007 try { 1008 // change the aid value for open channel. 1009 seSession.openLogicalChannel(aidArray).then((data) => { 1010 seChannel = data; 1011 }).catch((error : BusinessError)=> { 1012 hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); 1013 }); 1014 } catch (exception) { 1015 hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); 1016 } 1017 if (seChannel == undefined) { 1018 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 1019 return; 1020 } 1021} 1022``` 1023 1024### Session.openLogicalChannel 1025 1026 openLogicalChannel(aid: number[], callback: AsyncCallback\<Channel>): void 1027 1028打开逻辑通道,参考[ISO 7816-4]协议,返回逻辑Channel实例对象。SE不能提供逻辑Channel或应用程序没有访问SE的权限时,返回null。使用callback异步回调。 1029 1030**系统能力:** SystemCapability.Communication.SecureElement 1031 1032**参数:** 1033 1034| **参数名** | **类型** | **必填** | **说明** | 1035| ---------- | ---------------------- | ------ | ------------------------------------------------------------ | 1036| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 1037| callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callback形式异步返回可用的逻辑Channel对象实例。 | 1038 1039**错误码:** 1040 1041错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1042 1043| 错误码ID | 错误信息 | 1044| -------- | -------------------------------- | 1045|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 1046|801 | Capability not supported. | 1047| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 1048| 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. | 1049| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 1050| 3300104 | IOError, there is a communication problem to the reader or the SE. | 1051 1052**示例:** 1053 1054<!--code_no_check--> 1055```js 1056import { hilog } from '@kit.PerformanceAnalysisKit'; 1057import { omapi } from '@kit.ConnectivityKit'; 1058 1059let seSession : omapi.Session; 1060let seChannel : omapi.Channel; 1061let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 1062 1063// Before use seSession, initialization for seSession is required 1064function secureElementDemo() { 1065 try { 1066 // change the aid value for open channel. 1067 seSession.openLogicalChannel(aidArray, (error, data) => { 1068 if (error) { 1069 hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); 1070 } else { 1071 seChannel = data; 1072 } 1073 }); 1074 } catch (exception) { 1075 hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); 1076 } 1077 if (seChannel == undefined) { 1078 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 1079 return; 1080 } 1081} 1082``` 1083 1084### Session.openLogicalChannel 1085 1086openLogicalChannel(aid: number[], p2: number): Promise\<Channel> 1087 1088打开逻辑通道,参考[ISO 7816-4]协议,返回逻辑Channel实例对象。SE不能提供逻辑Channel或应用程序没有访问SE的权限时,返回null。使用Promise异步回调 1089 1090**系统能力:** SystemCapability.Communication.SecureElement 1091 1092**参数:** 1093 1094| **参数名** | **类型** | **必填** | **说明** | 1095| ---------- | -------- | ------ | ----------------------------------------- | 1096| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 1097| p2 | number | 是 | 此Channel上执行SELECT APDU命令的P2参数。 | 1098 1099**返回值:** 1100 1101| **类型** | **说明** | 1102| -------- | -------------- | 1103| Promise\<[Channel](#channel)> | 以Promise形式异步返回可用的逻辑Channel实例对象。 | 1104 1105**错误码:** 1106 1107错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1108 1109| 错误码ID | 错误信息 | 1110| -------- | -------------------------------- | 1111|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 1112|801 | Capability not supported. | 1113| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 1114| 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. | 1115| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 1116| 3300104 | IOError, there is a communication problem to the reader or the SE. | 1117 1118**示例:** 1119 1120<!--code_no_check--> 1121```js 1122import { hilog } from '@kit.PerformanceAnalysisKit'; 1123import { omapi } from '@kit.ConnectivityKit'; 1124 1125let seSession : omapi.Session; 1126let seChannel : omapi.Channel; 1127let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 1128let p2 : number = 0x00; 1129 1130// Before use seSession, initialization for seSession is required 1131function secureElementDemo() { 1132 try { 1133 // change the aid value for open channel. 1134 seSession.openLogicalChannel(aidArray, p2).then((data) => { 1135 seChannel = data; 1136 }).catch((error : BusinessError)=> { 1137 hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); 1138 }); 1139 } catch (exception) { 1140 hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); 1141 } 1142 if (seChannel == undefined) { 1143 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 1144 return; 1145 } 1146} 1147``` 1148 1149### Session.openLogicalChannel 1150 1151openLogicalChannel(aid: number[], p2: number, callback: AsyncCallback\<Channel>):void 1152 1153打开逻辑通道,参考[ISO 7816-4]协议,返回Channel实例对象。SE不能提供逻辑Channel或应用程序没有访问SE的权限时,返回null。使用callback异步回调。 1154 1155**系统能力:** SystemCapability.Communication.SecureElement 1156 1157**参数:** 1158 1159| **参数名** | **类型** | **必填** | **说明** | 1160| ---------- | ---------------------- | ------ | ------------------------------------------------------------ | 1161| aid | number[] | 是 | 在此Channel上选择的Applet的AID或如果没有Applet被选择时空的数组。 | 1162| p2 | number | 是 | 此Channel上执行SELECT APDU命令的P2参数。 | 1163| callback | AsyncCallback\<[Channel](#channel)> | 是 | 以callback形式异步返回可用的逻辑Channel对象实例。 | 1164 1165**错误码:** 1166 1167错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1168 1169| 错误码ID | 错误信息 | 1170| -------- | -------------------------------- | 1171|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 1172|801 | Capability not supported. | 1173| 3300101 | IllegalStateError, an attempt is made to use an SE session that has been closed. | 1174| 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. | 1175| 3300103 | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session. | 1176| 3300104 | IOError, there is a communication problem to the reader or the SE. | 1177 1178**示例:** 1179 1180<!--code_no_check--> 1181```js 1182import { hilog } from '@kit.PerformanceAnalysisKit'; 1183import { omapi } from '@kit.ConnectivityKit'; 1184 1185let seSession : omapi.Session; 1186let seChannel : omapi.Channel; 1187let aidArray : number[] = [0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10]; 1188let p2 : number = 0x00; 1189 1190// Before use seSession, initialization for seSession is required 1191function secureElementDemo() { 1192 try { 1193 // change the aid value for open channel. 1194 seSession.openLogicalChannel(aidArray, p2, (error, data) => { 1195 if (error) { 1196 hilog.error(0x0000, 'testTag', 'openLogicalChannel error %{public}s', JSON.stringify(error)); 1197 } else { 1198 seChannel = data; 1199 } 1200 }); 1201 } catch (exception) { 1202 hilog.error(0x0000, 'testTag', 'openLogicalChannel exception %{public}s', JSON.stringify(exception)); 1203 } 1204 if (seChannel == undefined) { 1205 hilog.error(0x0000, 'testTag', 'seChannel invalid.'); 1206 return; 1207 } 1208} 1209``` 1210## Channel 1211 1212Channel的实例表示在某个Session实例上创建通道,可能为基础通道或逻辑通道。通过[Session.openBasicChannel](#sessionopenbasicchannel)或[Session.openLogicalChannel](#sessionopenlogicalchannel)获取Channel实例。 1213 1214### Channel.getSession 1215 1216 getSession(): Session 1217 1218获取打开该Channel的Session对象。 1219 1220**系统能力:** SystemCapability.Communication.SecureElement 1221 1222**返回值:** 1223 1224| **类型** | **说明** | 1225| -------- | ----------------------------- | 1226| [Session](#session) | 该Channel绑定的Session 对象。 | 1227 1228**错误码:** 1229 1230错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1231 1232| 错误码ID | 错误信息 | 1233| -------- | ----------------------------------------- | 1234| 801 | Capability not supported. | 1235 1236**示例:** 1237 1238<!--code_no_check--> 1239```js 1240import { hilog } from '@kit.PerformanceAnalysisKit'; 1241import { omapi } from '@kit.ConnectivityKit'; 1242 1243let seSession : omapi.Session; 1244let seChannel : omapi.Channel; 1245 1246// Before use seChannel, initialization for seChannel is required 1247 1248try { 1249 seSession = seChannel.getSession(); 1250} catch (exception) { 1251 hilog.error(0x0000, 'testTag', 'getSession exception %{public}s', JSON.stringify(exception)); 1252} 1253``` 1254 1255### Channel.close 1256 1257close(): void 1258 1259关闭Channel。 1260 1261**系统能力:** SystemCapability.Communication.SecureElement 1262 1263**错误码:** 1264 1265错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1266 1267| 错误码ID | 错误信息 | 1268| -------- | ----------------------------------------- | 1269| 801 | Capability not supported. | 1270 1271**示例:** 1272 1273<!--code_no_check--> 1274```js 1275import { hilog } from '@kit.PerformanceAnalysisKit'; 1276import { omapi } from '@kit.ConnectivityKit'; 1277 1278let seChannel : omapi.Channel; 1279 1280// Before use seChannel, initialization for seChannel is required 1281 1282try { 1283 seChannel.close(); 1284} catch (exception) { 1285 hilog.error(0x0000, 'testTag', 'close exception %{public}s', JSON.stringify(exception)); 1286} 1287``` 1288 1289### Channel.isBasicChannel 1290 1291isBasicChannel(): boolean 1292 1293检查该Channel是否为基础Channel。 1294 1295**系统能力:** SystemCapability.Communication.SecureElement 1296 1297**返回值:** 1298 1299| **类型** | **说明** | 1300| -------- | ------------------------------------------------------------ | 1301| boolean | true: 该Channel是基础Channel, false:该Channel逻辑Channel 。 | 1302 1303**错误码:** 1304 1305错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1306 1307| 错误码ID | 错误信息 | 1308| -------- | ----------------------------------------- | 1309| 801 | Capability not supported. | 1310 1311**示例:** 1312 1313<!--code_no_check--> 1314```js 1315import { hilog } from '@kit.PerformanceAnalysisKit'; 1316import { omapi } from '@kit.ConnectivityKit'; 1317 1318let seChannel : omapi.Channel; 1319 1320// Before use seChannel, initialization for seChannel is required 1321 1322try { 1323 let isBasic = seChannel.isBasicChannel(); 1324 hilog.info(0x0000, 'testTag', 'isBasic = %{public}s', JSON.stringify(isBasic)); 1325} catch (exception) { 1326 hilog.error(0x0000, 'testTag', 'isBasicChannel exception %{public}s', JSON.stringify(exception)); 1327} 1328``` 1329 1330### Channel.isClosed 1331 1332isClosed(): boolean 1333 1334检查该Channel是否已被关闭。 1335 1336**系统能力:** SystemCapability.Communication.SecureElement 1337 1338**返回值:** 1339 1340| **类型** | **说明** | 1341| -------- | --------------------------------------------- | 1342| boolean | true: Channel是关闭的,false: 不是关闭的。 | 1343 1344**错误码:** 1345 1346错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1347 1348| 错误码ID | 错误信息 | 1349| -------- | ----------------------------------------- | 1350| 801 | Capability not supported. | 1351 1352**示例:** 1353 1354<!--code_no_check--> 1355```js 1356import { hilog } from '@kit.PerformanceAnalysisKit'; 1357import { omapi } from '@kit.ConnectivityKit'; 1358 1359let seChannel : omapi.Channel; 1360 1361// Before use seChannel, initialization for seChannel is required 1362 1363try { 1364 let isClosed = seChannel.isClosed(); 1365 hilog.info(0x0000, 'testTag', 'isClosed = %{public}s', JSON.stringify(isClosed)); 1366} catch (exception) { 1367 hilog.error(0x0000, 'testTag', 'isClosed exception %{public}s', JSON.stringify(exception)); 1368} 1369``` 1370 1371### Channel.getSelectResponse 1372 1373getSelectResponse(): number[] 1374 1375获取SELECT Applet时的响应数据,包含状态字。 1376 1377**系统能力:** SystemCapability.Communication.SecureElement 1378 1379**返回值:** 1380 1381| **类型** | **说明** | 1382| -------- | ------------------------------------------------------------ | 1383| number[] | SELECT Applet时的响应数据,包含状态字。 | 1384 1385**错误码:** 1386 1387错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1388 1389| 错误码ID | 错误信息 | 1390| -------- | ----------------------------------------- | 1391| 801 | Capability not supported. | 1392 1393**示例:** 1394 1395<!--code_no_check--> 1396```js 1397import { hilog } from '@kit.PerformanceAnalysisKit'; 1398import { omapi } from '@kit.ConnectivityKit'; 1399 1400let seChannel : omapi.Channel; 1401 1402// Before use seChannel, initialization for seChannel is required 1403 1404try { 1405 let response = seChannel.getSelectResponse(); 1406 hilog.info(0x0000, 'testTag', 'response = %{public}s', JSON.stringify(response)); 1407} catch (exception) { 1408 hilog.error(0x0000, 'testTag', 'getSelectResponse exception %{public}s', JSON.stringify(exception)); 1409} 1410``` 1411 1412### Channel.transmit 1413 1414transmit(command: number[]): Promise\<number[]> 1415 1416向SE发送APDU数据,数据符合ISO/IEC 7816规范。使用Promise异步回调 1417 1418**系统能力:** SystemCapability.Communication.SecureElement 1419 1420**参数:** 1421 1422| **参数名** | **类型** | **必填** | **说明** | 1423| ---------- | -------- | ------ | ------------------------------------- | 1424| command | number[] | 是 | 需要发送到SE的APDU数据。 | 1425 1426**返回值:** 1427 1428| **类型** | **说明** | 1429| -------- | -------------- | 1430| Promise\<number[]> | 以Promise形式异步返回接收到的响应APDU数据,number数组。 | 1431 1432**错误码:** 1433 1434错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1435 1436| 错误码ID | 错误信息 | 1437| -------- | -------------------------------- | 1438|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 1439|801 | Capability not supported. | 1440| 3300101 | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. | 1441| 3300103 | SecurityError, the command is filtered by the security policy. | 1442| 3300104 | IOError, there is a communication problem to the reader or the SE. | 1443 1444**示例:** 1445 1446<!--code_no_check--> 1447```js 1448import { hilog } from '@kit.PerformanceAnalysisKit'; 1449import { omapi } from '@kit.ConnectivityKit'; 1450 1451let seChannel : omapi.Channel; 1452 1453// Before use seChannel, initialization for seChannel is required 1454 1455let cmdData = [0x01, 0x02, 0x03, 0x04]; // please change the raw data to be correct. 1456try { 1457 seChannel.transmit(cmdData).then((response) => { 1458 hilog.info(0x0000, 'testTag', 'transmit response = %{public}s.', JSON.stringify(response)); 1459 }).catch((error : BusinessError) => { 1460 hilog.error(0x0000, 'testTag', 'transmit error = %{public}s.', JSON.stringify(error)); 1461 }); 1462} catch (exception) { 1463 hilog.error(0x0000, 'testTag', 'transmit exception = %{public}s.', JSON.stringify(exception)); 1464} 1465``` 1466 1467### Channel.transmit 1468 1469transmit(command: number[], callback: AsyncCallback\<number[]>): void 1470 1471向SE发送APDU数据,数据符合ISO/IEC 7816规范。使用callback异步回调。 1472 1473**系统能力:** SystemCapability.Communication.SecureElement 1474 1475**参数:** 1476 1477| **参数名** | **类型** | **必填** | **说明** | 1478| ---------- | ----------------------- | ------ | ------------------------------------- | 1479| command | number[] | 是 | 需要发送到SE的APDU数据。 | 1480| callback | AsyncCallback\<number[]> | 是 | 返回接收到的响应APDU数据,number数组。 | 1481 1482**错误码:** 1483 1484错误码的详细介绍请参见[SE错误码](errorcode-se.md)。 1485 1486| 错误码ID | 错误信息 | 1487| -------- | -------------------------------- | 1488|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. | 1489|801 | Capability not supported. | 1490| 3300101 | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. | 1491| 3300103 | SecurityError, the command is filtered by the security policy. | 1492| 3300104 | IOError, there is a communication problem to the reader or the SE. | 1493 1494**示例:** 1495 1496<!--code_no_check--> 1497```js 1498import { hilog } from '@kit.PerformanceAnalysisKit'; 1499import { omapi } from '@kit.ConnectivityKit'; 1500 1501let seChannel : omapi.Channel; 1502 1503// Before use seChannel, initialization for seChannel is required 1504 1505let cmdData = [0x01, 0x02, 0x03, 0x04]; // please change the raw data to be correct. 1506try { 1507 seChannel.transmit(cmdData, (error, response) => { 1508 if (error) { 1509 hilog.error(0x0000, 'testTag', 'transmit error %{public}s', JSON.stringify(error)); 1510 } else { 1511 hilog.info(0x0000, 'testTag', 'transmit response = %{public}s.', JSON.stringify(response)); 1512 } 1513 }); 1514} catch (exception) { 1515 hilog.error(0x0000, 'testTag', 'transmit exception %{public}s', JSON.stringify(exception)); 1516} 1517``` 1518