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

weixinpay-sdk

v1.0.2

Published

基于微信官方的原生 API 封装而成的 SDK,将官方要求的 xml 格式均通过 sdk 转换成 JSON 格式方便开发,当前已支持 Native

Downloads

6

Readme

微信支付 weixinpay-sdk

版本说明

  • v1.0.1
    • 封装微信官方原生接口,可以使用 json 格式进行数据请求
    • 当前完成 Native 支付方式
    • 完成接口:统一下单、查询订单、关闭订单
    • 包含功能:验签方法,转换工具等。

安装

npm i weixinpay-sdk

使用示例

  • 接口方法:
    • 统一下单:unifiedorder
    • 查询订单:orderquery
    • 关闭订单:closeorder

统一下单

const WeiXinPay = require('weixinpay-sdk')
// 基础配置
// 特别说明:只要正确配置了商户 api 私密 key, SDK 会自动创建随机字符串和签名。
let config = {
  appid: '', // 公众账号 ID
  mch_id: '', // 商户号
  key: '' // 商户 api key
}
let wxPay = new WeiXinPay(config);
let order = Date.now();
let orderRes = await wxPay.exec('unifiedorder', {
  body: '支付测试', // 商品简单描述
  out_trade_no: order, // 商户订单号
  total_fee: 1, // 订单总金额,单位分
  spbill_create_ip: req.ip, // 客户端 Ip
  trade_type: 'NATIVE', // 交易类型 JSAPI | NATIVE | APP
  notify_url: 'http://domain.com/notify', // 交易成功后的异步通知地址
})

查询订单

app.get('/queryorder', async (req, res) => {
  let order = req.query;
  let result = await wxPay.exec('orderquery', order);
  if (wxPay.checkSign(result)) {
    res.send(result);
  } else {
    res.send({
      msg: '查询失败!'
    });
  }
})

关闭订单

app.get('/closeorder', async (req, res) => {
  let order = req.query;
  let result = await wxPay.exec('closeorder', order);
  if (wxPay.checkSign(result)) {
    if (result.return_msg === 'OK') {
      res.send({
        msg: '订单已关闭!'
      })
    } else {
      res.send({
        msg: result.return_msg
      })
    }
  } else {
    res.send({
      msg: result.return_msg
    });
  }
})

异步通知

app.post('/notify', XmlBodyParser({
  trim: false,
  explicitArray: false
}), (req, res) => {
  let data = req.body.xml;
  if (wxPay.checkSign(data)) {
    // 验签成功
    // doWork...
    console.log('验签成功')
  } else {
    // 验签失败
    console.log('验签失败')
  }
  res.send(wxPay.notifyOK)
})