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

wechatpay-nodejs-sdk

v0.0.7

Published

A Node.js library for WeChat Pay integration.

Downloads

12

Readme

wechatpay-nodejs-sdk

wechatpay-nodejs-sdk 是一个用于 Node.js 的微信支付集成库。它提供了简单易用的方法来与微信支付 API 进行交互,包括签名验证、发送请求、处理微信支付回调等功能。

功能特性

  • 发送支付请求(如 Native 支付请求)
  • 验证微信支付回调的签名
  • 解密微信支付加密数据
  • 缓存和获取微信支付公钥

安装

您可以通过 npm 来安装这个库:

npm install wechatpay-nodejs-sdk

快速开始

以下是一个如何使用 wechatpay-nodejs-sdk 发送支付请求和处理微信支付回调的简单示例:

const WechatPay = require('wechatpay-nodejs-sdk');
const wechatPay = new WechatPay({
  appid: '您的微信应用ID',
  mchid: '您的微信商户ID',
  publicKey: fs.readFileSync('path/to/your/public/key.pem'),
  privateKey: fs.readFileSync('path/to/your/private/key.pem'),
  secretKey: '您的微信支付密钥'
});

// 发送 Native 支付请求
const paymentData = await wechatPay.transactions_native({
  description: '商品描述',
  out_trade_no: '订单号',
  amount: { total: 100 },
  notify_url: 'https://your.domain/notify'
});

// 验证微信支付回调的签名
router.post('/notify', async (req, res) => {
  const isVerified = await wechatPay.verifySign({
    body: req.body,
    signature: req.headers['wechatpay-signature'],
    serial: req.headers['wechatpay-serial'],
    nonce: req.headers['wechatpay-nonce'],
    timestamp: req.headers['wechatpay-timestamp']
  });
  if (isVerified) {
    // 签名验证成功的逻辑
  } else {
    // 签名验证失败的逻辑
  }
});

文档

更多详细信息,请参阅文档

贡献

欢迎贡献!如果您有任何改进建议或功能请求,请在 GitHub 仓库中创建一个 issue。

许可证

此项目采用 MIT 许可证。有关详细信息,请参阅 LICENSE 文件。