Git Product home page Git Product logo

wechat-payment's Introduction

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

wechat-payment's People

Contributors

heftykoo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wechat-payment's Issues

Use template-literal instead of EJS

Template Literal is fastest, smallest and simplest template engine, because it use JS's literal template feature.

It's 55 times faster than EJS, and it also use less CPU and RAM ressources, so it may be a good idea to use it instead of EJS 😀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.