gws-seal
v1.0.1
Published
gws-seal
Readme
简介
电子签章GWS SDK,调用前需确保已安装GZCA数字证书客户端并启动,支持TypeScript。
1 快速开始
1.1 安装
使用包管理器
Install with npm
npm install gws-seal --saveInstall with yarn
yarn add gws-sealInstall with pnpm
pnpm add gws-seal1.2 使用
ES Module
使用包管理器
import { GwsService } from "gws-seal";
const gwsService = new GwsService(gwsServiceConfig);import { createService } from "gws-seal";
async function foo() {
const gwsService = await createService(gwsServiceConfig);
}使用本地文件
import { GwsService } from "./index.es.js"; // SDK文件地址
const gzcaService = new GwsService(gwsServiceConfig);import { createService } from "./index.es.js"; // SDK文件地址
async function foo() {
const gwsService = await createService(gwsServiceConfig);
}UMD
<script src="./index.umd.js"></script>const gzcaService = new GWS_SEAL.GwsService(gwsServiceConfig);async function foo() {
const gwsService = await GWS_SEAL.createService(gwsServiceConfig);
}实例化参数说明
| 属性 | 说明 | 类型 | 默认值 |
| --------------- | ------------------------------------ | ------------------------------------- | --------- |
| appKey | 必填,appKey | String | -- |
| secret | 必填,应用密钥 | String | -- |
| baseUrl | 必填,服务器地址 | String | -- |
| onOpen | 可选,签章服务端socket连接成功回调 | (event: Event) => void | -- |
| onError | 可选,签章服务端socket错误时回调 | (event: Event) => void | -- |
| onClose | 可选,签章服务端socket关闭时回调 | (event: Event) => void | -- |
| onMessage | 可选,签章服务端socket收到消息时回调 | (data: Record<string, any>) => void | -- |
| onRequestError | 可选,http请求错误时回调 | (data: Record<string, any>) => void | -- |
| theme | 可选,弹窗主题色 | String | #409eff |
| gwsClientConfig | 可选,gws-client实例化参数 | Object | -- |
gwsClientConfig
| 属性 | 说明 | 类型 | 默认值 |
| ------------- | -------------------------------- | --------------------------------------------------------------- | ------- |
| isRememberPin | 可选,是否记住pin码 | Boolean | false |
| pinPolicy | 可选,口令安全策略 | 0 | 1| 2| 3 | 0 |
| onOpen | 可选,客户端socket连接成功回调 | (event: Event) => void | -- |
| onError | 可选,客户端socket错误时回调 | (event: Event) => void | -- |
| onClose | 可选,客户端socket关闭时回调 | (event: Event) => void | -- |
| onMessage | 可选,客户端socket收到消息时回调 | (data: Record<string, any>) => void | -- |
| onUkeyChange | 可选,Ukey插入拔出时回调 | (event: {type: 'remove' \| 'insert', data: CertType}) => void | -- |
使用示例
链式调用
// 位置签章
import { createService } from "gws-seal";
createService(gwsServiceConfig).then((gwsService) => {
gzcaService
.positionSealing(params)
.then((res) => {
console.log("签章文件url", res);
})
.catch((error) => {
console.log("签章失败原因", error);
});
});同步调用
// 位置签章
import { createService } from "gws-seal";
async function positionSealing() {
try {
const gzcaService = await createService(gwsServiceConfig);
const res = await gzcaService.positionSealing(params);
console.log("签章文件url", res);
} catch (error) {
console.log("签章失败原因", error);
}
}2 API接口
2.1 销毁
断开socket连接
接口名称
destroy
函数签名
type Destroy = () => void;2.2 重启
重新连接socket,可重新传入新配置
接口名称
restart
函数签名
type Restart = (config?: GwsServiceConfig) => void;2.3 位置签章
位置签章,返回签章文件url
接口名称
positionSealing
函数签名
type PositionSealing = (params: {
fileType: string;
fileData?: string;
filePath?: string;
page?: number;
height?: number;
width?: number;
x: number;
y: number;
}) => Promise<string>;参数说明
| 属性 | 说明 | 类型 | 默认值 |
| -------- | ------------------------------------------------------- | -------------- | ------ |
| fileType | 必填,文件类型 | PDF | OFD | -- |
| fileData | 可选,与filePath二选一,待签章文件(Base64) | String | -- |
| filePath | 可选,与fileData二选一,签章系统能访问的URL地址 | String | -- |
| page | 必填,位置签章页,第一页从0开始 | Number | -- |
| height | 可选,图片高度(毫米) | Number | -- |
| width | 可选,图片宽度(毫米) | Number | -- |
| x | 必填,位置签章坐标,表示签章后的X的位置。起始点为左下角 | Number | -- |
| y | 必填,位置签章坐标,表示签章后的Y的位置。起始点为左下角 | Number | -- |
2.4 关键字签章
关键字签章,返回签章文件url
接口名称
keywordSealing
函数签名
type KeywordSealing = (params: {
fileType: string;
fileData?: string;
filePath?: string;
height?: number;
width?: number;
keyword: string;
offX?: number;
offY?: number;
}) => Promise<string>;参数说明
| 属性 | 说明 | 类型 | 默认值 |
| -------- | ----------------------------------------------- | -------------- | ------ |
| fileType | 必填,文件类型 | PDF | OFD | -- |
| fileData | 可选,与filePath二选一,待签章文件(Base64) | String | -- |
| filePath | 可选,与fileData二选一,签章系统能访问的URL地址 | String | -- |
| height | 可选,图片高度(毫米) | Number | -- |
| width | 可选,图片宽度(毫米) | Number | -- |
| keyword | 必填,关键字 | String | -- |
| offX | 可选,关键字签章x偏移量,正数向右,负数向左 | Number | 0 |
| offY | 可选,关键字签章y偏移量,正数向上,负数向下 | Number | 0 |
2.5 骑缝章签章
骑缝章签章,返回签章文件url
接口名称
connectiveSealing
函数签名
type ConnectiveSealing = (params: {
fileType: string;
fileData?: string;
filePath?: string;
height?: number;
width?: number;
connOff?: number;
}) => Promise<string>;参数说明
| 属性 | 说明 | 类型 | 默认值 |
| -------- | ----------------------------------------------------- | -------------- | ------ |
| fileType | 必填,文件类型 | PDF | OFD | -- |
| fileData | 可选,与filePath二选一,待签章文件(Base64) | String | -- |
| filePath | 可选,与fileData二选一,签章系统能访问的URL地址 | String | -- |
| height | 可选,图片高度(毫米) | Number | -- |
| width | 可选,图片宽度(毫米) | Number | -- |
| connOff | 可选,偏移量,正数向上,负数向下。默认在右侧的中心为0 | Number | 0 |
2.6 多处位置签章
多处位置签章,返回签章文件url
接口名称
multiplePositionSealing
函数签名
type multiplePositionSealing = (params: {
fileType: string;
fileData?: string;
filePath?: string;
pictureList: PositionType[];
}) => Promise<string>;
type PositionType = {
height?: number;
width?: number;
page: number;
x: number;
y: number;
};参数说明
| 属性 | 说明 | 类型 | 默认值 |
| ----------- | ----------------------------------------------- | ---------------- | ------ |
| fileType | 必填,文件类型 | PDF | OFD | -- |
| fileData | 可选,与filePath二选一,待签章文件(Base64) | String | -- |
| filePath | 可选,与fileData二选一,签章系统能访问的URL地址 | String | -- |
| pictureList | 必填,批量位置对象,对象内容如下 | PositionType[] | -- |
批量位置对象
| 属性 | 说明 | 类型 | 默认值 |
| ------ | ------------------------------------------------------- | -------- | ------ |
| page | 必填,位置签章页,第一页从0开始 | Number | -- |
| height | 可选,图片高度(毫米) | Number | -- |
| width | 可选,图片宽度(毫米) | Number | -- |
| x | 必填,位置签章坐标,表示签章后的X的位置。起始点为左下角 | Number | -- |
| y | 必填,位置签章坐标,表示签章后的Y的位置。起始点为左下角 | Number | -- |
