Giter Site home page Giter Site logo

egg-alipay-crypto's Introduction

egg-alipay-crypto

扩展支持支付宝加解密 nodejs 版本的 egg 插件

NPM version Codacy Badge Known Vulnerabilities npm download License

Sonar

Install

# use pnpm
$ pnpm install egg-alipay-crypto

# use yarn
$ yarn add egg-alipay-crypto

Usage

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

Configurations

egg-alipay-crypto support all alipay-crypto's configurations, check alipay-crypto documents to get more information.

// {app_root}/config/config.default.js
exports.alipaycrypto = {
  privateKey: ''
}

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 = {
      app_id: '20135234674',
      method: 'alipay.system.oauth.token',
      sign_type: 'RSA2',
      version: '1.0',
      charset: 'utf-8',
      timestamp: '2023-07-29 14:50:22',
      grant_type: 'authorization_code',
      biz_content: ''
    }

    const initial = ctx.serializedParams(data) // 'app_id=20135234674&charset=utf-8&grant_type=authorization_code&method=alipay.system.oauth.token&sign_type=RSA2&timestamp=2023-07-29 14:50:22&version=1.0'
    const sign = ctx.alipaySign(initial) // or => const sign = ctx.alipaySign(data)
    const md5_result = ctx.md5(data)
    // or
    const initial = app.alipaycrypto.serializedParams(data)
    const sign = app.alipaycrypto.encrypt(initial)
    const md5_result = app.alipaycrypto.md5(data)
  }
}

module.exports = HomeService

Change logs

Change logs

Questions & Suggestions

Please open an issue here.

License

MIT

egg-alipay-crypto's People

Contributors

saqqdy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.