Socket
Book a DemoInstallSign in
Socket

@neuroo_fe/wechat-payment

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@neuroo_fe/wechat-payment

wechat payment middleware

1.0.6
latest
Source
npmnpm
Version published
Weekly downloads
15
Maintainers
4
Weekly downloads
 
Created
Source

wechat-payment

GitHub issues GitHub forks GitHub stars Twitter NPM

描述

微信支付中间件。

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

依赖

  • ^node 7.x

安装

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支付路径,必须跟微信配置的支付路径一致stringtrue----
getJsConfig获取微信 JsApiConfig 的回调函数,返回的参数必须跟微信要求的一致,并且包含 chooseWXPay 权限。回调函数的参数 url 为支付页面的路径(不包含 origin),orgin 为当前页面的域名。functiontrueurl, origin{ debug, appId, timestamp, nonceStr, signatrue, jsApiList }
getOrderInfo获取订单信息的回调函数,回调函数的参数 token 是用来获取唯一订单的凭证functiontruetokenobject
payment支付配置objecttrue----

getJsConfig 回调函数返回值

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

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

payment 参数说明

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

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

FAQs

Package last updated on 21 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.