https://github.com/saqqdy/egg-wxcrypto
扩展支持微信消息加解密nodejs版本的egg插件
https://github.com/saqqdy/egg-wxcrypto
egg-plugin egg-wxcrypto eggjs eggplugin node-wxcrypto wxcrypto
Last synced: 3 months ago
JSON representation
扩展支持微信消息加解密nodejs版本的egg插件
- Host: GitHub
- URL: https://github.com/saqqdy/egg-wxcrypto
- Owner: saqqdy
- License: mit
- Created: 2023-06-25T09:43:42.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-25T15:22:43.000Z (over 1 year ago)
- Last Synced: 2025-02-20T20:17:46.134Z (4 months ago)
- Topics: egg-plugin, egg-wxcrypto, eggjs, eggplugin, node-wxcrypto, wxcrypto
- Language: TypeScript
- Homepage:
- Size: 543 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# egg-wxcrypto
扩展支持微信消息加解密 nodejs 版本的 egg 插件
[![NPM version][npm-image]][npm-url]
[![Codacy Badge][codacy-image]][codacy-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![License][license-image]][license-url][![Sonar][sonar-image]][sonar-url]
## Install
```bash
# use pnpm
$ pnpm install egg-wxcrypto# use yarn
$ yarn add egg-wxcrypto
```## Usage
```js
// {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](https://github.com/saqqdy/node-wxcrypto) to get more information.
```js
// {app_root}/config/config.default.js
exports.wxcrypto = {
// token: '',
// aesKey: '',
// appId: '',
// options: {
// normalizeTags: true,
// buildXmlOptions: {}, // 透传用于生成 xml 字符串的配置
// xmlOptions: {} // 透传用于解析 xml 字符串的配置
// }
}
```### Use in service
```js
// {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
```js
// {app_root}/app/service/home.js
const { ctx } = thisctx.buildXML(data, options) // data => xmlString
ctx.parseXML(xmlString, options) // xmlString => data
```## Change logs
[Change logs](./CHANGELOG.md)
## Questions & Suggestions
Please open an issue [here](https://github.com/saqqdy/egg-wxcrypto/issues).
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/egg-wxcrypto.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-wxcrypto
[codacy-image]: https://app.codacy.com/project/badge/Grade/f70d4880e4ad4f40aa970eb9ee9d0696
[codacy-url]: https://www.codacy.com/gh/saqqdy/egg-wxcrypto/dashboard?utm_source=github.com&utm_medium=referral&utm_content=saqqdy/egg-wxcrypto&utm_campaign=Badge_Grade
[snyk-image]: https://snyk.io/test/npm/egg-wxcrypto/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-wxcrypto
[download-image]: https://img.shields.io/npm/dm/egg-wxcrypto.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-wxcrypto
[license-image]: https://img.shields.io/badge/License-MIT-blue.svg
[license-url]: LICENSE
[sonar-image]: https://sonarcloud.io/api/project_badges/quality_gate?project=saqqdy_egg-wxcrypto
[sonar-url]: https://sonarcloud.io/dashboard?id=saqqdy_egg-wxcrypto