# dzhyun-token

> 大智慧云平台token管理模块

Latest version **1.0.8** (published 2021-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install dzhyun-token
pnpm add dzhyun-token
yarn add dzhyun-token
bun add dzhyun-token
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-05-19 |
| First published | 2017-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 93.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | jiagang |
| Maintainers | jiagang, super-dongw |
| Keywords | dzhyun, token |

## Links

- npm: https://www.npmjs.com/package/dzhyun-token
- Repository: https://github.com/huicloud/dzhyun-token
- Homepage: https://github.com/huicloud/dzhyun-token#readme
- Issues: https://github.com/huicloud/dzhyun-token/issues
- npm.io page: https://npm.io/package/dzhyun-token

## Dependencies (2)

- [jssha](https://npm.io/package/jssha.md) ^2.2.0
- [dzhyun-connection](https://npm.io/package/dzhyun-connection.md) ^1.0.0

## Recent versions

- 1.0.8 (latest) — 2021-05-19
- 1.0.7 — 2021-05-19
- 1.0.6 — 2019-06-20
- 1.0.5 — 2018-06-29
- 1.0.4 — 2018-05-24
- 1.0.3 — 2018-05-23
- 1.0.2 — 2017-06-22
- 1.0.1 — 2017-05-25
- 1.0.0 — 2017-05-25

## README

大智慧云平台token前端管理模块
---
可以在前端根据appid和secret_key生成token

提供webpack插件，将明文的appid和secret_key在打包时加密

编码方式，将指定的关键字转换hex后拼上short_id从左开始拼接成2位字符，将appid和key的hex分别按位加上关键字转换hex数值取两位字符，然后生成的hex按3位一个转成字符得到转换后的字符串

### 使用
1、global

    <script src="dist/dzhyun-token.min.js"></script>
    <script>
      var tokenManager = new DzhyunTokenManager({appid: 'xxxxxx', secret_key: 'xxxxxx', shortid: 'xxxxxx'});
      tokenManager.getToken(86400).then(function(token) {
        ...
      });
    </script>

2、模块化

安装

    npm install dzhyun-token
    
使用

    import DzhyunTokenManager from 'dzhyun-token';
    ...

### API
new DzhyunTokenManager({address: 'xxxxxx', appid: 'xxxxxx', secret_key: 'xxxxxx', shortid: 'xxxxxx'})
- **address** `String` 可选，无法本地生成token时改为向远程地址请求token，需要依赖dzhyun-connection模块
- **appid** `String` 必填
- **secret_key** `String` 必填
- **shortid** `String` 必填

DzhyunTokenManager.prototype.getToken(duration) 得到token, 返回Promise对象，会缓存生成的token
- **duration** `Number` 可选，生成token的有效期秒数，默认不传时默认1天有效期

DzhyunTokenManager.prototype.generateToken(duration) 生成新的token, 返回Promise对象
- **duration** `Number` 可选，生成token的有效期秒数，默认不传时默认1天有效期

### webpack插件使用

    const DzhyunTokenManagerPlugin = require('dzhyun-token/plugin');

    plugins: [
        ...
        new DzhyunTokenManagerPlugin({ useFake: true, keyword: 'abcdef' })
    ],

参数说明
- **useFake** `Boolean` 可选，是否填充伪造假的appid信息
- **keyword** `String` 可选，指定加密混浊用关键字，默认使用随机字符每次编译混浊后的编码会不同，指定了关键字能保证每次编译后混浊后编码相同

---
_Source: https://npm.io/package/dzhyun-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
