Socket
Book a DemoInstallSign in
Socket

koa-weixin-jssdk

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-weixin-jssdk

Koa weixin jssdk middleware

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created
Source

koa-weixin-jssdk

koa weixin jssdk middleware

Quick Start


import koa from 'koa';
import koaBody from 'koa-body';
import weixinJSSDK from '../src';

const port = process.env.PORT || 3000;
const app = koa();

app.use(koaBody());

app.use(weixinJSSDK({
    appId: '<YOUR_APP_ID>', // [required] weixin-jssdk app id
    
    secret: '<YOUR_SECRET>', // weixin-jssdk secret
 
    pathName: '/jssdk', // [optional] eg: http://imyourfather.com/jssdk

    onError: (err, ctx) => {
        console.error(err);
        ctx.body = 'error';
    },
}));

app.listen(port);

Example

$ git clone <this_git_repo>
$ npm i
$ npm start

Third-party weixin service

Maybe you already have a Third-party weixin service and have a access token, you could use custom fetchTicket function instead of secret.

The fetchTicket function must return { ticket, expires_in } as a Promise instance.


app.use(weixinJSSDK({
    appId: '<YOUR_APP_ID>', // [required]
    
    fetchTicket() {
        return fetch(/* you_third_party_weixin_fetch_ticket_url */);
        // Must return a promise;
        // The responsed json must include `ticket` and `expires_in` fields.
    }
 
    // other configs...

}));

Installation

Using npm:

$ npm install koa-weixin-jssdk --save

License

MIT

Keywords

weixin

FAQs

Package last updated on 18 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts