npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-weixin-pay

v0.5.1

Published

> Weixin 支付 API

Downloads

493

Readme

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 id = 'id';
var config = nodeWeixinPay.prepay(app, merchant, id);

处理微信回调接口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