ijsbridge
TypeScript icon, indicating that this package has built-in type declarations

2.7.2 • Public • Published

[TOC]

ijsbridge 接入向导(两种方式)

npm 方式

npm i ijsbridge

script 引入,支持 es5

<script src="https://fastly.jsdelivr.net/npm/ijsbridge/ijsbridge.min.js"></script>

Web调试

chrome内核

请使用 chrome 的 inspect 调试(需翻墙,或部分 chrome 内核浏览器)

chrome://inspect/#devices

ijsbridge 接口文档

import WebBridgeApi from "ijsbridge"

接口 sysinfo

获取设备基本配置/信息

接收参数 无

返回参数
参数 说明
Brand 设备品牌
SystemName 系统名称
SystemVersion 系统版本
BundleId 包名
ApplicationName 应用名
Version 版本
DeviceName 设备名称
UserAgent 设备标记
Carrier 运营商
NetInfo 网络类型

示例

WebBridgeApi.sysinfo().then(({ err, result }) => {
  console.log("测试桥返回结果sysinfo", result, err);
});

接口 scanCode

打开相机扫描二维码

接收参数

参数 说明
closeAlbums ture 关闭相册扫码 不传值默认打开
返回参数

二维码字符串数据

示例

WebBridgeApi.scanCode().then(({ err, result }) => {
  console.log("测试桥返回结果scanCode", result, err);
});

接口 authorize

获取用户授权,未登录可触发登录

接收参数 无

返回参数

返回用户基本信息(含有 openid)

示例

WebBridgeApi.authorize().then(({ err, result }) => {
  console.log("测试桥返回结果authorize", result, err);
});

接口 getUserInfo

获取用户授权,未登录会触发登录

接收参数 无

返回参数:

返回用户基本信息

示例

WebBridgeApi.getUserInfo().then(({ err, result }) => {
  console.log("测试桥返回结果", result, err);
});

接口 fetch

网络请求

接收参数

参数 说明
url 请求地址
option 请求参数

option 字段说明:

普通 GET 请求: get:{'field1':'','field2':''} || 或者在网址里用 querystring 的形式

普通 POST 请求 post:{'field1':'','field2':''}

上传文件 post:{'file':{ data: '文件数据', type: "image/png", filename: "photo.png" },'field2':''} ||或者 post:{'file':{ path: '本地路径', type: "image/png", filename: "photo.png" },'field2':''}

返回参数
参数 说明
header
body 内容

示例

WebBridgeApi.fetch({
  url: "http://www.baidu.com",
  option: {
    method: "POST",
    headers: {},
    get: { ka: "", kb: "" },
    post: {
      data: "test",
      file: { path: "", type: "image/png", filename: "photo.png" },
    },
  },
}).then(({ err, result }) => {
  console.log("测试桥返回结果", result, err);
});

接口 router

路由跳转

接收参数

参数 说明
route 路由名称
params 参数
返回参数

示例

WebBridgeApi.router({
  route: "web",
  params: { url: "http://www.baidu.com" },
}).then(({ err, result }) => {
  console.log("测试桥返回结果authorize", result, err);
});

接口 showToast

显示 toast

接收参数

参数 说明
title 显示内容
duration 显示时间 ms
返回参数

示例

WebBridgeApi.showToast({ title: "test" }).then(({ err, result }) => {});

接口 showDialog

提示对话框

接收参数

参数 说明
title 显示内容
buttons 显示时间 ms

buttons 结构

参数 说明
text 显示内容
返回参数

index 第几个

示例

