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

express-jssdk

v1.0.2

Published

jssdk signature for express middleware

Downloads

7

Readme

express-jssdk

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

wechat jssdk signature for express middleware

Installation

npm install --save express-jssdk

Usage

Server Side


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

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

{
  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

License

MIT License