Giter Club home page Giter Club logo

node-weixin-pay's Introduction

node-weixin-pay NPM version Build Status Dependency Status Coverage percentage

Weixin 支付 API

支持QQ群:39287176

Install

$ npm install --save-exact node-weixin-pay

Usage

通用功能

1、初始化对象与基本数据

var nodeWeixinPay = require('node-weixin-pay');
var nodeWeixinConfig = require('node-weixin-config');

// 必须
var merchant = {
  id: process.env.MERCHANT_ID || 'id',
  key: process.env.MERCHANT_KEY || 'key'
};
var app = {
  id: process.env.APP_ID || 'appid',
  secret: process.env.APP_SECRET || 'appsecret',
  token: process.env.APP_TOKEN || 'apptoken'
};

// 证书是可选的,但在退款,红包,企业支付时需要

var certificate = {
  pkcs12: path.resolve(certPKCS12File),             //格式是文件名
  key: String(certKey)
};

//或者

var certificate = {
  pfx: new Buffer(conf.merchant_pfx, 'base64'),     //格式是文件二进制内容
  pfxKey: conf.merchant_id
};

//对于大部分的支付接口来说是需要config的
var config = {
  app: app,
  merchant: merchant,
  // 可选(除了退款外接口,可以不用添加)
  certificate: certificate
};

//校验数据的正确性
nodeWeixinConfig.app.init(app);
nodeWeixinConfig.merchant.init(merchant);

var params = { openid: process.env.OPENID,
  spbill_create_ip: '1.202.241.25',
  notify_url: 'http://wx.domain.com/weixin/pay/main',
  body: '测试支付',
  out_trade_no: '111',
  total_fee: '1',
  trade_type: 'JSAPI',
  appid: app.id,
  mch_id: merchant.id,
  nonce_str: 'XjUw56N8MjeCUqHCwqgiKwr2CJVgYUpe' };

2、签名一个请求

var sign = nodeWeixinPay.sign(merchant, params);

3、准备一个支付配置

var prepayId = 'prepayId';
var config = nodeWeixinPay.prepay(app, merchant, prepayId);

处理微信回调接口API

1、处理回调数据,所有的请求的处理结果回调

//req.rawBody should be enabled
var req = {rawBody: xml};
var res = {
  json: function() {

  }
};
nodeWeixinPay.callback.notify(app, merchant, req, res, function(error, data) {
});

基础API

1、发送统一支付请求

nodeWeixinPay.api.order.unified(config, params, function(error, data) {
});

2、发送订单查询请求

var config = nodeWeixinPay.api.query(config, params, function(error, data) {
});

3、发送订单关闭请求

var config = nodeWeixinPay.api.close(config, params, function(error, data) {
});

4、发送创建退款请求

var config = nodeWeixinPay.api.refund.create(config, params, function(error, data) {
});

5、发送退款查询请求

var config = nodeWeixinPay.api.refund.query(config, params, function(error, data) {
});

6、发送下载对账单请求

var config = nodeWeixinPay.api.statements(config, params, function(error, data) {
});

7、发送测速报告请求

var config = nodeWeixinPay.api.report(config, params, function(error, data) {
});

微信红包接口

1、发起普通微信红包

var config = nodeWeixinPay.api.redenvelope.create(config, params, function(error, data) {
});

2、发起裂变微信红包

var config = nodeWeixinPay.api.redenvelope.distribute(config, params, function(error, data) {
});

3、发起红包查询

var config = nodeWeixinPay.api.redenvelope.query(config, params, function(error, data) {
});

企业付款接口

1、发起企业支付

var config = nodeWeixinPay.api.enterprise.create(config, params, function(error, data) {
});

2、查询企业支付

var config = nodeWeixinPay.api.enterprise.query(config, params, function(error, data) {
});

License

Apache-2.0 © calidion

node-weixin-pay's People

Contributors

calidion avatar lgyhector avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-weixin-pay's Issues

企业付款api 验证mch_billno字段

1.企业付款接口中验证mch_billno字段为必填,实际微信文档是没有这个字段,此字段在红包中需要,请去除这个验证
2.企业付款接口签名功能,prepare方法中加入的字段appid实际不需要,mch_id实际在文档中应该为mchid,加入这些错误字段会导致提交到微信后报SIGN_ERROR错误,请尽快修改

npm run test 的时候报错

请问一下,在npm run test 的时候报了以下的错误(Invalid Merchant Data: {"key":"key","reason":"Key key is NULL"}),小白不知道怎么解决这个问题呀

f:\faymi\git_project\node-weixin-pay\gulpfile.js:40
      throw err;
Error: Invalid Merchant Data: {"key":"key","reason":"Key key is NULL"}
    at Error (native)
    at Object.init (f:\faymi\git_project\node-weixin-pay\node_modules\node-weixin-config\lib\merchant.js:7:13)
    at Object.<anonymous> (f:\faymi\git_project\node-weixin-pay\test\api.js:22:27)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Object.Module._extensions.(anonymous function) [as .js] (f:\faymi\git_project\node-weixin-pay\node_modules\istanbul\lib\hook.js:109:37)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)

发送请求方法问题

发现支付这块请求接口比较特殊的几点:
1、需要证书加密的xmlssl请求(涉及退款功能的接口)
2、无需证书加密的xml(大部分接口)
3、微信接口直接返回文本表格(订单对账接口)
目前pay模块发送请求request方法中用的都是 xmlssl方法,对上述有两种方式并不支持。
感觉需要完善一下~

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.