WebBridgeApi.showDialog({title:'test',buttons:[{text:'1'},{text:'2'}]).then(({ err, result }) => {

});

接口 chooseImage

选择本地图片

接收参数 无

返回参数:

返回选择的图片路径

示例

WebBridgeApi.chooseImage().then(({ err, result }) => {
  console.log("测试桥返回结果", result, err);
});

接口 chooseVideo

选择本地视频

接收参数 无

返回参数:

返回选择的视频路径

示例

WebBridgeApi.chooseVideo().then(({ err, result }) => {
  console.log("测试桥返回结果", result, err);
});

接口 showImageViewer

打开图片浏览器

接收参数

参数 说明
images 图片数组
index 首先显示

images 结构

参数 说明
image 图片地址
title 标题

返回参数:

示例

WebBridgeApi.showImageViewer({
  images: [{ image: "http://", title: "" }],
  index: 0,
}).then(({ err, result }) => {});

接口 showFullVideoPlayer

打开全屏视频播放器

接收参数

参数 说明
video 视频地址

返回参数:

示例

WebBridgeApi.showFullVideoPlayer({ video: "http://" }).then(
  ({ err, result }) => {}
);

接口 checkPermission

权限验证

接收参数

参数 说明
permission 权限(参照说明)
title 提示信息

返回参数:

Bool

示例

WebBridgeApi.checkPermission({
  permission: "location",
  title: "需要您打开定位权限",
}).then(({ err, result }) => {});

权限字串说明

说明 字串 IOS Android
Camera camera ✔️
Contacts contacts ✔️
Events event ✔️
Location location ✔️
Microphone microphone ✔️
Photos photo ✔️
Background Refresh backgroundRefresh ✔️
Bluetooth bluetooth ✔️
Media Library mediaLibrary ✔️
Motion Activity motion ✔️
Push Notifications notification ✔️
Reminders reminder ✔️
Speech Recognition speechRecognition ✔️
Coarse location coarseLocation
Phone Call callPhone ❌️
Read SMS readSms ❌️
Receive SMS receiveSms ❌️
Send SMS sendSms ❌️
Storage storage ❌️

接口 audioRecord

录制音频

示例

WebBridgeApi.audioRecord({start:true,time:15}}).then(({ err, result }) => {

});

接收参数

参数 说明
start 开始/结束(true/false)
time 时间(秒),默认 10 秒

返回参数:

Bool

接口 share

示例

WebBridgeApi.share({share:{title:'',desc:'',image:'',url:'',sharePlatform:23,shareType:'WebPage'},id:'这里会',type:'article'}}).then(({ err, result }) => {

});

接收参数

参数 说明
share 标准的分享字段,包含 title,desc,image,url
id 用于统计的索引 id,例如文稿 id
type 用于统计的索引类型,例如文稿 article
sharePlatform 平台参数
path 小程序用
userName 小程序用

平台参数 platform

参数 说明
1 新浪微博
22 微信好友
23 微信朋友圈
24 QQ 好友
6 QQ 空间

类型参数 shareType

参数 说明
Text 文本
Image 图片
WebPage 网页
App 应用
Music 音频
Video 视频
WechatApplet 小程序 注:platform必须为微信好

返回参数:

String

结果消息

接口 openLink

打开外部链接

示例

WebBridgeApi.openLink({ body: "" }).then(({ err, result }) => {});

接收参数

参数 说明
body 外部链接,同 param

返回参数:

Bool

接口 showPickerMenu

显示下浮菜单(带取消)

示例

WebBridgeApi.showPickerMenu({ items: [{ title: "选项" }] }).then(
  ({ err, result }) => {
    if (!err) console.log(result.item, result.index);
  }
);

接收参数

参数 说明
items 选项数组(必须有 title)

返回参数:

{item,index}

接口 launchWechatProgram

启动微信小程序

示例

WebBridgeApi.launchWechatProgram({
  userName: "gxxxx",
  path: "",
  extDic: {},
}).then(({ err, result }) => {
  if (!err) console.log(result.item, result.index);
});

接收参数

参数 说明
userName 微信小程序 id
path 启动路径
extDic 附加参数

返回参数:

Bool

接口 获取定位信息

获取定位信息

示例

WebBridgeApi.getCurrentPosition({ type: "gaode" }).then(
  ({ err, result }) => {}
);

接收参数 无

返回参数:

逆编码

参数 说明
latitude 经度
longitude 经度
address 格式化地址
poiName 兴趣点
country 国家
province
city
cityCode 城市编码
district 区县
street 街道
streetNumber 门牌号
adCode 区域编码

非逆编码

参数 说明
latitude 经度
longitude 经度

接口 registerAppEvent

注册全局事件(app)

示例

WebBridgeApi.registerAppEvent({ event: "update" }, ({ err, result }) => {});

接收参数

参数 说明
event 事件标记

返回参数:

Bool

接口 unRegisterAppEvent

注销全局事件

示例

WebBridgeApi.unRegisterAppEvent({ event: "update" }).then(
  ({ err, result }) => {}
);

接收参数

| 参数 | 说明 | | ----- | -------- | --- | | event | 事件标记 | |

返回参数:

Bool

接口 triggerAppEvent

触发全局事件

示例

WebBridgeApi.triggerAppEvent({ event: "update", params: { a: 1 } }).then(
  ({ err, result }) => {}
);

接收参数

参数 说明
event 事件标记
params 传递参数(非引用变量)

返回参数:

Bool

接口 navigatorConfig (webapp)

更改导航配置

