Gathering detailed insights and metrics for wechatpay-node-v3-laf
Gathering detailed insights and metrics for wechatpay-node-v3-laf
Gathering detailed insights and metrics for wechatpay-node-v3-laf
Gathering detailed insights and metrics for wechatpay-node-v3-laf
npm install wechatpay-node-v3-laf
Typescript
Module System
Node Version
NPM Version
70.3
Supply Chain
97.8
Quality
74.3
Maintenance
100
Vulnerability
100
License
TypeScript (98.72%)
JavaScript (1.28%)
Total Downloads
1,641
Last Day
1
Last Week
4
Last Month
18
Last Year
544
619 Stars
83 Commits
93 Forks
1 Watching
1 Branches
8 Contributors
Minified
Minified + Gzipped
Latest Version
2.1.14
Package Id
wechatpay-node-v3-laf@2.1.14
Unpacked Size
111.69 kB
Size
18.40 kB
File Count
13
NPM Version
9.5.1
Node Version
18.16.0
Publised On
03 Nov 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-63.6%
4
Compared to previous week
Last month
38.5%
18
Compared to previous month
Last year
-50.4%
544
Compared to previous year
微信官方在2020-12-25正式开放了v3版本的接口,相比较旧版本v2有了不少改变,例如:
由于官方文档只支持java和php,所以我在这里使用ts简单的封装了一个版本,支持在js或者ts中使用,后续会更加完善这个npm包,谢谢。
yarn add wechatpay-node-v3
(也可以用npm)
1import WxPay from 'wechatpay-node-v3'; // 支持使用require 2import fs from 'fs'; 3import request from 'superagent'; 4 5const pay = new WxPay({ 6 appid: '直连商户申请的公众号或移动应用appid', 7 mchid: '商户号', 8 publicKey: fs.readFileSync('./apiclient_cert.pem'), // 公钥 9 privateKey: fs.readFileSync('./apiclient_key.pem'), // 秘钥 10}); 11 12# 这里以h5支付为例 13try { 14 # 参数介绍请看h5支付文档 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml 15 const params = { 16 appid: '直连商户申请的公众号或移动应用appid', 17 mchid: '商户号', 18 description: '测试', 19 out_trade_no: '订单号', 20 notify_url: '回调url', 21 amount: { 22 total: 1, 23 }, 24 scene_info: { 25 payer_client_ip: 'ip', 26 h5_info: { 27 type: 'Wap', 28 app_name: '网页名称 例如 百度', 29 app_url: '网页域名 例如 https://www.baidu.com', 30 }, 31 }, 32 }; 33 const nonce_str = Math.random().toString(36).substr(2, 15), // 随机字符串 34 timestamp = parseInt(+new Date() / 1000 + '').toString(), // 时间戳 秒 35 url = '/v3/pay/transactions/h5'; 36 37 # 获取签名 38 const signature = pay.getSignature('POST', nonce_str, timestamp, url, params); # 如果是get 请求 则不需要params 参数拼接在url上 例如 /v3/pay/transactions/id/12177525012014?mchid=1230000109 39 # 获取头部authorization 参数 40 const authorization = pay.getAuthorization(nonce_str, timestamp, signature); 41 42 const result = await request 43 .post('https://api.mch.weixin.qq.com/v3/pay/transactions/h5') 44 .send(params) 45 .set({ 46 Accept: 'application/json', 47 'Content-Type': 'application/json', 48 'User-Agent': 49 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', 50 Authorization: authorization, 51 }); 52 53 console.log('result==========>', result.body); 54 } catch (error) { 55 console.log(error); 56 }
如果你使用的是nest框架,请结合nest-wechatpay-node-v3
一起使用。
import WxPay from 'wechatpay-node-v3';
或者 const WxPay = require('wechatpay-node-v3')
参数介绍
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
appid | 直连商户申请的公众号或移动应用appid | 是 |
mchid | 商户号 | 是 |
serial_no | 证书序列号 | 否 |
publicKey | 公钥 | 是 |
privateKey | 密钥 | 是 |
authType | 认证类型,目前为WECHATPAY2-SHA256-RSA2048 | 否 |
userAgent | 自定义User-Agent | 否 |
key | APIv3密钥 | 否 有验证回调必须 |
openssl x509 -in apiclient_cert.pem -noout -serial
获取以下函数是我针对微信相关接口进行进一步封装,可以直接使用。
版本号 | 版本介绍 |
---|---|
v0.0.1 | 仅支持签名和获取头部参数Authorization |
v1.0.0 | 增加了支付(不包括合单支付)、查询订单、关闭订单、申请交易账单、申请资金账单、下载账单 |
v1.2.0 | 增加了回调解密,合单支付、合单关闭、合单查询 |
v1.2.1 | 修改app、jsapi、native支付字段scene_info 改为可选 |
v1.2.2 | 增加获取序列号方法 |
v1.2.3 | 修改小程序支付签名错误和取消serial_no字段必填 |
v1.3.0 | 增加普通订单的退款和查询 |
v1.3.1 | 修复APP调起支付时出现“支付验证签名失败“的问题 |
v1.3.2 | 增加请求成功后的签名验证 |
v1.3.3 | 修复superagent post请求异常 Z_DATA_ERROR |
v1.3.4 | 修复superagent get请求异常 Z_DATA_ERROR |
v1.3.5 | 修复APP支付签名错误 |
v2.0.0 | 增加提现到零钱和优化接口参数,规定返回参数格式,其他接口会后续优化 |
v2.0.1 | 增加请求头Wechatpay-Serial和完善转账其他接口 |
v2.0.2 | 增加敏感信息加密方法(publicEncrypt) |
v2.0.3 | 修复get请求无参时的签名 |
v2.0.4 | 修复敏感信息加密方法(publicEncrypt)使用微信平台公钥 |
v2.0.6 | 修复发起商家转账零钱参数wx_serial_no(自定义参数,即http请求头Wechatpay-Serial的值)为可选参数 |
v2.1.0 | 升级superagent依赖6.1.0到8.0.6 |
v2.1.1 | 商家转账API支持场景参数 |
v2.1.2 | 基础支付接口支持传appid |
v2.1.3 | 支持分账相关接口 |
v2.1.4 | 修复错误原因存在空值bug |
v2.1.5 | 修复动态 appid 签名错误 |
v2.1.6 | Native下单API支持support_fapiao字段 |
欢迎提存在的Bug或者意见。
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More