wxpay-nodejs-sdk 0.2.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 +46 -95
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -1,27 +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
- > **⚠️ 免责声明:本项目为社区开源项目,非微信支付官方 SDK。使用本 SDK 产生的任何问题,本项目不承担任何责任。请以[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012081606.md)为准。**
6
-
7
- ## 官方文档
8
-
9
- - [微信支付商户平台文档中心](https://pay.weixin.qq.com/doc/v3/merchant/llms.txt)
10
- - [APIv3 概述](https://pay.weixin.qq.com/doc/v3/merchant/4012081606.md)
11
- - [签名认证](https://pay.weixin.qq.com/doc/v3/merchant/4012365342.md)
12
- - [微信支付公钥](https://pay.weixin.qq.com/doc/v3/merchant/4012153196.md)
13
- - [平台证书](https://pay.weixin.qq.com/doc/v3/merchant/4012068814.md)
14
-
15
- ## 特性
16
-
17
- - 🚀 **完整的 TypeScript 支持** — 类型定义完善,开发体验友好
18
- - 🔐 **安全可靠** — 内置签名验证、回调通知验签与解密
19
- - 📦 **开箱即用** — 封装所有常用微信支付 API
20
- - 🎯 **统一的接口风格** — 每个 Service 对应一类业务,易于使用
21
-
22
- ## 环境要求
23
-
24
- - Node.js >= 18.0.0
5
+ > **免责声明:本项目为社区开源项目,非微信支付官方 SDK。使用前请阅读 [微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)。**
25
6
 
26
7
  ## 安装
27
8
 
@@ -29,13 +10,14 @@
29
10
  npm install wxpay-nodejs-sdk
30
11
  ```
31
12
 
13
+ 要求 Node.js >= 18.0.0。
14
+
32
15
  ## 快速开始
33
16
 
34
17
  ```typescript
35
- import { WxPayClient, JsapiService } from 'wxpay-nodejs-sdk';
18
+ import { WxPayClient, JsapiService, buildJsapiBridgeConfig } from 'wxpay-nodejs-sdk';
36
19
  import fs from 'node:fs';
37
20
 
38
- // 1. 初始化客户端
39
21
  const client = new WxPayClient({
40
22
  mchid: '1900000100',
41
23
  apiV3Key: 'your-api-v3-key',
@@ -43,106 +25,75 @@ const client = new WxPayClient({
43
25
  privateKey: fs.readFileSync('/path/to/apiclient_key.pem'),
44
26
  });
45
27
 
46
- // 2. 创建 JSAPI 支付订单
47
28
  const jsapi = new JsapiService(client);
48
- const order = await jsapi.createOrder({
29
+
30
+ // 下单
31
+ const { data } = await jsapi.createOrder({
49
32
  appid: 'wx1234567890abcdef',
50
33
  mchid: '1900000100',
51
34
  description: '商品描述',
52
35
  out_trade_no: '订单号',
53
- amount: { total: 100, currency: 'CNY' },
36
+ amount: { total: 100 },
54
37
  payer: { openid: '用户openid' },
55
38
  notify_url: 'https://example.com/callback',
56
39
  });
57
40
 
58
- console.log(order.data.prepay_id); // 用于前端调起支付
41
+ // 生成前端调起支付参数
42
+ const config = buildJsapiBridgeConfig('wx1234567890abcdef', data.prepay_id, privateKey);
59
43
  ```
60
44
 
61
- ## 支持的 API
62
-
63
- | Service | 说明 |
64
- | ------------------------- | -------------------------------------- |
65
- | `JsapiService` | JSAPI 支付 / 小程序支付 |
66
- | `AppService` | APP 支付 |
67
- | `H5Service` | H5 支付 |
68
- | `NativeService` | Native 支付 |
69
- | `CombineService` | 合单支付(JSAPI/H5/APP/Native/小程序) |
70
- | `ProfitSharingService` | 分账 |
71
- | `PayScoreService` | 微信支付分 |
72
- | `ParkingService` | 微信支付分停车服务 |
73
- | `BillService` | 账单下载 |
74
- | `MerchantTransferService` | 商家转账 |
75
- | `CouponService` | 代金券 |
76
- | `ComplaintService` | 消费者投诉 |
77
- | `PartnershipService` | 委托营销 |
78
- | `SmartGuideService` | 智慧导购 |
79
- | `BusinessCircleService` | 商圈服务 |
80
- | `PayGiftActivityService` | 支付有礼 |
81
- | `MedInsService` | 医保服务 |
82
- | `MediaService` | 文件上传 |
83
- | `SecurityService` | 安全服务 |
84
- | `CallbackHandler` | 回调通知验签与解密 |
85
-
86
- ## 回调通知处理
45
+ ## 回调通知
87
46
 
88
47
  ```typescript
89
48
  import { CallbackHandler } from 'wxpay-nodejs-sdk';
90
49
 
91
50
  const handler = new CallbackHandler(apiV3Key, wxpay.certificates);
92
-
93
- // 支付成功通知
94
- const payment = handler.processTransactionCallback(headers, body);
95
-
96
- // 退款通知
97
- const refund = handler.processRefundCallback(headers, body);
98
-
99
- // 分账通知
100
- const profitSharing = handler.processProfitSharingCallback(headers, body);
51
+ const callback = handler.processTransactionCallback(headers, rawBody);
52
+ console.log(callback.data.out_trade_no, callback.data.trade_state);
101
53
  ```
102
54
 
103
- ## 错误处理
55
+ ## 支持的 API
104
56
 
105
- ```typescript
106
- import { WxPayError } from 'wxpay-nodejs-sdk';
107
-
108
- try {
109
- const order = await jsapi.createOrder({ ... });
110
- } catch (error) {
111
- if (error instanceof WxPayError) {
112
- console.error(`[${error.detail.code}] ${error.detail.message}`);
113
- console.error(`HTTP ${error.status}`);
114
- }
115
- }
116
- ```
57
+ | Service | 说明 |
58
+ |---------|------|
59
+ | `JsapiService` | JSAPI 支付 / 小程序支付 |
60
+ | `AppService` | APP 支付 |
61
+ | `H5Service` | H5 支付 |
62
+ | `NativeService` | Native 支付 |
63
+ | `CombineService` / `CombineH5Service` / `CombineAppService` / `CombineNativeService` / `CombineMiniProgramService` | 合单支付 |
64
+ | `ProfitSharingService` | 分账 |
65
+ | `PayScoreService` | 微信支付分 |
66
+ | `ParkingService` | 停车服务 |
67
+ | `BillService` | 账单下载 |
68
+ | `MerchantTransferService` | 商家转账 |
69
+ | `CouponService` | 代金券 |
70
+ | `ComplaintService` | 消费者投诉 |
71
+ | `PartnershipService` | 委托营销 |
72
+ | `SmartGuideService` | 智慧导购 |
73
+ | `BusinessCircleService` | 商圈服务 |
74
+ | `PayGiftActivityService` | 支付有礼 |
75
+ | `MedInsService` | 医保服务 |
76
+ | `MediaService` | 文件上传 |
77
+ | `SecurityService` | 安全服务 |
78
+ | `CallbackHandler` | 回调通知验签与解密 |
79
+
80
+ > 各 Service 的方法和参数请参考 [微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524),本 SDK 的方法名与官方 API 路径一一对应。
117
81
 
118
82
  ## 文档
119
83
 
120
- - [快速入门](docs/quickstart.md) — 详细的接入指南
121
- - [API 参考](docs/api-reference.md) — 完整的接口文档
122
- - [使用示例](docs/example.md) — 各类场景的代码示例
123
- - [回调通知](docs/callback.md) — 回调处理详解
124
- - [支付流程](docs/flow.md) — 支付流程说明
125
- - [常见问题](docs/faq.md) — FAQ
84
+ - [快速入门](docs/quickstart.md)
85
+ - [使用示例](docs/example.md)
86
+ - [回调通知](docs/callback.md)
87
+ - **[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)**
126
88
 
127
89
  ## 免责声明
128
90
 
129
91
  1. 本项目为**社区开源项目**,由开发者个人维护,**非微信支付官方 SDK**。
130
92
  2. 本项目仅提供对微信支付 API 的封装,不保证接口的完整性、准确性和时效性。
131
- 3. 使用本 SDK 前,请务必仔细阅读并遵守[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012081606.md)中的相关规则和要求。
132
- 4. 因使用本 SDK 产生的任何直接或间接损失(包括但不限于资金损失、业务中断等),本项目及作者不承担任何责任。
133
- 5. 本项目不对微信支付 API 的变更、下线或其他调整做任何保证,开发者应及时关注官方文档更新。
134
- 6. 在生产环境使用前,请务必进行充分的测试验证。
135
-
136
- 如有疑问,请优先查阅[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012081606.md)或联系微信支付技术支持。
93
+ 3. 使用本 SDK 前,请务必阅读并遵守[微信支付官方文档](https://pay.weixin.qq.com/doc/v3/merchant/4012062524)中的规则和要求。
94
+ 4. 因使用本 SDK 产生的任何损失,本项目及作者不承担任何责任。
95
+ 5. 在生产环境使用前,请务必进行充分的测试验证。
137
96
 
138
97
  ## 许可证
139
98
 
140
99
  MIT
141
-
142
- ---
143
-
144
- **微信支付官方资源**
145
-
146
- - [微信支付商户平台](https://pay.weixin.qq.com/)
147
- - [微信支付开发者文档](https://pay.weixin.qq.com/doc/v3/merchant/4012081606.md)
148
- - [微信支付 APIv3 SDK(官方)](https://github.com/wechatpay-apiv3)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wxpay-nodejs-sdk",
3
- "version": "0.2.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",
@@ -38,7 +38,9 @@
38
38
  "release:major": "standard-version --release-as major",
39
39
  "release:patch": "standard-version --release-as patch",
40
40
  "release:dry": "standard-version --dry-run",
41
- "publish:npm": "standard-version --release-as minor && npm run build && npm publish --registry https://registry.npmjs.org/",
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/",
42
44
  "publish:beta": "standard-version --prerelease beta && npm run build && npm publish --tag beta --registry https://registry.npmjs.org/"
43
45
  },
44
46
  "lint-staged": {