示例

WebBridgeApi.requestApi('navigatorConfig',{title:'导航栏标题',right:{icon:"adb",handle:()=>{}});

接收参数

参数 说明
title 导航栏标题
right 右导航按钮 icon 字体图标 handle 点击事件

其中字体图标目前只支持 MaterialIcons 图标,全部图标请浏览 https://oblador.github.io/react-native-vector-icons/

接口 orientation

旋转屏幕 版本 1.3.0+

示例

WebBridgeApi.orientation({ orientation: "LANDSCAPE" });

接收参数

参数 说明
orientation 旋转方向 支持 PORTRAIT、LANDSCAPE、LANDSCAPE-RIGHT、UNLOCK

接口 connectDlna

投屏 版本 1.3.0+

示例

WebBridgeApi.connectDlna({ media: "视频地址" });

接收参数

参数 说明
media 视频地址,只支持 http(s)协议

接口 musicControl

锁屏声音控制 版本 1.3.0+

示例

//初始化
WebBridgeApi.musicControl({
  item: {
    title: "", //标题
    artwork: "", //底图 or logo
    artist: "",
    album: "",
  },
});

//更改状态
WebBridgeApi.musicControl({ state: "play" }); //play or pause

//停止
WebBridgeApi.musicControl({ stop: true });

定义本地监听

WebBridgeApi.defineApi("onMusicControl", ({ play, pause }) => {
  //播放
  if (play) {
    return;
  }

  //暂停
  if (pause) {
    return;
  }
});

接收参数

参照示例


其他接口


接口 faceDetect

人像识别(广告机)

示例

WebBridgeApi.requestApi("faceDetect", { user: { groupId: "" } });

接收参数

参数 说明
user 用户数据,必须包含 groupId
dbSource 同步接口地址

注:(dbSource) http://***/face/list?orgid=29&size={size}&username={userName}&department_id=2818&department_type=2

参数 说明
size 单页长度
userName 最后用户名

返回参数

参数 说明
image 本地人像图片
groupId 人像组
userId 人像 ID
userInfo 人像信息
userName 人像名

接口 faceRegister

人像注册(广告机)

示例

WebBridgeApi.requestApi("faceRegister", {
  user: { userName: "", groupId: "", userInfo: "" },
});

接收参数

参数 说明
user 用户数据,必须包含 userName, groupId, userInfo,三项数据
dbSource 同步接口地址

返回参数

参数 说明
image 本地人像图片
groupId 人像组
userId 人像 ID
userInfo 人像信息
userName 人像名
feature 状态码

接口 cardDetect

身份证识别(广告机)

示例

WebBridgeApi.requestApi('cardDetect',{start:1,stop:0,once:1}}});

接收参数

参数 说明
start 开始识别
stop 结束识别
once 是否只识别一次

返回参数

参数 说明
name 姓名
sex 性别
birth 生日
address 地址
id_num 身份证
photo 本地头像

接口 readeFile

读取本地文件(1.6.4+)

示例

WebBridgeApi.OS.readeFile(input);

接收参数(input)

参数 说明
path 文件路径
encoding 编码格式("utf8", "base64", "ascii" 默认 base64)

返回参数 文件内容

接口 saveFile

保存文件(1.6.4+)

示例

WebBridgeApi.OS.saveFile(input);

接收参数

参数 说明
path 文件路径
encoding 编码(同上)
body 内容

返回文件路径

接口 unzip

保存文件(1.6.4+)

示例

WebBridgeApi.OS.unzip(input);

接收参数

参数 说明
path 文件路径
body 内容变量(跟 path 二选一)
encoding 编码(同上)
pass 加密压缩密码

文件解压返回解压文件列表 内容解压返回内容

本地接口 onMusicControl

获取音频控制(1.6.2+)

示例

WebBridgeApi.defineApi("onMusicControl", (err, res) => {});

接收 res 参数

参数 说明
play 播放
seek 跳转到指定帧
pause 暂停

本地接口 schemeOpen

捕获唤起 url(1.6.2+)

示例

WebBridgeApi.defineApi("schemeOpen", (err, res) => {});

接收 res 参数

参数 说明
url 唤起的 url

本地接口 shake

捕获摇一摇(1.6.4+)

示例

WebBridgeApi.defineApi("shake", (err) => {});

Readme

Keywords

Package Sidebar

Install

npm i ijsbridge

Weekly Downloads

9

Version

2.7.2

License

ISC

Unpacked Size

202 kB

Total Files

16

Last publish

Collaborators

  • irobotda1