wxpay-nodejs-sdk 0.1.0 → 0.2.1-beta.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.
Files changed (2) hide show
  1. package/README.md +36 -55
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -1,17 +1,8 @@
1
1
  # wxpay-nodejs-sdk
2
2
 
3
- 微信支付 API V3 Node.js SDK,提供类型安全的支付接口封装,支持所有常用支付和分账接口。
3
+ 微信支付 API V3 Node.js SDK,基于 TypeScript,提供类型安全的支付接口封装。
4
4
 
5
- ## 特性
6
-
7
- - 🚀 **完整的 TypeScript 支持** — 类型定义完善,开发体验友好
8
- - 🔐 **安全可靠** — 内置签名验证、回调通知验签与解密
9
- - 📦 **开箱即用** — 封装所有常用微信支付 API
10
- - 🎯 **统一的接口风格** — 每个 Service 对应一类业务,易于使用
11
-
12
- ## 环境要求
13
-
14
- - Node.js >= 18.0.0
5
+ > **免责声明:本项目为社区开源项目,非微信支付官方 SDK。使用前请阅读 [微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)。**
15
6
 
16
7
  ## 安装
17
8
 
@@ -19,13 +10,14 @@
19
10
  npm install wxpay-nodejs-sdk
20
11
  ```
21
12
 
13
+ 要求 Node.js >= 18.0.0。
14
+
22
15
  ## 快速开始
23
16
 
24
17
  ```typescript
25
- import { WxPayClient, JsapiService } from 'wxpay-nodejs-sdk';
18
+ import { WxPayClient, JsapiService, buildJsapiBridgeConfig } from 'wxpay-nodejs-sdk';
26
19
  import fs from 'node:fs';
27
20
 
28
- // 1. 初始化客户端
29
21
  const client = new WxPayClient({
30
22
  mchid: '1900000100',
31
23
  apiV3Key: 'your-api-v3-key',
@@ -33,18 +25,31 @@ const client = new WxPayClient({
33
25
  privateKey: fs.readFileSync('/path/to/apiclient_key.pem'),
34
26
  });
35
27
 
36
- // 2. 创建 JSAPI 支付订单
37
28
  const jsapi = new JsapiService(client);
38
- const order = await jsapi.createOrder({
29
+
30
+ // 下单
31
+ const { data } = await jsapi.createOrder({
39
32
  appid: 'wx1234567890abcdef',
33
+ mchid: '1900000100',
40
34
  description: '商品描述',
41
35
  out_trade_no: '订单号',
42
- amount: { total: 100, currency: 'CNY' },
36
+ amount: { total: 100 },
43
37
  payer: { openid: '用户openid' },
44
38
  notify_url: 'https://example.com/callback',
45
39
  });
46
40
 
47
- console.log(order.data.prepay_id); // 用于前端调起支付
41
+ // 生成前端调起支付参数
42
+ const config = buildJsapiBridgeConfig('wx1234567890abcdef', data.prepay_id, privateKey);
43
+ ```
44
+
45
+ ## 回调通知
46
+
47
+ ```typescript
48
+ import { CallbackHandler } from 'wxpay-nodejs-sdk';
49
+
50
+ const handler = new CallbackHandler(apiV3Key, wxpay.certificates);
51
+ const callback = handler.processTransactionCallback(headers, rawBody);
52
+ console.log(callback.data.out_trade_no, callback.data.trade_state);
48
53
  ```
49
54
 
50
55
  ## 支持的 API
@@ -55,10 +60,10 @@ console.log(order.data.prepay_id); // 用于前端调起支付
55
60
  | `AppService` | APP 支付 |
56
61
  | `H5Service` | H5 支付 |
57
62
  | `NativeService` | Native 支付 |
58
- | `CombineService` | 合单支付(JSAPI/H5/APP/Native/小程序) |
63
+ | `CombineService` / `CombineH5Service` / `CombineAppService` / `CombineNativeService` / `CombineMiniProgramService` | 合单支付 |
59
64
  | `ProfitSharingService` | 分账 |
60
65
  | `PayScoreService` | 微信支付分 |
61
- | `ParkingService` | 微信支付分停车服务 |
66
+ | `ParkingService` | 停车服务 |
62
67
  | `BillService` | 账单下载 |
63
68
  | `MerchantTransferService` | 商家转账 |
64
69
  | `CouponService` | 代金券 |
@@ -72,46 +77,22 @@ console.log(order.data.prepay_id); // 用于前端调起支付
72
77
  | `SecurityService` | 安全服务 |
73
78
  | `CallbackHandler` | 回调通知验签与解密 |
74
79
 
75
- ## 回调通知处理
80
+ > 各 Service 的方法和参数请参考 [微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524),本 SDK 的方法名与官方 API 路径一一对应。
76
81
 
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
- ## 错误处理
82
+ ## 文档
93
83
 
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
- ```
84
+ - [快速入门](docs/quickstart.md)
85
+ - [使用示例](docs/example.md)
86
+ - [回调通知](docs/callback.md)
87
+ - **[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)**
106
88
 
107
- ## 文档
89
+ ## 免责声明
108
90
 
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
91
+ 1. 本项目为**社区开源项目**,由开发者个人维护,**非微信支付官方 SDK**。
92
+ 2. 本项目仅提供对微信支付 API 的封装,不保证接口的完整性、准确性和时效性。
93
+ 3. 使用本 SDK 前,请务必阅读并遵守[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)中的规则和要求。
94
+ 4. 因使用本 SDK 产生的任何损失,本项目及作者不承担任何责任。
95
+ 5. 在生产环境使用前,请务必进行充分的测试验证。
115
96
 
116
97
  ## 许可证
117
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wxpay-nodejs-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.1-beta.0",
4
4
  "description": "微信支付 API V3 Node.js SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -37,7 +37,11 @@
37
37
  "release:minor": "standard-version --release-as minor",
38
38
  "release:major": "standard-version --release-as major",
39
39
  "release:patch": "standard-version --release-as patch",
40
- "release:dry": "standard-version --dry-run"
40
+ "release:dry": "standard-version --dry-run",
41
+ "publish:patch": "standard-version --release-as patch && npm run build && npm publish --registry https://registry.npmjs.org/",
42
+ "publish:minor": "standard-version --release-as minor && npm run build && npm publish --registry https://registry.npmjs.org/",
43
+ "publish:major": "standard-version --release-as major && npm run build && npm publish --registry https://registry.npmjs.org/",
44
+ "publish:beta": "standard-version --prerelease beta && npm run build && npm publish --tag beta --registry https://registry.npmjs.org/"
41
45
  },
42
46
  "lint-staged": {
43
47
  "*.ts": [