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

@neuroo_fe/wechat-payment

v1.0.6

Published

wechat payment middleware

Downloads

3

Readme

wechat-payment

GitHub issues GitHub forks GitHub stars Twitter NPM

描述

微信支付中间件。

提供了一个支付成功回调的中间件,并会根据配置的路由,自动生成支付页面。

依赖

安装

yarn add @neuroo_fe/wechat-payment

或者

npm install @neuroo_fe/wechat-payment --save

使用

后端

const express = require('express')
const app = express()
const payment = require('@neuroo_fe/wechat-payment')
const middleware = payment(app, config).middleware  // 关于config,后面文档会提到
app.use('/pay/callback', middleware(async (message, req, res, next) => {
	// 支付成功后的逻辑,message为微信返回的字段,只对 `time_end` 做了格式化处理,处理成 `2017/08/08 08:08:08` 的时间格式
}))

前端

location.href = `yourpaypath?token=youtoken&redirect=${location.href}`

一般前端在创建订单后,会有订单号,可以将订单号作为 token ,将当前页面地址作为成功后返回的地址

config

| 属性名 | 说明 | 类型 | 必填 | 参数 | 返回值 | | ------------ | ---------------------------------------- | -------- | ---- | ----------- | ---------------------------------------- | | payPath | 支付路径,必须跟微信配置的支付路径一致 | string | true | -- | -- | | getJsConfig | 获取微信 JsApiConfig 的回调函数,返回的参数必须跟微信要求的一致,并且包含 chooseWXPay 权限。回调函数的参数 url 为支付页面的路径(不包含 origin),orgin 为当前页面的域名。 | function | true | url, origin | { debug, appId, timestamp, nonceStr, signatrue, jsApiList } | | getOrderInfo | 获取订单信息的回调函数,回调函数的参数 token 是用来获取唯一订单的凭证 | function | true | token | object | | payment | 支付配置 | object | true | -- | -- |

getJsConfig 回调函数返回值

getOrderInfo 回调函数必须返回一个对象,对象中必须包含下面的参数

| 属性名 | 说明 | 类型 | | ------- | --------------------- | ------------------ | | openId | 下单者的 openid | string | | orderNo | 唯一订单号 | string | | price | 价格,以分为单位 | number || string | | body | 客服消息的标题,同样也会作为支付页面的标题 | string |

payment 参数说明

payment 也为一个对象,具体键值如下:

| 属性名 | 说明 | 类型 | | -------------- | ---------------------------------------- | ------ | | partnerKey | 参考微信开发者文档 | string | | appId | 参考微信开发者文档 | string | | mchId | 参考微信开发者文档 | string | | notifyUrl | 支付成功的回调地址,必须跟使用中间件的地址一致,这里的地址为全写的 url ,必须包含域名。 | string | | pfx | 参考微信开发者文档 | buffer | | spbillCreateIp | 参考微信开发者文档 | string | | tradeType | 参考微信开发者文档 | string |