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

@dataee/wechatpay

v2.1.2

Published

微信支付 SDK,支持刷卡支付、公众号支付、扫码支付、APP支付、H5支付,以及优惠券,红包,企业付款,微信代扣

Downloads

1

Readme

微信支付 node.js

Build Status Codacy Badge dependencies Status Known Vulnerabilities

微信支付 SDK,支持刷卡支付、公众号支付、扫码支付、APP 支付、H5 支付,以及优惠券,红包,企业付款,微信代扣

特性

  • 使用 Typescript 编写,拥有更安全的类型和更好的代码提示
  • 支持所有类型微信支付
  • 支持微信代扣
  • 提供调试模式

开始使用

const path = require("path");
const fs = require("fs");
const {
  PubPay,
  RequestError,
  CommunicationError,
  utils: { getXMLBody }
} = require("@sigodenjs/wechatpay");

const pay = new PubPay({
  appId: "wxb80e5bddb2d804f3",
  key: "6Q9VX4N3WTBM9G9XBL7H1L9PB9ANHLY7",
  mchId: "1434712502",
  pfx: fs.readFileSync(path.resolve(__dirname, "cert.p12"))
});

// 调用统一下单接口
pay
  .unifiedOrder({
    body: "腾讯充值中心-QQ会员充值",
    out_trade_no: "1217752501201407033233368018",
    total_fee: 888,
    spbill_create_ip: "8.8.8.8",
    notify_url: "https://example.com/wechatpay/notify",
    trade_type: "JSAPI",
    openid: "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"
  })
  .then(res => {
    if (!pay.verifySign(res)) {
      // 签名校验失败
      throw new Error("签名校验失败");
    }
    if (res.result_code === "FAIL") {
      console.log(res.err_code, res.err_code_des);
    } else {
      console.log(res.prepay_id);
    }
  })
  .catch(err => {
    if (err instanceof RequestError) {
      // 请求错误
    } else if (err instanceof CommunicationError) {
      // return_code = FAIL
    }
  });

// 支付结果通知
router.post("/wechatpay/notify", (req, res) => {
  const options = {
    length: req.headers["content-length"],
    limit: "1mb",
    encoding: "utf8"
  };
  getXMLBody(req, options).then(data => {
    pay
      .payNotify(data, async parsedData => {
        if (!pay.verifySign(parsedData)) {
          // 签名校验失败
        }
        if (parsedData.result_code === "FAIL") {
          // 业务逻辑失败
        }
        // ...
        return {
          return_code: "SUCCESS",
          return_msg: "OK"
        };
      })
      .then(returnData => {
        res.set("Content-Type", "application/xml; charset=utf-8");
        res.end(returnData);
      });
  });
});

类和接口

业务类

综合类

  • Pay: 组合所有支付类,包含所有支付相关接口
  • Entrust: 组合所有代扣类,包含所有代扣相关接扣

如果你只使用了某一项支付,请使用业务类。但如果涉及多种支付,使用综合类更便捷。

支付相关接口

代扣相关接口

许可证

Copyright (c) 2018 sigoden

Licensed under the MIT license.