wxpay-nodejs-sdk 0.2.1 → 0.2.2

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/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
- import crypto4 from 'crypto';
2
+ import os from 'os';
3
+ import crypto2 from 'crypto';
3
4
 
4
5
  // src/core/client.ts
5
6
  var CertificateManager = class {
@@ -11,6 +12,8 @@ var CertificateManager = class {
11
12
  wxpayPublicKeyId = null;
12
13
  /** API V3 密钥 */
13
14
  apiV3Key;
15
+ /** 自动更新定时器 */
16
+ autoUpdateTimer = null;
14
17
  constructor(apiV3Key, certificates) {
15
18
  this.apiV3Key = apiV3Key;
16
19
  if (certificates) {
@@ -25,6 +28,21 @@ var CertificateManager = class {
25
28
  get serialNos() {
26
29
  return Array.from(this.certificates.keys());
27
30
  }
31
+ /**
32
+ * 获取最新的证书序列号或公钥ID
33
+ *
34
+ * 优先返回微信支付公钥ID(公钥模式),否则返回第一个平台证书序列号。
35
+ * 用于设置请求头 Wechatpay-Serial,告知微信支付客户端支持验签的证书。
36
+ *
37
+ * @returns 序列号字符串,无配置时返回 undefined
38
+ */
39
+ getNewestSerial() {
40
+ if (this.wxpayPublicKeyId) {
41
+ return this.wxpayPublicKeyId;
42
+ }
43
+ const keys = Array.from(this.certificates.keys());
44
+ return keys.length > 0 ? keys[0] : void 0;
45
+ }
28
46
  /**
29
47
  * 设置微信支付公钥(公钥模式)
30
48
  *
@@ -57,7 +75,7 @@ var CertificateManager = class {
57
75
  return Buffer.from(ciphertext, "base64").toString("utf-8");
58
76
  }
59
77
  try {
60
- const decipher = crypto4.createDecipheriv(
78
+ const decipher = crypto2.createDecipheriv(
61
79
  "aes-256-gcm",
62
80
  Buffer.from(this.apiV3Key, "utf-8"),
63
81
  Buffer.from(nonce, "utf-8")
@@ -108,9 +126,68 @@ var CertificateManager = class {
108
126
  this.wxpayPublicKey = null;
109
127
  this.wxpayPublicKeyId = null;
110
128
  }
129
+ /**
130
+ * 启动自动更新
131
+ *
132
+ * 定期调用更新函数刷新平台证书。适用于生产环境的证书自动维护。
133
+ *
134
+ * @param updateFn - 证书更新函数,返回最新的证书 Map
135
+ * @param options - 自动更新配置选项
136
+ * @returns 停止更新的函数
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * const manager = new CertificateManager(apiV3Key);
141
+ * const stop = manager.startAutoUpdate(
142
+ * async () => {
143
+ * const certs = await downloadCertificates();
144
+ * return certs;
145
+ * },
146
+ * { intervalMs: 60 * 60 * 1000 }
147
+ * );
148
+ * // 稍后停止
149
+ * stop();
150
+ * ```
151
+ */
152
+ startAutoUpdate(updateFn, options) {
153
+ const intervalMs = options?.intervalMs ?? 60 * 60 * 1e3;
154
+ this.stopAutoUpdate();
155
+ const doUpdate = async () => {
156
+ try {
157
+ const certs = await updateFn();
158
+ for (const [serialNo, publicKey] of certs) {
159
+ this.setPublicKey(serialNo, publicKey);
160
+ }
161
+ options?.onSuccess?.(Array.from(certs.keys()));
162
+ } catch (error) {
163
+ options?.onError?.(error instanceof Error ? error : new Error(String(error)));
164
+ }
165
+ };
166
+ void doUpdate();
167
+ this.autoUpdateTimer = setInterval(() => {
168
+ void doUpdate();
169
+ }, intervalMs);
170
+ return () => {
171
+ this.stopAutoUpdate();
172
+ };
173
+ }
174
+ /**
175
+ * 停止自动更新
176
+ */
177
+ stopAutoUpdate() {
178
+ if (this.autoUpdateTimer) {
179
+ clearInterval(this.autoUpdateTimer);
180
+ this.autoUpdateTimer = null;
181
+ }
182
+ }
111
183
  };
112
-
113
- // src/utils/http.ts
184
+ var SDK_VERSION = "0.2.1";
185
+ function getUserAgent() {
186
+ const platform = os.platform();
187
+ const arch = os.arch();
188
+ const nodeVersion = process.version;
189
+ return `wxpay-nodejs-sdk/${SDK_VERSION} (${platform} ${arch}) Node.js/${nodeVersion}`;
190
+ }
114
191
  var WxPayError = class extends Error {
115
192
  /** HTTP 状态码 */
116
193
  status;
@@ -163,13 +240,16 @@ function parseResponseHeaders(headers) {
163
240
  return result;
164
241
  }
165
242
  function createRequestHeaders(options) {
166
- return {
243
+ const headers = {
167
244
  Authorization: options.authorization,
168
245
  Accept: options.accept ?? "application/json",
169
246
  "Content-Type": options.contentType ?? "application/json",
170
- "User-Agent": "wxpay-nodejs-sdk/0.1.0",
171
- ...options.additional
247
+ "User-Agent": getUserAgent()
172
248
  };
249
+ if (options.wechatPaySerial) {
250
+ headers["Wechatpay-Serial"] = options.wechatPaySerial;
251
+ }
252
+ return { ...headers, ...options.additional };
173
253
  }
174
254
  async function parseResponse(response, verify) {
175
255
  const headers = parseResponseHeaders(response.headers);
@@ -238,7 +318,7 @@ ${body}
238
318
  `;
239
319
  }
240
320
  function sign(signString, privateKey) {
241
- const signer = crypto4.createSign("RSA-SHA256");
321
+ const signer = crypto2.createSign("RSA-SHA256");
242
322
  signer.update(signString);
243
323
  signer.end();
244
324
  return signer.sign(privateKey, "base64");
@@ -247,36 +327,68 @@ function buildAuthorization(mchid, serialNo, timestamp, nonce, signature) {
247
327
  return `WECHATPAY2-SHA256-RSA2048 mchid="${mchid}",nonce_str="${nonce}",timestamp="${timestamp}",serial_no="${serialNo}",signature="${signature}"`;
248
328
  }
249
329
  function generateNonce() {
250
- return crypto4.randomUUID().replace(/-/g, "");
330
+ return crypto2.randomUUID().replace(/-/g, "");
331
+ }
332
+ var RESPONSE_EXPIRED_SECONDS = 5 * 60;
333
+ function isTimestampValid(timestamp) {
334
+ const responseTime = parseInt(timestamp, 10);
335
+ if (isNaN(responseTime)) return false;
336
+ const now = Math.floor(Date.now() / 1e3);
337
+ return Math.abs(now - responseTime) < RESPONSE_EXPIRED_SECONDS;
251
338
  }
252
339
  function verifySignature(body, signature, timestamp, nonce, publicKey) {
340
+ if (!isTimestampValid(timestamp)) {
341
+ return false;
342
+ }
253
343
  const signString = `${timestamp}
254
344
  ${nonce}
255
345
  ${body}
256
346
  `;
257
- const verifier = crypto4.createVerify("RSA-SHA256");
347
+ const verifier = crypto2.createVerify("RSA-SHA256");
258
348
  verifier.update(signString);
259
349
  verifier.end();
260
350
  return verifier.verify(publicKey, signature, "base64");
261
351
  }
262
352
  function oaepEncrypt(plaintext, publicKey) {
263
- const encrypted = crypto4.publicEncrypt(
353
+ const encrypted = crypto2.publicEncrypt(
264
354
  {
265
355
  key: publicKey,
266
- padding: crypto4.constants.RSA_PKCS1_OAEP_PADDING,
267
- oaepHash: "sha256"
356
+ padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING,
357
+ oaepHash: "sha1"
268
358
  },
269
359
  Buffer.from(plaintext, "utf-8")
270
360
  );
271
361
  return encrypted.toString("base64");
272
362
  }
363
+ function oaepDecrypt(ciphertext, privateKey) {
364
+ const decrypted = crypto2.privateDecrypt(
365
+ {
366
+ key: privateKey,
367
+ padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING,
368
+ oaepHash: "sha1"
369
+ },
370
+ Buffer.from(ciphertext, "base64")
371
+ );
372
+ return decrypted.toString("utf-8");
373
+ }
273
374
 
274
375
  // src/core/client.ts
275
376
  var WxPayClient = class _WxPayClient {
276
- /** 生产环境 API 地址 */
377
+ /** 生产环境 API 主域名 */
277
378
  static PRODUCTION_BASE = "https://api.mch.weixin.qq.com";
379
+ /** 生产环境 API 备用域名(跨城容灾) */
380
+ static PRODUCTION_BACKUP = "https://api2.mch.weixin.qq.com";
278
381
  /** 沙箱环境 API 地址 */
279
382
  static SANDBOX_BASE = "https://api.mch.weixin.qq.com/sandboxnew";
383
+ /** SDK 版本号 */
384
+ static SDK_VERSION = "0.2.1";
385
+ /** 动态 User-Agent 字符串 */
386
+ static USER_AGENT = (() => {
387
+ const platform = os.platform();
388
+ const arch = os.arch();
389
+ const nodeVersion = process.version;
390
+ return `wxpay-nodejs-sdk/${_WxPayClient.SDK_VERSION} (${platform} ${arch}) Node.js/${nodeVersion}`;
391
+ })();
280
392
  /** 商户号 */
281
393
  mchid;
282
394
  apiV3Key;
@@ -284,6 +396,7 @@ var WxPayClient = class _WxPayClient {
284
396
  privateKey;
285
397
  timeout;
286
398
  baseUrl;
399
+ backupUrl;
287
400
  enableResponseVerification;
288
401
  /** 平台证书管理器 */
289
402
  certificates;
@@ -294,6 +407,7 @@ var WxPayClient = class _WxPayClient {
294
407
  this.privateKey = this.resolvePrivateKey(options.privateKey);
295
408
  this.timeout = options.timeout ?? 3e4;
296
409
  this.baseUrl = options.sandbox ? _WxPayClient.SANDBOX_BASE : _WxPayClient.PRODUCTION_BASE;
410
+ this.backupUrl = options.sandbox ? null : _WxPayClient.PRODUCTION_BACKUP;
297
411
  this.enableResponseVerification = options.enableResponseVerification ?? true;
298
412
  this.certificates = new CertificateManager(this.apiV3Key, options.platformCertificates);
299
413
  if (options.wxpayPublicKeyId && options.wxpayPublicKey) {
@@ -365,8 +479,12 @@ var WxPayClient = class _WxPayClient {
365
479
  const headers = {
366
480
  Authorization: authorization,
367
481
  Accept: "application/json",
368
- "User-Agent": "wxpay-nodejs-sdk/0.1.0"
482
+ "User-Agent": _WxPayClient.USER_AGENT
369
483
  };
484
+ const serial = this.certificates.getNewestSerial();
485
+ if (serial) {
486
+ headers["Wechatpay-Serial"] = serial;
487
+ }
370
488
  const controller = new AbortController();
371
489
  const timeoutId = setTimeout(() => {
372
490
  controller.abort();
@@ -488,8 +606,12 @@ var WxPayClient = class _WxPayClient {
488
606
  Authorization: authorization,
489
607
  Accept: "application/json",
490
608
  "Content-Type": `multipart/form-data; boundary=${boundary}`,
491
- "User-Agent": "wxpay-nodejs-sdk/0.1.0"
609
+ "User-Agent": _WxPayClient.USER_AGENT
492
610
  };
611
+ const serial = this.certificates.getNewestSerial();
612
+ if (serial) {
613
+ headers["Wechatpay-Serial"] = serial;
614
+ }
493
615
  const controller = new AbortController();
494
616
  const timeoutId = setTimeout(() => {
495
617
  controller.abort();
@@ -530,67 +652,90 @@ var WxPayClient = class _WxPayClient {
530
652
  }
531
653
  /**
532
654
  * 通用 HTTP 请求方法
655
+ *
656
+ * 支持跨城容灾:当主域名请求失败(网络错误、超时)时,自动切换到备用域名重试。
533
657
  */
534
658
  async request(method, path, params, body, extraHeaders) {
535
- const url = buildUrl(this.baseUrl, path, params);
536
659
  const bodyStr = body ? JSON.stringify(body) : "";
537
660
  const timestamp = Math.floor(Date.now() / 1e3);
538
661
  const nonce = generateNonce();
539
- const urlObj = new URL(url);
540
- const signPath = urlObj.pathname + urlObj.search;
541
- const signString = buildSignString({
542
- method: method.toUpperCase(),
543
- path: signPath,
544
- timestamp,
545
- nonce,
546
- body: bodyStr
662
+ const headers = createRequestHeaders({
663
+ authorization: "",
664
+ wechatPaySerial: this.certificates.getNewestSerial(),
665
+ additional: extraHeaders
547
666
  });
548
- const signature = sign(signString, this.privateKey);
549
- const authorization = buildAuthorization(
550
- this.mchid,
551
- this.serialNo,
552
- timestamp,
553
- nonce,
554
- signature
555
- );
556
- const headers = createRequestHeaders({ authorization, additional: extraHeaders });
557
- const controller = new AbortController();
558
- const timeoutId = setTimeout(() => {
559
- controller.abort();
560
- }, this.timeout);
561
- try {
562
- const response = await fetch(url, {
563
- method,
564
- headers,
565
- body: bodyStr || void 0,
566
- signal: controller.signal
667
+ const urls = [this.baseUrl];
668
+ if (this.backupUrl) {
669
+ urls.push(this.backupUrl);
670
+ }
671
+ let lastError;
672
+ for (const baseUrl of urls) {
673
+ const url = buildUrl(baseUrl, path, params);
674
+ const urlObj = new URL(url);
675
+ const signPath = urlObj.pathname + urlObj.search;
676
+ const signString = buildSignString({
677
+ method: method.toUpperCase(),
678
+ path: signPath,
679
+ timestamp,
680
+ nonce,
681
+ body: bodyStr
567
682
  });
568
- return await parseResponse(response, this.createVerifier());
569
- } catch (error) {
570
- if (error instanceof WxPayError) {
571
- throw error;
572
- }
573
- if (error instanceof DOMException && error.name === "AbortError") {
574
- throw new WxPayError(
575
- 0,
576
- {},
577
- {
578
- code: "REQUEST_TIMEOUT",
579
- message: `\u8BF7\u6C42\u8D85\u65F6 (${this.timeout}ms)`
683
+ const signature = sign(signString, this.privateKey);
684
+ headers["Authorization"] = buildAuthorization(
685
+ this.mchid,
686
+ this.serialNo,
687
+ timestamp,
688
+ nonce,
689
+ signature
690
+ );
691
+ const controller = new AbortController();
692
+ const timeoutId = setTimeout(() => {
693
+ controller.abort();
694
+ }, this.timeout);
695
+ try {
696
+ const response = await fetch(url, {
697
+ method,
698
+ headers,
699
+ body: bodyStr || void 0,
700
+ signal: controller.signal
701
+ });
702
+ return await parseResponse(response, this.createVerifier());
703
+ } catch (error) {
704
+ lastError = error;
705
+ const isNetworkError = !(error instanceof WxPayError) && !(error instanceof DOMException && error.name === "AbortError");
706
+ if (!isNetworkError || urls.indexOf(baseUrl) === urls.length - 1) {
707
+ if (error instanceof WxPayError) throw error;
708
+ if (error instanceof DOMException && error.name === "AbortError") {
709
+ throw new WxPayError(
710
+ 0,
711
+ {},
712
+ {
713
+ code: "REQUEST_TIMEOUT",
714
+ message: `\u8BF7\u6C42\u8D85\u65F6 (${this.timeout}ms)`
715
+ }
716
+ );
580
717
  }
581
- );
582
- }
583
- throw new WxPayError(
584
- 0,
585
- {},
586
- {
587
- code: "NETWORK_ERROR",
588
- message: error instanceof Error ? error.message : "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"
718
+ throw new WxPayError(
719
+ 0,
720
+ {},
721
+ {
722
+ code: "NETWORK_ERROR",
723
+ message: error instanceof Error ? error.message : "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"
724
+ }
725
+ );
589
726
  }
590
- );
591
- } finally {
592
- clearTimeout(timeoutId);
727
+ } finally {
728
+ clearTimeout(timeoutId);
729
+ }
593
730
  }
731
+ throw new WxPayError(
732
+ 0,
733
+ {},
734
+ {
735
+ code: "NETWORK_ERROR",
736
+ message: lastError instanceof Error ? lastError.message : "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"
737
+ }
738
+ );
594
739
  }
595
740
  /**
596
741
  * 解析私钥:支持直接传入内容或文件路径
@@ -630,6 +775,75 @@ var WxPayClient = class _WxPayClient {
630
775
  };
631
776
  }
632
777
  };
778
+ var CertificateService = class {
779
+ client;
780
+ apiV3Key;
781
+ certificateManager;
782
+ constructor(client, apiV3Key, certificateManager) {
783
+ this.client = client;
784
+ this.apiV3Key = apiV3Key;
785
+ this.certificateManager = certificateManager;
786
+ }
787
+ /**
788
+ * 下载平台证书列表
789
+ *
790
+ * 调用微信支付 /v3/certificates 接口获取当前可用的平台证书。
791
+ * 返回的证书内容已解密为 PEM 格式。
792
+ *
793
+ * @returns 解密后的平台证书列表
794
+ */
795
+ async downloadCertificates() {
796
+ const response = await this.client.get("/v3/certificates");
797
+ const decryptedCerts = response.data.data.map((cert) => {
798
+ const pem = this.decryptCertificate(cert.encryptCertificate);
799
+ return {
800
+ serialNo: cert.serialNo,
801
+ effectiveTime: cert.effectiveTime,
802
+ expireTime: cert.expireTime,
803
+ certificatePem: pem
804
+ };
805
+ });
806
+ return {
807
+ status: response.status,
808
+ headers: response.headers,
809
+ data: decryptedCerts
810
+ };
811
+ }
812
+ /**
813
+ * 下载并更新本地平台证书缓存
814
+ *
815
+ * 下载最新的平台证书列表,解密后自动更新 CertificateManager 中的缓存。
816
+ * 适用于定时更新证书的场景。
817
+ *
818
+ * @returns 更新后的证书列表
819
+ */
820
+ async downloadAndUpdate() {
821
+ const response = await this.downloadCertificates();
822
+ for (const cert of response.data) {
823
+ this.certificateManager.setPublicKey(cert.serialNo, cert.certificatePem);
824
+ }
825
+ return response.data;
826
+ }
827
+ /**
828
+ * 使用 AES-256-GCM 解密证书内容
829
+ *
830
+ * @param encrypted - 加密的证书信息
831
+ * @returns PEM 格式的证书内容
832
+ */
833
+ decryptCertificate(encrypted) {
834
+ const key = Buffer.from(this.apiV3Key, "utf-8");
835
+ const nonce = Buffer.from(encrypted.nonce, "utf-8");
836
+ const aad = Buffer.from(encrypted.associatedData, "utf-8");
837
+ const ciphertextBuffer = Buffer.from(encrypted.ciphertext, "base64");
838
+ const authTag = ciphertextBuffer.subarray(-16);
839
+ const encryptedData = ciphertextBuffer.subarray(0, -16);
840
+ const decipher = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
841
+ decipher.setAuthTag(authTag);
842
+ decipher.setAAD(aad);
843
+ const decrypted = Buffer.concat([decipher.update(encryptedData), decipher.final()]);
844
+ return decrypted.toString("utf-8");
845
+ }
846
+ };
633
847
 
634
848
  // src/services/jsapi.ts
635
849
  var JsapiService = class {
@@ -2421,6 +2635,7 @@ var BillService = class {
2421
2635
  return this.client.downloadRaw(downloadUrl);
2422
2636
  }
2423
2637
  };
2638
+ var SUPPORTED_SIGNATURE_TYPES = /* @__PURE__ */ new Set(["WECHATPAY2-SHA256-RSA2048"]);
2424
2639
  var CallbackHandler = class {
2425
2640
  apiV3Key;
2426
2641
  certificates;
@@ -2432,13 +2647,19 @@ var CallbackHandler = class {
2432
2647
  * 验证回调通知签名
2433
2648
  *
2434
2649
  * 使用微信支付平台公钥验证回调通知的签名。
2650
+ * 支持读取 Wechatpay-Signature-Type 头识别签名类型。
2435
2651
  *
2436
2652
  * @param headers - 回调请求头
2437
2653
  * @param body - 回调请求体(原始 JSON 字符串)
2438
2654
  * @returns 签名验证是否通过
2655
+ * @throws 如果签名类型不支持或找不到对应的证书
2439
2656
  */
2440
2657
  verifySignature(headers, body) {
2658
+ const signatureType = headers["wechatpay-signature-type"];
2441
2659
  const serialNo = headers["wechatpay-serial"];
2660
+ if (signatureType && !SUPPORTED_SIGNATURE_TYPES.has(signatureType)) {
2661
+ throw new Error(`\u4E0D\u652F\u6301\u7684\u7B7E\u540D\u7C7B\u578B: ${signatureType}`);
2662
+ }
2442
2663
  const publicKey = this.certificates.getPublicKey(serialNo);
2443
2664
  if (!publicKey) {
2444
2665
  throw new Error(`\u672A\u627E\u5230\u5E8F\u5217\u53F7\u4E3A ${serialNo} \u7684\u5E73\u53F0\u8BC1\u4E66\uFF0C\u8BF7\u786E\u4FDD\u5DF2\u914D\u7F6E\u5E73\u53F0\u8BC1\u4E66`);
@@ -2715,7 +2936,7 @@ var CallbackHandler = class {
2715
2936
  const ciphertextBuffer = Buffer.from(ciphertext, "base64");
2716
2937
  const authTag = ciphertextBuffer.subarray(-16);
2717
2938
  const encryptedData = ciphertextBuffer.subarray(0, -16);
2718
- const decipher = crypto4.createDecipheriv("aes-256-gcm", key, Buffer.from(nonce, "utf-8"));
2939
+ const decipher = crypto2.createDecipheriv("aes-256-gcm", key, Buffer.from(nonce, "utf-8"));
2719
2940
  decipher.setAuthTag(authTag);
2720
2941
  decipher.setAAD(Buffer.from(associatedData, "utf-8"));
2721
2942
  const decrypted = Buffer.concat([decipher.update(encryptedData), decipher.final()]);
@@ -3843,13 +4064,327 @@ var SecurityService = class {
3843
4064
  return this.client.post("/v3/security/echo", request);
3844
4065
  }
3845
4066
  };
4067
+
4068
+ // src/services/payrollcard.ts
4069
+ var PayrollCardService = class {
4070
+ client;
4071
+ constructor(client) {
4072
+ this.client = client;
4073
+ }
4074
+ /**
4075
+ * 查询授权关系
4076
+ *
4077
+ * 查询商户与用户之间的微工卡授权关系。
4078
+ *
4079
+ * @param params - 查询参数
4080
+ * @returns 授权关系信息
4081
+ */
4082
+ async queryAuthorization(params) {
4083
+ return this.client.get("/v3/payroll-card/relations", params);
4084
+ }
4085
+ /**
4086
+ * 生成预授权 token
4087
+ *
4088
+ * 生成微工卡预授权 token,用于后续核身操作。
4089
+ *
4090
+ * @param request - 预授权请求参数
4091
+ * @returns 预授权 token 信息
4092
+ */
4093
+ async createToken(request) {
4094
+ return this.client.post("/v3/payroll-card/tokens", request);
4095
+ }
4096
+ /**
4097
+ * 核身预下单
4098
+ *
4099
+ * 创建核身预下单,获取核身参数。
4100
+ *
4101
+ * @param request - 核身预下单请求参数
4102
+ * @returns 核身参数信息
4103
+ */
4104
+ async createAuthentication(request) {
4105
+ return this.client.post("/v3/payroll-card/authentications", request);
4106
+ }
4107
+ /**
4108
+ * 查询核身结果
4109
+ *
4110
+ * 根据商户请求号查询核身结果。
4111
+ *
4112
+ * @param outRequestNo - 商户请求号
4113
+ * @param params - 查询参数
4114
+ * @returns 核身结果信息
4115
+ */
4116
+ async queryAuthentication(outRequestNo, params) {
4117
+ return this.client.get(
4118
+ `/v3/payroll-card/authentications/out-request-no/${outRequestNo}`,
4119
+ params
4120
+ );
4121
+ }
4122
+ /**
4123
+ * 发起批量转账
4124
+ *
4125
+ * 通过工资卡渠道发起批量转账。
4126
+ *
4127
+ * @param request - 批量转账请求参数
4128
+ * @returns 批量转账结果
4129
+ */
4130
+ async createTransferBatch(request) {
4131
+ return this.client.post("/v3/payroll-card/transfer-batches", request);
4132
+ }
4133
+ };
4134
+
4135
+ // src/services/scanandride.ts
4136
+ var ScanAndRideService = class {
4137
+ client;
4138
+ constructor(client) {
4139
+ this.client = client;
4140
+ }
4141
+ /**
4142
+ * 开通用户服务
4143
+ *
4144
+ * 用户授权开通刷码乘车服务。
4145
+ *
4146
+ * @param request - 开通服务请求参数
4147
+ * @returns 开通结果
4148
+ */
4149
+ async createUserService(request) {
4150
+ return this.client.post("/v3/qrcode/user-services", request);
4151
+ }
4152
+ /**
4153
+ * 查询用户服务状态
4154
+ *
4155
+ * 查询用户是否已开通刷码乘车服务。
4156
+ *
4157
+ * @param outRequestNo - 商户请求号
4158
+ * @param params - 查询参数
4159
+ * @returns 用户服务状态
4160
+ */
4161
+ async queryUserService(outRequestNo, params) {
4162
+ return this.client.get(`/v3/qrcode/user-services/out-request-no/${outRequestNo}`, params);
4163
+ }
4164
+ /**
4165
+ * 扣费受理
4166
+ *
4167
+ * 发起刷码乘车扣费请求。
4168
+ *
4169
+ * @param request - 扣费请求参数
4170
+ * @returns 扣费受理结果
4171
+ */
4172
+ async createTransaction(request) {
4173
+ return this.client.post("/v3/qrcode/transactions", request);
4174
+ }
4175
+ /**
4176
+ * 查询扣费订单
4177
+ *
4178
+ * 根据商户订单号查询扣费订单状态。
4179
+ *
4180
+ * @param outTradeNo - 商户订单号
4181
+ * @param params - 查询参数
4182
+ * @returns 订单信息
4183
+ */
4184
+ async queryTransaction(outTradeNo, params) {
4185
+ return this.client.get(`/v3/qrcode/transactions/out-trade-no/${outTradeNo}`, params);
4186
+ }
4187
+ };
4188
+
4189
+ // src/services/retailstore.ts
4190
+ var RetailStoreService = class {
4191
+ client;
4192
+ constructor(client) {
4193
+ this.client = client;
4194
+ }
4195
+ /**
4196
+ * 创建门店活动
4197
+ *
4198
+ * @param request - 活动创建请求参数
4199
+ * @returns 创建结果
4200
+ */
4201
+ async createActivity(request) {
4202
+ return this.client.post("/v3/marketing/goldplan/retailstore/activities", request);
4203
+ }
4204
+ /**
4205
+ * 查询门店活动详情
4206
+ *
4207
+ * @param activityId - 活动ID
4208
+ * @returns 活动详情
4209
+ */
4210
+ async queryActivity(activityId) {
4211
+ return this.client.get(`/v3/marketing/goldplan/retailstore/activities/${activityId}`);
4212
+ }
4213
+ /**
4214
+ * 更新门店活动
4215
+ *
4216
+ * @param activityId - 活动ID
4217
+ * @param request - 更新请求参数
4218
+ * @returns 更新结果
4219
+ */
4220
+ async updateActivity(activityId, request) {
4221
+ return this.client.patch(
4222
+ `/v3/marketing/goldplan/retailstore/activities/${activityId}`,
4223
+ request
4224
+ );
4225
+ }
4226
+ /**
4227
+ * 创建门店资质
4228
+ *
4229
+ * @param request - 资质创建请求参数
4230
+ * @returns 创建结果
4231
+ */
4232
+ async createQualification(request) {
4233
+ return this.client.post("/v3/marketing/goldplan/retailstore/qualifications", request);
4234
+ }
4235
+ /**
4236
+ * 查询门店资质
4237
+ *
4238
+ * @param qualificationId - 资质ID
4239
+ * @returns 资质详情
4240
+ */
4241
+ async queryQualification(qualificationId) {
4242
+ return this.client.get(`/v3/marketing/goldplan/retailstore/qualifications/${qualificationId}`);
4243
+ }
4244
+ };
4245
+
4246
+ // src/services/goldplan.ts
4247
+ var GoldPlanService = class {
4248
+ client;
4249
+ constructor(client) {
4250
+ this.client = client;
4251
+ }
4252
+ /**
4253
+ * 查询商户零钱余额
4254
+ *
4255
+ * @param mchid - 商户号
4256
+ * @returns 零钱余额信息
4257
+ */
4258
+ async queryBalance(mchid) {
4259
+ return this.client.get(`/v3/merchant/fund/balance/${mchid}`);
4260
+ }
4261
+ /**
4262
+ * 查询商户零钱流水
4263
+ *
4264
+ * @param mchid - 商户号
4265
+ * @param params - 查询参数
4266
+ * @returns 零钱流水列表
4267
+ */
4268
+ async queryFlow(mchid, params) {
4269
+ return this.client.get(`/v3/merchant/fund/flow`, { mchid, ...params });
4270
+ }
4271
+ /**
4272
+ * 查询商家零钱状态
4273
+ *
4274
+ * @param mchid - 商户号
4275
+ * @returns 零钱状态信息
4276
+ */
4277
+ async queryStatus(mchid) {
4278
+ return this.client.get(`/v3/merchant/fund/status/${mchid}`);
4279
+ }
4280
+ };
4281
+
4282
+ // src/services/lovefeast.ts
4283
+ var LoveFeastService = class {
4284
+ client;
4285
+ constructor(client) {
4286
+ this.client = client;
4287
+ }
4288
+ /**
4289
+ * 创建爱心餐品牌
4290
+ *
4291
+ * @param request - 品牌创建请求参数
4292
+ * @returns 创建结果
4293
+ */
4294
+ async createBrand(request) {
4295
+ return this.client.post("/v3/lovefeast/brands", request);
4296
+ }
4297
+ /**
4298
+ * 查询爱心餐品牌
4299
+ *
4300
+ * @param brandId - 品牌ID
4301
+ * @returns 品牌详情
4302
+ */
4303
+ async queryBrand(brandId) {
4304
+ return this.client.get(`/v3/lovefeast/brands/${brandId}`);
4305
+ }
4306
+ /**
4307
+ * 创建爱心餐订单
4308
+ *
4309
+ * @param request - 订单创建请求参数
4310
+ * @returns 订单创建结果
4311
+ */
4312
+ async createOrder(request) {
4313
+ return this.client.post("/v3/lovefeast/orders", request);
4314
+ }
4315
+ /**
4316
+ * 查询爱心餐订单
4317
+ *
4318
+ * @param outTradeNo - 商户订单号
4319
+ * @param params - 查询参数
4320
+ * @returns 订单详情
4321
+ */
4322
+ async queryOrder(outTradeNo, params) {
4323
+ return this.client.get(`/v3/lovefeast/orders/out-trade-no/${outTradeNo}`, params);
4324
+ }
4325
+ };
4326
+
4327
+ // src/services/merchant-exclusive-coupon.ts
4328
+ var MerchantExclusiveCouponService = class {
4329
+ client;
4330
+ constructor(client) {
4331
+ this.client = client;
4332
+ }
4333
+ /**
4334
+ * 创建优惠券批次
4335
+ *
4336
+ * @param request - 批次创建请求参数
4337
+ * @returns 创建结果
4338
+ */
4339
+ async createCouponStock(request) {
4340
+ return this.client.post("/v3/marketing/busifavor/stocks", request);
4341
+ }
4342
+ /**
4343
+ * 查询优惠券批次详情
4344
+ *
4345
+ * @param stockId - 批次ID
4346
+ * @returns 批次详情
4347
+ */
4348
+ async queryCouponStock(stockId) {
4349
+ return this.client.get(`/v3/marketing/busifavor/stocks/${stockId}`);
4350
+ }
4351
+ /**
4352
+ * 发放优惠券
4353
+ *
4354
+ * @param request - 发放请求参数
4355
+ * @returns 发放结果
4356
+ */
4357
+ async sendCoupon(request) {
4358
+ return this.client.post("/v3/marketing/busifavor/coupons", request);
4359
+ }
4360
+ /**
4361
+ * 查询用户优惠券
4362
+ *
4363
+ * @param openid - 用户标识
4364
+ * @param params - 查询参数
4365
+ * @returns 用户优惠券列表
4366
+ */
4367
+ async queryUserCoupons(openid, params) {
4368
+ return this.client.get(`/v3/marketing/busifavor/users/${openid}/coupons`, params);
4369
+ }
4370
+ /**
4371
+ * 查询优惠券详情
4372
+ *
4373
+ * @param couponId - 优惠券ID
4374
+ * @param params - 查询参数
4375
+ * @returns 优惠券详情
4376
+ */
4377
+ async queryCoupon(couponId, params) {
4378
+ return this.client.get(`/v3/marketing/busifavor/users/coupons/${couponId}`, params);
4379
+ }
4380
+ };
3846
4381
  function generateAppPaySign(appId, timeStamp, nonceStr, prepayId, privateKey) {
3847
4382
  const signString = `${appId}
3848
4383
  ${timeStamp}
3849
4384
  ${nonceStr}
3850
4385
  prepay_id=${prepayId}
3851
4386
  `;
3852
- const signer = crypto4.createSign("RSA-SHA256");
4387
+ const signer = crypto2.createSign("RSA-SHA256");
3853
4388
  signer.update(signString);
3854
4389
  signer.end();
3855
4390
  return signer.sign(privateKey, "base64");
@@ -3874,13 +4409,13 @@ ${timeStamp}
3874
4409
  ${nonceStr}
3875
4410
  prepay_id=${prepayId}
3876
4411
  `;
3877
- const signer = crypto4.createSign("RSA-SHA256");
4412
+ const signer = crypto2.createSign("RSA-SHA256");
3878
4413
  signer.update(signString);
3879
4414
  signer.end();
3880
4415
  return signer.sign(privateKey, "base64");
3881
4416
  }
3882
4417
  function generateNonceStr() {
3883
- return crypto4.randomUUID().replace(/-/g, "");
4418
+ return crypto2.randomUUID().replace(/-/g, "");
3884
4419
  }
3885
4420
  function buildJsapiBridgeConfig(appId, prepayId, privateKey) {
3886
4421
  const timeStamp = String(Math.floor(Date.now() / 1e3));
@@ -3914,7 +4449,7 @@ ${timeStamp}
3914
4449
  ${nonceStr}
3915
4450
  ${packageStr}
3916
4451
  `;
3917
- const signer = crypto4.createSign("RSA-SHA256");
4452
+ const signer = crypto2.createSign("RSA-SHA256");
3918
4453
  signer.update(signString);
3919
4454
  signer.end();
3920
4455
  return signer.sign(privateKey, "base64");
@@ -4064,7 +4599,7 @@ function buildH5CouponUrl(params, signKey) {
4064
4599
  }
4065
4600
  const sortedKeys = Object.keys(signFields).sort();
4066
4601
  const signStr = sortedKeys.map((k) => `${k}=${signFields[k]}`).join("&") + `&key=${signKey}`;
4067
- const sign2 = crypto4.createHmac("sha256", signKey).update(signStr).digest("hex").toUpperCase();
4602
+ const sign2 = crypto2.createHmac("sha256", signKey).update(signStr).digest("hex").toUpperCase();
4068
4603
  const urlParams = new URLSearchParams({
4069
4604
  stock_id: params.stock_id,
4070
4605
  out_request_no: params.out_request_no,
@@ -4166,7 +4701,7 @@ ${timestamp}
4166
4701
  ${nonceStr}
4167
4702
  ${packageStr}
4168
4703
  `;
4169
- const signer = crypto4.createSign("RSA-SHA256");
4704
+ const signer = crypto2.createSign("RSA-SHA256");
4170
4705
  signer.update(signString);
4171
4706
  signer.end();
4172
4707
  const sign2 = signer.sign(privateKey, "base64");
@@ -4181,6 +4716,6 @@ ${packageStr}
4181
4716
  };
4182
4717
  }
4183
4718
 
4184
- export { AppService, BillService, BusinessCircleService, CallbackHandler, CertificateManager, CombineAppService, CombineH5Service, CombineMiniProgramService, CombineNativeService, CombineService, ComplaintService, CouponService, H5Service, JsapiService, MedInsService, MediaService, MerchantTransferService, NativeService, ParkingService, PartnershipService, PayGiftActivityService, PayScoreService, ProfitSharingService, SecurityService, SmartGuideService, WxPayClient, WxPayError, buildAppBridgeConfig, buildAuthorization, buildH5CouponUrl, buildJsapiBridgeConfig, buildMedInsJsapiBridgeConfig, buildMedInsMiniProgramBridgeConfig, buildMerchantTransferAuthorizationJsapiBridgeConfig, buildMerchantTransferJsapiBridgeConfig, buildMerchantTransferMiniProgramBridgeConfig, buildMiniProgramBridgeConfig, buildParkingAppBridgePath, buildParkingH5BridgeUrl, buildParkingMiniProgramBridgeConfig, buildParkingRepayBridgeConfig, buildPayScoreAppBridgeConfig, buildPayScoreDetailAppBridgeConfig, buildPayScoreDetailJsapiBridgeConfig, buildPayScoreDetailMiniProgramBridgeConfig, buildPayScoreJsapiBridgeConfig, buildPayScoreMiniProgramBridgeConfig, buildSignString, generateAppPaySign, generateNonce, generateNonceStr, generatePayScorePaySign, generatePaySign, oaepEncrypt, sign, verifySignature };
4719
+ export { AppService, BillService, BusinessCircleService, CallbackHandler, CertificateManager, CertificateService, CombineAppService, CombineH5Service, CombineMiniProgramService, CombineNativeService, CombineService, ComplaintService, CouponService, GoldPlanService, H5Service, JsapiService, LoveFeastService, MedInsService, MediaService, MerchantExclusiveCouponService, MerchantTransferService, NativeService, ParkingService, PartnershipService, PayGiftActivityService, PayScoreService, PayrollCardService, ProfitSharingService, RetailStoreService, ScanAndRideService, SecurityService, SmartGuideService, WxPayClient, WxPayError, buildAppBridgeConfig, buildAuthorization, buildH5CouponUrl, buildJsapiBridgeConfig, buildMedInsJsapiBridgeConfig, buildMedInsMiniProgramBridgeConfig, buildMerchantTransferAuthorizationJsapiBridgeConfig, buildMerchantTransferJsapiBridgeConfig, buildMerchantTransferMiniProgramBridgeConfig, buildMiniProgramBridgeConfig, buildParkingAppBridgePath, buildParkingH5BridgeUrl, buildParkingMiniProgramBridgeConfig, buildParkingRepayBridgeConfig, buildPayScoreAppBridgeConfig, buildPayScoreDetailAppBridgeConfig, buildPayScoreDetailJsapiBridgeConfig, buildPayScoreDetailMiniProgramBridgeConfig, buildPayScoreJsapiBridgeConfig, buildPayScoreMiniProgramBridgeConfig, buildSignString, generateAppPaySign, generateNonce, generateNonceStr, generatePayScorePaySign, generatePaySign, isTimestampValid, oaepDecrypt, oaepEncrypt, sign, verifySignature };
4185
4720
  //# sourceMappingURL=index.mjs.map
4186
4721
  //# sourceMappingURL=index.mjs.map