npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@byzk/usbkey-request-base

v1.0.6

Published

博雅中科usbkey服务跨域解决方案

Downloads

17

Readme

博雅中科Usbkey服务对应的js调用方式,主要解决跨域问题并为集成客户端提供简单可靠的调用方式, 此库为请求解决的基础调用库.

目录

安装

示例

API简介

使用技巧

IE使用示例

其他

安装

浏览器中使用

<script src="http://raw.githack.com/SuLinXin66/bk-usbkey-request-base/master/dist/bk-usbkey-request-base-iife.min.js"></script>

注: 因本库采用es6 Promise对象, 如果要兼容IE系列浏览器请引用如下js来支持Promise对象

<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script> 
<script src="http://raw.githack.com/SuLinXin66/bk-usbkey-request-base/master/dist/bk-usbkey-request-base-iife-ie.min.js"></script>

npm中使用

npm install --save @byzk/usbkey-request-base

yarn中使用

yarn add @byzk/usbkey-request-base

示例

浏览器中使用示例

<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script> 
<script src="http://raw.githack.com/SuLinXin66/bk-usbkey-request-base/master/dist/bk-usbkey-request-base-iife-ie.min.js"></script>
<script>
  bkUsbkeyReqBase([
    {
      url: "https://127.0.0.1:8000/api/EPSAPP_Initialize",   
      data: {
        crosFlag: 1
      },
      nameSign: "test1",
      timeOut: 3000
    }
  ]).catch(function (err) {
    console.log(err);
  });
</script>

CommonJS规范中使用

const bkUsbkeyReqBase = require('@byzk/usbkey-request-base').default;
bkUsbkeyReqBase([
  {
    url: "https://127.0.0.1:8000/api/EPSAPP_Initialize",   
    data: {
      crosFlag: 1
     },
    nameSign: "test1",
    timeOut: 3000
  }
]).then(data=>{
  console.log(data);
}).catch(e=>{
  console.log("出错了 => ", e.message);
})

ES6规范中使用

import bkUsbkeyReqBase from "@byzk/usbkey-request-base"; 
bkUsbkeyReqBase([
  {
    url: "https://127.0.0.1:8000/api/EPSAPP_Initialize",   
    data: {
      crosFlag: 1
     },
    nameSign: "test1",
    timeOut: 3000
  }
]).then(data=>{
  console.log(data);
}).catch(e=>{
  console.log("出错了 => ", e.message);
})

API简介

请求方法

bkUsbkeyReqBase (params: CrossSendData | Array<CrossSendData>, errorJudgeFun?: (jsonData: any, strData: string) => boolean): Promise<CrossResponseMap<CrossResponse>> | null;

方法参数: params: 请求参数 errorJudgeFun?: 错误判断方法, 传入usbkey响应数据,返回是否有错 方法返回值: 请求结果 发起请求到usbkey本地服务, 请求参数CrossSendData请参考请求参数, 返回参数CrossResponse请参考返回参数

请求参数

CrossRequestType

// 请求方式
type CrossRequestType = 'GET' | 'get' | 'POST' | 'post';

CrossSendData

// 请求发送数据
interface CrossSendData {
  // 请求地址, 必选
  url: string;
  // 方法签名, 请求响应之后,从响应结果集中根据nameSign的值进行获取对应结果, 必选
	nameSign: string;
  // 超时时间, 默认5000(5s), 配置小于或者等于0则永不超时, 可选
  timeOut?: number;
  // 请求方式, 默认为post, 可选
  method?: CrossRequestType;
}

响应参数

CrossResponseMap

// 响应结果集
interface CrossResponseMap<CrossResponse> {
  	// 集合长度
    length: number;
		// 集合内操作的方法签名(请求时传入的nameSign): 响应内容
    [name: string]: CrossResponse;
}

CrossResponse

// 响应结果
interface CrossResponse {
    // 请求时填写的nameSign
    name: string;
    // 响应的具体内容数据
    data: CrossResponseData;
}

