storage-sdk-xcx
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

1 、下载与安装

环境依赖

微信开发者工具

安装SDK

执行以下命令安装小程序npm扩展包:

// 安装前置模块 
npm install crypto-js
// 安装加密SDK
npm install storage-sdk-xcx

2、开始使用

下面为您演示使用Storage JS SDK完成一个基础操作,如创建一条数据。

// app.js
const { create } = require('storage-sdk-xcx')
const http = create({
   baseUrl: 'http://dev-gw.sunac.com.cn',
   crypto: {
      type: 'des',
      key: 'kkkkkkkkkkkkkkkk',
      cfg: {
         iv: 'kkkkkkkkkkkkkkkk'
      }
   },
   signQuery: {
      ak: "ccccc",
      sk: "bbbbb"
   }
})

http.post('/storage/api/v1/tenant/insertOne?tenantId=tenantId_3002', {
   "tenantId": "tenantId_3002",
   "tempId": "tempId-01",
   "data": {
      "name": "ssss",
			"phone": "15811388293"
   }
}, {
   unEncryt: false
}).then(res => {
   console.log(res)
})

3、初始化http对象

3.1 初始化create对象参数说明

参数 说明 类型 默认值
baseUrl base 地址 string -
crypto 加密对象 object -
unEncryt 禁用加密,在create 实例传入将覆盖至所有接口,单个接口使用,在config添加该属性中也生效 boolean falase
signQuery 签名参数配置 object -
…… 其余参数均和 【wx.request】 配置相同 - -

3.2 crypto参数说明

参数 类型 是否必填 针对加密对象
type aes|des |rsa_PKCS1 all
key string 加密key值 all
cfg 调整aes、des的加密模式、填充模式等等具体可以查看文档 【crypto-js】, 目前仅支持mode:CBC padding: Pkcs7,其中iv参数非必填项默认为""。 ase|ase

3.3 signQuery参数说明

参数 说明 类型 默认值
sk sercetKey string -
ak accessKey string -
exp 单位:秒。exp秒后过期 number 900

4、实例方法

拦截器
// 请求拦截器
http.interceptors.request.use((config) => {
   return config;
});

// 响应拦截器
http.interceptors.response.use((res) => {
   // 自定义错误
   if (res.code !== 200) {
      return Promise.reject(new Error("Request Error"));
   };

   return res;
}, (error) => {
   const { message, response, config } = error;
   return Promise.reject(error);
});
请求
http.request(config)

http.get(url[, data[, config]])

http.post(url[, data[, config]])

http.put(url[, data[, config]])

http.delete(url[, config])

http.head(url[, config])

http.options(url[, config])

http.connect(url[, config])

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.11
1.0.01

Package Sidebar

Install

npm i storage-sdk-xcx

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

385 kB

Total Files

10

Last publish

Collaborators

  • amaoy