Gathering detailed insights and metrics for @bared/wechatpay-node-v3
Gathering detailed insights and metrics for @bared/wechatpay-node-v3
Gathering detailed insights and metrics for @bared/wechatpay-node-v3
Gathering detailed insights and metrics for @bared/wechatpay-node-v3
npm install @bared/wechatpay-node-v3
Typescript
Module System
Node Version
NPM Version
TypeScript (98.72%)
JavaScript (1.28%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
717 Stars
83 Commits
119 Forks
1 Watchers
1 Branches
8 Contributors
Updated on Jul 10, 2025
Latest Version
1.3.7
Package Id
@bared/wechatpay-node-v3@1.3.7
Unpacked Size
64.33 kB
Size
11.70 kB
File Count
8
NPM Version
9.2.0
Node Version
18.12.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
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 }
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 |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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-07-07
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