# express-jssdk

> jssdk signature for express middleware

Latest version **1.0.2** (published 2020-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-jssdk
pnpm add express-jssdk
yarn add express-jssdk
bun add express-jssdk
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-03-11 |
| First published | 2017-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 37.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | jay |
| Maintainers | junxu |
| Keywords | jssdk, wechat, weixin |

## Links

- npm: https://www.npmjs.com/package/express-jssdk
- Repository: https://github.com/baaxl9vh/express-jssdk
- Homepage: https://github.com/baaxl9vh/express-jssdk#readme
- Issues: https://github.com/baaxl9vh/express-jssdk/issues
- npm.io page: https://npm.io/package/express-jssdk

## Dependencies (3)

- [redis](https://npm.io/package/redis.md) ^2.8.0
- [redlock](https://npm.io/package/redlock.md) ^4.1.0
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.0

## Recent versions

- 1.0.2 (latest) — 2020-03-11
- 1.0.2-dev.3 — 2020-03-10
- 1.0.2-dev.2 — 2020-03-10
- 1.0.2-dev.1 — 2020-03-10
- 1.0.1 — 2019-11-25
- 1.0.0 — 2019-11-25
- 0.0.22 — 2019-08-06
- 0.0.21 — 2019-08-03
- 0.0.20 — 2019-08-02
- 0.0.19 — 2019-08-02
- 0.0.18 — 2019-08-02
- 0.0.16 — 2019-08-02
- 0.0.13 — 2019-08-02
- 0.0.12 — 2019-08-02
- 0.0.11 — 2019-08-02
- … 8 more at https://npm.io/package/express-jssdk/versions

## README

# express-jssdk

微信公从号JSSDK接口签名 Express 中间件

wechat jssdk signature for express middleware

## Installation

```bash
npm install --save express-jssdk
```

## Usage

### Server Side

```javascript

var express = require('express')
var jssdk = require('express-jssdk')
var app = express()

app.get('/jssdk', jssdk({
  appId: 'your app id',                         // 公众号appId，
  secret: 'your secret'                         // 公众号secret，
}))

app.listen(80, function () {})

```

### Client Side

```javascript
var url = window.location.protocol + '//yourdomain.com/index.html';
var title = 'Test Share';
var desc = 'Test Desc';
var icon = window.location.protocol + '//yourdomain.com/icon.jpg';
$.ajax({
    url: '//yourdomain.com/api/jssdk/',
    dataType: 'json',
    type: 'GET',
    data: {url: window.location.href},          // 这里一定要用window.location.href，不然会二次分享无自定义分享，签名的url一定要与当前页面一致，包括query参数，二次分享会自动加上参数
    success: function (data) {
        wx.config({
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: [
                'checkJsApi',
                'updateAppMessageShareData',    // 1.4版本
                'updateTimelineShareData',      // 1.4版本
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'hideMenuItems'
            ]
        });
        wx.ready(function () {
            wx.hideMenuItems({
                menuList: [
                    'menuItem:share:weiboApp',
                    'menuItem:share:email'
                ],
                success: function (res) {
                },
                fail: function (res) {
                }
            });
            wx.updateAppMessageShareData({
                title: title,
                desc: desc,
                link: url,
                imgUrl: icon,
                success: function () {
                    console.log('updateAppMessageShareData success');
                }
            });
            wx.updateTimelineShareData({
                title: desc,
                link: url,
                imgUrl: icon,
                success: function () {
                    console.log('updateTimelineShareData success');
                }
            });
            wx.onMenuShareAppMessage({
                link: url,
                title: title,
                desc: desc,
                imgUrl: icon,
                success: function (res) {
                    console.log('share to friend success');
                }
            });
            wx.onMenuShareTimeline({
                link: url,
                title: desc,
                desc: desc,
                imgUrl: icon,
                success: function (res) {
                    console.log('share to timeline success');
                }
            });
        });
    },
    error: function (err) {
        console.log(err);
    }
});
```

## Configure JSSDK

```javascript
{
  appId: 'your app id',                                // 公众号appId，
  secret: 'your secret',                               // 公众号secret，
  corp: false,                                         // 是否企业号，corp account or not, default false
  nonceStrLength: 16,                                  // 随机字符串长度，最长32位，nonceStr length, default 16
  type: 'none',                                        // 票据和token保存方式：file，本地文件，redis，保存在redis，none，默认值，不保存到文件或者redis，type=none时，会强制修改cache=true
  tokenFilename: __dirname + '/local-token.json',      // access_token存储文件，access_token local file，default:__dirname/local-token.json
  ticketFilename: __dirname + '/local-ticket.json'     // jsapi ticket存储文件，jsapi ticket local file，default:__dirname/local-ticket.json
  redisHost: '127.0.0.1',                              // redis server host ip
  redisPort: 6379,                                     // redis server port
  redisAuth: 'your reids passwrd',                     // redis password
  cache: true                                          // 是否缓存在进程内存，默认true
}
```

## Change Log

+ 2018-4-24, 添加票据和token保存到redis
+ 2019-8-2, 默认会在保存一份token和ticket在运行内存，内存中token和ticket未过时时，直接使用内存数据
+ 2019-8-2, 添加Typescript types 文件
+ 2019-8-3, 更新usage
+ 2019-8-5, 修复回调bug，修订type参数，默认为none方试，只在进程内存缓存，配置项添加cache参数，添加mocha测试用例

## TODO

+ 支持多公众号[版本](./src/jssdk.ts)

## License

[MIT License](http://www.opensource.org/licenses/mit-license.php)

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