CrossResponseData

// 响应的具体数据
interface CrossResponseData {
    // 试图将返回结果转换为一个对象, 如果转换失败,此项为 undefined
    jsonData: object | undefined
    // 响应的原始数据
    strData: string | undefined
}

异常

CrossResponseErr

// 当响应处理错误时的错误数据
interface CrossResponseErr {
    // 错误编码
    code: string | number;
    // 消息
    message: string;
    // 错误的方法签名
    errNameSign?: string;
    // 错误的Json数据
    jsonData?: any;
    // 错误的strData
    strData?: any;
    // 成功的条数
    successLength?: number;
    // 总共操作的条数
    totalOperateLength?: number;
    // 错误消息
    msg?: string;
}

使用技巧

使用async/await

import bkUsbkeyReqBase from "@byzk/usbkey-request-base"; 
async function test(){
  try {
    const getCertResult = await bkUsbkeyReqBase({
      url: "http://127.0.0.1/test/getCert",
      nameSign: "getCert"
    })
    
    const certInfo = getCertResult["getCert"].data.jsonData.result;
    
    const certInfoResult = await bkUsbkeyReqBase([
      {
        url: "http://127.0.0.1/test/getCertInfoByNo",
        nameSign: "certNo",
        data: {
          certNo: 1
        }
      },
      {
        url: "http://127.0.0.1/test/getCertInfoByNo",
        nameSign: "certStartTime",
        data: {
          certNo: 21
        }
      },
      {
        url: "http://127.0.0.1/test/getCertInfoByNo",
        nameSign: "certEndTime",
        data: {
          certNo: 22
        }
      },
    ])
    
    const certNo = certInfoResult["certNo"].data.jsonData.result;
    
    const certStartTime = certInfoResult["certStartTime"].data.jsonData.result;
    
    const certEndTime = certInfoResult["certEndTime"].data.jsonData.result;
    
    console.log("证书数据 => ", certInfo);
    console.log("证书序列号 => ", certNo);
    console.log("证书有效期,开始时间 => ", certStartTime);
    console.log("证书有效期,结束时间 => ", certEndTime);
  } catch(e) {}
}

IE使用示例

<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script> 
    <script type="text/javascript" src="http://raw.githack.com/SuLinXin66/bk-usbkey-request-base/master/dist/bk-usbkey-request-base-iife-ie.min.js"></script>
    <script>
       window.onload = function(){
         
          bkUsbkeyReqBase({
              url: "http://127.0.0.1/test/getCert",
              nameSign: "getCert"
          })["then"](function(data) {
            console.log("getCert response data => ", data)
            var certStr  = data["getCert"].data.jsonData.result
             bkUsbkeyReqBase([
               {
                 url: "http://127.0.0.1/test/getCertInfoByNo",
                 nameSign: "certNo",
                 data: {
                   certNo: 1
                 }
               },
               {
                url: "http://127.0.0.1/test/getCertInfoByNo",
                nameSign: "certStartTime",
                data: {
                  certNo: 21
                }
              },
              {
                url: "http://127.0.0.1/test/getCertInfoByNo",
                nameSign: "certEndTime",
                data: {
                  certNo: 22
                }
              }
            ])["then"](function(data){
              // 正常返回
              console.log(data);
              var certNo = data["certNo"].data.jsonData.result;

              var certStartTime = data["certStartTime"].data.jsonData.result;

              var certEndTime = data["certEndTime"].data.jsonData.result;

              console.log("证书数据 => ", certInfo);
              console.log("证书序列号 => ", certNo);
              console.log("证书有效期,开始时间 => ", certStartTime);
              console.log("证书有效期,结束时间 => ", certEndTime);
            })["catch"](function(e){
              // 错误信息
              console.log("出错了 => ", e.message);
            })
          })["catch"](function(e){
            console.log("发生错误")
          })
       }
    </script>
  </head>
  <body>
		<h1>请打开开发者工具, 查看console结果</h1>
  </body>
</html>

其他

API文档