1.1.0 • Published 11 months ago

egg-wxcrypto v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

egg-wxcrypto

扩展支持微信消息加解密 nodejs 版本的 egg 插件

NPM version Codacy Badge Known Vulnerabilities npm download License

Sonar

Install

# use pnpm
$ pnpm install egg-wxcrypto

# use yarn
$ yarn add egg-wxcrypto

Usage

// {app_root}/config/plugin.js
exports.wxcrypto = {
  enable: true,
  package: 'egg-wxcrypto'
}

Configurations

egg-wxcrypto support all node-wxcrypto's configurations, check node-wxcrypto documents to get more information.

// {app_root}/config/config.default.js
exports.wxcrypto = {
  // token: '',
  // aesKey: '',
  // appId: '',
  // options: {
  //   normalizeTags: true,
  //   buildXmlOptions: {}, // 透传用于生成 xml 字符串的配置
  //   xmlOptions: {} // 透传用于解析 xml 字符串的配置
  // }
}

Use in service

// {app_root}/app/service/home.js
const { Service } = require('egg')

class HomeService extends Service {
  async index() {
    const { ctx, app } = this
    const data = {
      // ...
    }
    await ctx.decryptWxMsg(this.request.body, options) // decrypt
    await ctx.encryptWxMsg(data, options) // encrypt
    // or
    await app.wxcrypto.decrypt(encrypt, timestamp, nonce, options) // decrypt
    await app.wxcrypto.encrypt(data, options) // encrypt
  }
}

module.exports = HomeService

Extended Context Methods

// {app_root}/app/service/home.js
const { ctx } = this

ctx.buildXML(data, options) // data => xmlString
ctx.parseXML(xmlString, options) // xmlString => data

Change logs

Change logs

Questions & Suggestions

Please open an issue here.

License

MIT

1.1.0

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

1.0.0-beta.0

11 months ago