扫码器(CodeScanner)

# 打开扫码器 openCodeScanner

● 接口说明
打开扫码器,30秒后将自动关闭,再次调用或调用监听接口可以重置关闭时间
● Typescript 类型参考

type ResBody = {
    resultCode: number, resultMessage: string
}

zwexplorer.CodeScanner.openCodeScanner(
    data?: {}, 
    callback?: (res: ResBody)=>void
): Promise<ResBody>
● 返回数据
参数 类型 必然存在 说明
res.resultCode Number 状态码,0 为正常,其它为异常 [状态码参考]
res.data Object 接口返回的详细数据
res.resultMessage String 接口消息
● 接口示例
zwexplorer.CodeScanner.openCodeScanner({},(res)=>{
  // 返回数据
})

# 监听结果 onCodeScannerResult

● 接口说明
监听扫码器返回的信息,超时时间(默认30s),  
超时将关闭扫码器,并返回超时信息,再次调用会重置关闭扫码器的时间
● Typescript 类型参考
type ReqBody = {
    timeout?: number
}

type ResBody = {
    resultCode: number, resultMessage: string, data: string
}

zwexplorer.CodeScanner.onCodeScannerResult(
    data: ReqBody, 
    callback?: (res: ResBody)=>void
): Promise<ResBody>
● 参数说明
参数 类型 必填 说明
data.timeout Number 超时时间(s)
● 返回数据
参数 类型 必然存在 说明
res.resultCode Number 状态码,0 为正常,其它为异常 [状态码参考]
res.data Object 状态码为 0 时,返回扫码信息
res.resultMessage String 接口消息
● 接口示例
zwexplorer.CodeScanner.onCodeScannerResult({timeout: 30 },(res)=>{
    // 返回数据
})

# 关闭扫码器 closeCodeScanner

● 接口说明
关闭扫码器
● Typescript 类型参考

type ResBody = {
    resultCode: number, resultMessage: string
}

zwexplorer.CodeScanner.closeCodeScanner(
    data: ReqBody, 
    callback?: (res: ResBody)=>void
): Promise<ResBody>
● 返回数据
参数 类型 必然存在 说明
res.resultCode Number 状态码,0 为正常,其它为异常 [状态码参考]
res.data Object 接口返回的详细数据
res.resultMessage String 接口消息
● 接口示例
zwexplorer.CodeScanner.closeCodeScanner(data,(res)=>{
    // 返回数据
})

● 扫码器对接指南
zwexplorer.CodeScanner.openCodeScanner(data, (res) => {
  if (res.resultCode === 0) {
    // 已打开
    zwexplorer.CodeScanner.onCodeScannerResult({ timeout: 30 }, (res) => {
      // 扫码信息返回,正确返回或超时返回
      zwexplorer.CodeScanner.closeCodeScanner(data, (res) => {
        // 已关闭
      });
    });
  }
});