# node-wechat-sign

> make it easier to get wechat access_token, jsapi_ticket and sign url

Latest version **1.0.10** (published 2017-01-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-wechat-sign
pnpm add node-wechat-sign
yarn add node-wechat-sign
bun add node-wechat-sign
```

## 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.10 |
| Published | 2017-01-18 |
| First published | 2017-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Shiwen Luo |
| Maintainers | shiwen-l |
| Keywords | wechat, jssdk, sign, access_token, jsapi_ticket, token, ticket, signature, weixin |

## Links

- npm: https://www.npmjs.com/package/node-wechat-sign
- Repository: https://github.com/pplam/wechat-sign
- Homepage: https://github.com/pplam/wechat-sign#readme
- Issues: https://github.com/pplam/wechat-sign/issues
- npm.io page: https://npm.io/package/node-wechat-sign

## Dependencies (4)

- [jssha](https://npm.io/package/jssha.md) ^1.6.0
- [request](https://npm.io/package/request.md) ^2.79.0
- [node-cache](https://npm.io/package/node-cache.md) ^4.1.1
- [request-promise](https://npm.io/package/request-promise.md) ^4.1.1

## Recent versions

- 1.0.10 (latest) — 2017-01-18
- 1.0.9 — 2017-01-18
- 1.0.8 — 2017-01-13
- 1.0.7 — 2017-01-12
- 1.0.6 — 2017-01-12
- 1.0.5 — 2017-01-12
- 1.0.4 — 2017-01-12
- 1.0.3 — 2017-01-12
- 1.0.2 — 2017-01-12
- 1.0.1 — 2017-01-12
- 1.0.0 — 2017-01-12

## README

Wechat-Sign
==========

Make it easier to get wechat access_token, jsapi_ticket and sign url

## Installation

  `npm install node-wechat-sign`

## Usage

~~~javascript
  import Wechat from 'node-wechat-sign'

  const wechat = new Wechat(config)  // You should instantiate it out of your method if you need to share the cache among methods

  const access_token = await wechat.getAccessToken()
  const jsapi_ticket = await wechat.getTicket()
  const signature = await wechat.sign(url)
~~~

Here use memory to cache the access_token and jsapi_ticket.
To refresh the cached access_token or jsapi_ticket, pass in a `refresh` parameter with `true` value:

~~~javascript
  const refresh = true
  const access_token = await wechat.getAccessToken(refresh)
  const jsapi_ticket = await wechat.getTicket(refresh)
~~~

## Configure

~~~javascript
  config = {
    appid,
    secret,
    [tokenApiTemplate,]
    [ticketApiTemplate,]
    [templateVariablePattern,]
    [cacheExpiresInSeconds,]
  }
~~~

#### appid [ STRING ]

  Your officer account's appid.

#### secret [ STRING ]

  Your officer account's secret.

#### tokenApiTemplate [ STRING ]

  Url template of wechat server for access_token.
  Default value:
  `'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{secret}'`

#### ticketApiTemplate [ STRING ]

  Url template of wechat server for jsapi_ticket.
  Default value:
  `'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi'`

#### templateVariablePattern [ REGEXP ]

  Pattern to replace above templates with real data.
  Default value:
  `/#\{([^}]*)\}/mg`

#### cacheExpiresInSeconds [ NUMBER ]

  Seconds to expire the cached access_token and jsapi_ticket.
  Default value:
  `7200`


## Contribute

  Good features and suggestions are welcome. Code here: https://github.com/pplam/wechat-sign.

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