@ultramedia/jssdk
v0.1.0
Published
wechat's media platform jssdk utilities
Downloads
2
Readme
wechat's media platform jssdk utilities
Installation
npm i @ultramedia/jssdk
Usage
// express
const app = require('express')()
const {Sdk, Config} = require('@ultramedia/jssdk')
const config = Config({
apps: [{key: 'app id', secret: 'app secret'}]
})
const sdk = Sdk(config)
app.post('/config/:appid', (req, res, next) => {
const {appid} = req.params
const {key, secret} = config.getApp(appid)
sdk.createConfig(key, secret).then(data => res.json(data))
})
mock for testing
const {mock} = require('@ultramedia/jssdk')
describe('suite', () => {
let unmock;
beforeAll(() => {
unmock = mock()
})
afterAll(() => {
unmock()
})
it('test', () => {
console.log('all http requests for wechat server will be mocked')
})
})
mock data:
// when fetch access_token from wechat's server, mock response will be:
{access_token: 'access_token', expires_in: 7200}
// when fetch ticket from wechat's server, mock response will be:
{ticket: 'ticket', expires_in: 7200}
API
const {Config, Sdk, mock} = require('@ultramedia/jssdk')
Types declaration in: index.d.ts
Changes
v0.1.x
- add typescript declaration file.
- rename
createSdk
toSdk
from exports. (break change)