Gathering detailed insights and metrics for ape-node-wechatpay-v3
Gathering detailed insights and metrics for ape-node-wechatpay-v3
Gathering detailed insights and metrics for ape-node-wechatpay-v3
Gathering detailed insights and metrics for ape-node-wechatpay-v3
npm install ape-node-wechatpay-v3
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
18 Stars
27 Commits
2 Forks
1 Watchers
1 Branches
1 Contributors
Updated on May 23, 2025
Latest Version
1.0.31
Package Id
ape-node-wechatpay-v3@1.0.31
Unpacked Size
26.91 kB
Size
6.39 kB
File Count
6
NPM Version
9.5.1
Node Version
16.20.0
Published on
Dec 20, 2023
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
1
1npm i ape-node-wechatpay-v3 --save
创建实例
1const apeWeChatPay = require("ape-node-wechatpay-v3"); 2const fs = require("fs"); 3 4const weChatPay = new apeWeChatPay({ 5 appid: "xxxxxxxxxx", 6 mchid: "xxxxxxxxxx", 7 serial_no: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 8 authType: "WECHATPAY2-SHA256-RSA2048", 9 apiclientCert: fs.readFileSync("xxx/certificate/apiclient_cert.pem"), 10 apiclientkey: fs.readFileSync("xxx/certificate/apiclient_key.pem"), 11 certPath: "xxx/certificate", 12 APIv3: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 13});
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
appid | 公众号(移动应用 / 小程序)的 appid | 否 |
mchid | 商户号 | 是 |
serial_no | 证书序列号 | 是 |
authType | 请求头签名认证类型,不传则默认为 WECHATPAY2-SHA256-RSA2048 | 否 |
apiclientCert | 公钥 | 是 |
apiclientkey | 密钥 | 是 |
certPath | 微信支付平台证书下载路径(需要回调解密以及验证签名则必填)【包含 wechatpay.pem 和 wechatpaySerial.txt 俩个文件】,建议与公钥密钥在一个文件夹内 | 否 |
APIv3 | 商户后台配置的 APIv3 密钥(需要回调解密以及验证签名则必填) | 否 |
userAgent | 微信支付平台证书下载接口请求头 user-agent(默认为 node Serve) | 否 |
注意:serial_no 是证书序列号,请在商户后台查看。
示例代码
1let signature = weChatPay.getSignature(method, url, timestamp, nonce_str, body);
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
method | 支付接口方法 | 是 |
url | 支付接口地址 | 是 |
timestamp | 时间戳 | 是 |
nonce_str | 请求随机串 | 是 |
body | 请求体(接口需要传则给,反之给空字符串,如"") | 否 |
示例代码
1let authorization = weChatPay.getAuthorization(nonce_str, timestamp, signature);
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
nonce_str | 请求随机串(需要与获取签名值的一致) | 是 |
timestamp | 时间戳 | 是 |
signature | 签名值 | 是 |
示例代码
1let paySign = this.getJsapiSignature(appid, timeStamp, nonceStr, package);
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
appid | 应用 ID | 是 |
timeStamp | 时间戳 | 是 |
nonceStr | 随机字符串 | 是 |
package | 订单详情扩展字符串 | 是 |
会生成 wechatpay.pem 和 wechatpaySerial.txt 俩个文件,每次更新会覆盖旧的。
微信官方建议在十二小时内更新,可以写定时任务
示例代码
1let result = {}; 2try { 3 result = await weChatPay.getWeChatPayCert(); 4} catch (error) { 5 console.log(error); 6} 7console.log(result); 8// { code: 200, msg: '下载证书成功' }
!!!使用此方法必须在构造实体类时传递 certPath 、 APIv3 这俩个参数 !!!
文件说明
文件名称 | 说明 |
---|---|
wechatpay.pem | 下载平台证书接口解密出来公钥(回调签名验证需要) |
wechatpaySerial.txt | 下载平台证书接口的公钥序列号(回调签名验证需要) |
返回说明(为了方便开发者做对应的处理)
code | data | msg |
---|---|---|
200 | 下载成功 | 解释说明 |
500 / 其他(在 catch 里返回) | 下载失败(错误信息),详细请看 msg | 解释说明 |
示例代码
1let Body = req.body; // 微信请求你的回调接口的实体类 body 2let Headers = req.headers; // 微信请求你的回调接口的 headers 3let result = null; 4try { 5 result = await weChatPay.verifySignature( 6 Headers["wechatpay-signature"], // 应答签名 7 Headers["wechatpay-serial"], // 平台证书序列号 8 Headers["wechatpay-timestamp"], // 生成签名的时间戳 9 Headers["wechatpay-nonce"], // 应答随机串 10 req.body 11 ); 12} catch (error) { 13 console.log(error); 14} 15console.log(result); 16// { code: 200, msg: '验签名串和签名验证通过' }
!!!使用此方法必须在构造实体类时传递 certPath 、 APIv3 这俩个参数 !!!
返回说明(为了方便开发者做对应的处理)
code | data | msg |
---|---|---|
200 | 验证通过 | 解释说明 |
500 / 其他(在 catch 里返回) | 验证失败(错误信息),详细请看 msg | 解释说明 |
建议在签名验证成功后解密
示例代码
1let Body = req.body; // 微信请求你的回调接口的实体类 body 2let Headers = req.headers; // 微信请求你的回调接口的 headers 3let data = null; 4try { 5 data = await weChatPay.decrypting( 6 Body.resource.ciphertext, // 结果数据密文 7 Body.resource.nonce, // 加密使用的随机串 8 Body.resource.associated_data // 附加数据 9 ); 10} catch (error) { 11 console.log(error); 12} 13console.log(data); 14// { code: 200, data: xxxx(解密的数据), msg: '解密成功' }
!!!使用此方法必须在构造实体类时传递 certPath 、 APIv3 这俩个参数 !!!
返回说明(为了方便开发者做对应的处理)
code | data | msg |
---|---|---|
200 | 解密出来的数据 | 解释说明 |
500 / 其他(在 catch 里返回) | 解密失败(错误信息),详细请看 msg | 解释说明 |
示例代码
1let data = { 2 appid: "xxxxxx", 3 mchid: "xxxxxx", 4 description: "测试", 5 out_trade_no: "xxxxxx", 6 notify_url: "xxxxxx", 7 amount: { 8 total: 1, 9 }, 10 payer: { 11 openid: "xxxxxx", 12 }, 13}; 14let result; 15try { 16 result = await weChatPay.jsapiPay(data); 17} catch (error) { 18 console.log(error); 19} 20console.log(result); 21// 正常返回如下示例(data中包含jsapi支付客户端(小程序或者网页)所需要的全部参数) 22// { 23// code: 200, 24// data: { 25// appid: 'xxxxxx', 26// timeStamp: 'xxxxxx', 27// nonceStr: 'xxxxxx', 28// package: 'prepay_id=xxxxxx', 29// signType: 'RSA', 30// paySign: 'xxxxxx' 31// }, 32// msg: 'success' 33// }
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
data | jsapi 下单的 body 参数 | 是 |
示例代码
1let data = { 2 appid: "xxxxxx", 3 mchid: "xxxxxx", 4 description: "测试", 5 out_trade_no: "xxxxxx", 6 notify_url: "xxxxxx", 7 amount: { 8 total: 1, 9 }, 10}; 11let result; 12try { 13 result = await weChatPay.nativePay(data); 14} catch (error) { 15 console.log(error); 16} 17console.log(result); 18// 正常返回如下示例 19// { 20// "code": 200, 21// "code_url": "xxxxxxxxxx" 22// }
参数说明
参数名称 | 参数介绍 | 是否必须 |
---|---|---|
data | native 下单的 body 参数 | 是 |
版本号 | 版本介绍 |
---|---|
1.0.0 | 仅支持获取签名和获取头部参数 Authorization |
1.0.1 | 在 1.0.0 的基础上增加了说明文档 |
1.0.2 | 增加了 native 支付下单函数的封装 |
1.0.21 | 增加了 jsapi 支付下单函数的封装 |
1.0.3 | 增加了微信支付平台证书下载方法、支付回调签名验证的方法、 证书(回调)解密方法的封装 |
No vulnerabilities found.
No security vulnerabilities found.