egg-wxpay

0.1.0 • Public • Published

egg-wxpay

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-wxpay --save
or
$ cnpm i egg-wxpay --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.wxpay = {
    partnerKey: '<partnerkey>',
    appId: '<appid>',
    mchId: '<mchid>',
    notifyUrl: '<notifyurl>', //http://www.notify.com/notify
    ca: '<location-of-your-apiclient-cert.pem>',  // fs.readFileSync(path.join(__dirname, '../config/rootca.pem'))
    pfx: '<location-of-your-apiclient-cert.p12>', // fs.readFileSync(path.join(__dirname, '../config/apiclient_cert.p12')),
};
 
    
    

see config/config.default.js for more detail.

Example

//app/controller/wx.js
async pay(){
  // 支付
  const order = {
          body: '微信支付',
          out_trade_no: ulid(),// 订单号 唯一id
          total_fee: Math.floor(total * 100), // 微信最小单位是分
          spbill_create_ip: ip,               // 请求的ip地址
          openid,
          trade_type: 'JSAPI',
        };
  const payargs = await this.app.wxpay.getBrandWCPayRequestParams(order);
  this.ctx.body =  payargs;
}
 
// 回调
//app/router.js
module.exports = app => {
  const { router, controller } = app;
  ...
  router.post('/notify', app.wxpay.notify, controller.wx.notify);
  ...
}
//app/controller/wx.js
async notify() {
  const { out_trade_no } = this.ctx.request.body;// 订单号
  ...
}

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-wxpay

Weekly Downloads

7

Version

0.1.0

License

MIT

Unpacked Size

10.3 kB

Total Files

9

Last publish

Collaborators

  • wbget