wxpay-nodejs-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/index.d.mts +7874 -0
- package/dist/index.d.ts +7874 -0
- package/dist/index.js +4248 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4186 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xiang Bo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# wxpay-nodejs-sdk
|
|
2
|
+
|
|
3
|
+
微信支付 API V3 Node.js SDK,提供类型安全的支付接口封装,支持所有常用支付和分账接口。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 **完整的 TypeScript 支持** — 类型定义完善,开发体验友好
|
|
8
|
+
- 🔐 **安全可靠** — 内置签名验证、回调通知验签与解密
|
|
9
|
+
- 📦 **开箱即用** — 封装所有常用微信支付 API
|
|
10
|
+
- 🎯 **统一的接口风格** — 每个 Service 对应一类业务,易于使用
|
|
11
|
+
|
|
12
|
+
## 环境要求
|
|
13
|
+
|
|
14
|
+
- Node.js >= 18.0.0
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install wxpay-nodejs-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { WxPayClient, JsapiService } from 'wxpay-nodejs-sdk';
|
|
26
|
+
import fs from 'node:fs';
|
|
27
|
+
|
|
28
|
+
// 1. 初始化客户端
|
|
29
|
+
const client = new WxPayClient({
|
|
30
|
+
mchid: '1900000100',
|
|
31
|
+
apiV3Key: 'your-api-v3-key',
|
|
32
|
+
serialNo: 'your-certificate-serial-number',
|
|
33
|
+
privateKey: fs.readFileSync('/path/to/apiclient_key.pem'),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2. 创建 JSAPI 支付订单
|
|
37
|
+
const jsapi = new JsapiService(client);
|
|
38
|
+
const order = await jsapi.createOrder({
|
|
39
|
+
appid: 'wx1234567890abcdef',
|
|
40
|
+
description: '商品描述',
|
|
41
|
+
out_trade_no: '订单号',
|
|
42
|
+
amount: { total: 100, currency: 'CNY' },
|
|
43
|
+
payer: { openid: '用户openid' },
|
|
44
|
+
notify_url: 'https://example.com/callback',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
console.log(order.data.prepay_id); // 用于前端调起支付
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 支持的 API
|
|
51
|
+
|
|
52
|
+
| Service | 说明 |
|
|
53
|
+
|---------|------|
|
|
54
|
+
| `JsapiService` | JSAPI 支付 / 小程序支付 |
|
|
55
|
+
| `AppService` | APP 支付 |
|
|
56
|
+
| `H5Service` | H5 支付 |
|
|
57
|
+
| `NativeService` | Native 支付 |
|
|
58
|
+
| `CombineService` | 合单支付(JSAPI/H5/APP/Native/小程序) |
|
|
59
|
+
| `ProfitSharingService` | 分账 |
|
|
60
|
+
| `PayScoreService` | 微信支付分 |
|
|
61
|
+
| `ParkingService` | 微信支付分停车服务 |
|
|
62
|
+
| `BillService` | 账单下载 |
|
|
63
|
+
| `MerchantTransferService` | 商家转账 |
|
|
64
|
+
| `CouponService` | 代金券 |
|
|
65
|
+
| `ComplaintService` | 消费者投诉 |
|
|
66
|
+
| `PartnershipService` | 委托营销 |
|
|
67
|
+
| `SmartGuideService` | 智慧导购 |
|
|
68
|
+
| `BusinessCircleService` | 商圈服务 |
|
|
69
|
+
| `PayGiftActivityService` | 支付有礼 |
|
|
70
|
+
| `MedInsService` | 医保服务 |
|
|
71
|
+
| `MediaService` | 文件上传 |
|
|
72
|
+
| `SecurityService` | 安全服务 |
|
|
73
|
+
| `CallbackHandler` | 回调通知验签与解密 |
|
|
74
|
+
|
|
75
|
+
## 回调通知处理
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { CallbackHandler } from 'wxpay-nodejs-sdk';
|
|
79
|
+
|
|
80
|
+
const handler = new CallbackHandler(apiV3Key, wxpay.certificates);
|
|
81
|
+
|
|
82
|
+
// 支付成功通知
|
|
83
|
+
const payment = handler.processTransactionCallback(headers, body);
|
|
84
|
+
|
|
85
|
+
// 退款通知
|
|
86
|
+
const refund = handler.processRefundCallback(headers, body);
|
|
87
|
+
|
|
88
|
+
// 分账通知
|
|
89
|
+
const profitSharing = handler.processProfitSharingCallback(headers, body);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 错误处理
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { WxPayError } from 'wxpay-nodejs-sdk';
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const order = await jsapi.createOrder({ ... });
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof WxPayError) {
|
|
101
|
+
console.error(`[${error.detail.code}] ${error.detail.message}`);
|
|
102
|
+
console.error(`HTTP ${error.status}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 文档
|
|
108
|
+
|
|
109
|
+
- [快速入门](docs/quickstart.md) — 详细的接入指南
|
|
110
|
+
- [API 参考](docs/api-reference.md) — 完整的接口文档
|
|
111
|
+
- [使用示例](docs/example.md) — 各类场景的代码示例
|
|
112
|
+
- [回调通知](docs/callback.md) — 回调处理详解
|
|
113
|
+
- [支付流程](docs/flow.md) — 支付流程说明
|
|
114
|
+
- [常见问题](docs/faq.md) — FAQ
|
|
115
|
+
|
|
116
|
+
## 许可证
|
|
117
|
+
|
|
118
|
+
MIT
|