@jayfong/x-server 2.118.0 → 2.118.1

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.
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
5
  exports.PayService = void 0;
6
- var _crypto = _interopRequireDefault(require("crypto"));
6
+ var _nodeCrypto = _interopRequireDefault(require("node:crypto"));
7
7
  var _alipaySdk = _interopRequireDefault(require("alipay-sdk"));
8
8
  var _form = _interopRequireDefault(require("alipay-sdk/lib/form"));
9
9
  var _got = _interopRequireDefault(require("got"));
@@ -44,9 +44,8 @@ class PayService {
44
44
  };
45
45
  }
46
46
  async prepareWepay(options) {
47
- const appId = options.appId || this.options.wepay.appId;
48
47
  const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
49
- appid: appId,
48
+ appid: this.options.wepay.appId,
50
49
  mchid: this.options.wepay.merchantId,
51
50
  description: options.goodsName,
52
51
  out_trade_no: options.tradeNumber,
@@ -65,7 +64,7 @@ class PayService {
65
64
  throw new Error(error);
66
65
  }
67
66
  const params = {
68
- appId: appId,
67
+ appId: this.options.wepay.appId,
69
68
  timestamp: String(Math.round(Date.now() / 1000)),
70
69
  nonceStr: Math.random().toString().substr(2, 12),
71
70
  package: `prepay_id=${res.prepay_id}`,
@@ -145,13 +144,13 @@ class PayService {
145
144
  };
146
145
  }
147
146
  wepaySign(data) {
148
- return _crypto.default.createSign('RSA-SHA256').update(data.map(v => `${v}\n`).join('')).sign(this.options.wepay.privateKey, 'base64');
147
+ return _nodeCrypto.default.createSign('RSA-SHA256').update(data.map(v => `${v}\n`).join('')).sign(this.options.wepay.privateKey, 'base64');
149
148
  }
150
149
  wepayDecrypt(payload) {
151
150
  const ciphertextBuffer = Buffer.from(payload.ciphertext, 'base64');
152
151
  const authTag = ciphertextBuffer.slice(ciphertextBuffer.length - 16);
153
152
  const data = ciphertextBuffer.slice(0, ciphertextBuffer.length - 16);
154
- const decipherIv = _crypto.default.createDecipheriv('aes-256-gcm', this.options.wepay.secretKey, payload.nonce);
153
+ const decipherIv = _nodeCrypto.default.createDecipheriv('aes-256-gcm', this.options.wepay.secretKey, payload.nonce);
155
154
  decipherIv.setAuthTag(Buffer.from(authTag));
156
155
  decipherIv.setAAD(Buffer.from(payload.associated_data));
157
156
  const decryptStr = decipherIv.update(data, undefined, 'utf8');
@@ -2,7 +2,7 @@ import { EventEmitter } from 'node:events';
2
2
  declare class EventBus extends EventEmitter {
3
3
  onReturnOff(event: string, listener: (...args: any[]) => any): () => any;
4
4
  }
5
- export declare function defineBus<T extends Record<string, any>>(): StrictEventEmitter<EventBus, T, T, "addEventListener" | "removeEventListener", "on" | "addListener" | "once" | "removeListener" | "emit" | "off" | "onReturnOff">;
5
+ export declare function defineBus<T extends Record<string, any>>(): StrictEventEmitter<EventBus, T, T, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit" | "off" | "onReturnOff">;
6
6
  declare const assignmentCompatibilityHack: unique symbol;
7
7
  interface TypeRecord<T, U, V> {
8
8
  ' _emitterType'?: T;
@@ -1,4 +1,4 @@
1
- import { BaseService } from './base';
1
+ import type { BaseService } from './base';
2
2
  export interface PayServiceOptions {
3
3
  /** 支付宝 */
4
4
  alipay?: {
@@ -9,17 +9,17 @@ export interface PayServiceOptions {
9
9
  /** 支付宝公钥,用于对返回结果验签 */
10
10
  publicKey: string;
11
11
  };
12
- /** 微信支付 */
12
+ /** 微信支付(APIv3),未实现回调验签,因此验证微信支付身份块不需要关心 */
13
13
  wepay?: {
14
14
  /** 公众号 APPID */
15
15
  appId: string;
16
16
  /** 商户 ID */
17
17
  merchantId: string;
18
- /** 商户应用私钥 */
18
+ /** 商户API证书私钥 */
19
19
  privateKey: string;
20
- /** 证书序列号 */
20
+ /** 商户API证书序列号 */
21
21
  certificateSerialNumber: string;
22
- /** 秘钥,用于解密请求平台证书、回调数据 */
22
+ /** 密钥,用于解密回调数据 */
23
23
  secretKey: string;
24
24
  };
25
25
  }
@@ -48,9 +48,7 @@ export interface PayServicePrepareWepayOptions {
48
48
  totalMoney: number;
49
49
  /** 通知地址(POST) */
50
50
  notifyUrl: string;
51
- /** 对应公众号的 appId */
52
- appId?: string;
53
- /** 对应公众号用户的 openid */
51
+ /** 公众号用户的 openid */
54
52
  openid: string;
55
53
  }
56
54
  export interface PayServicePrepareWepayResult {
@@ -1,4 +1,4 @@
1
- import crypto from 'crypto';
1
+ import crypto from 'node:crypto';
2
2
  import AlipaySdk from 'alipay-sdk';
3
3
  import AlipayFormData from 'alipay-sdk/lib/form';
4
4
  import got from 'got';
@@ -39,9 +39,8 @@ export class PayService {
39
39
  };
40
40
  }
41
41
  async prepareWepay(options) {
42
- const appId = options.appId || this.options.wepay.appId;
43
42
  const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
44
- appid: appId,
43
+ appid: this.options.wepay.appId,
45
44
  mchid: this.options.wepay.merchantId,
46
45
  description: options.goodsName,
47
46
  out_trade_no: options.tradeNumber,
@@ -60,7 +59,7 @@ export class PayService {
60
59
  throw new Error(error);
61
60
  }
62
61
  const params = {
63
- appId: appId,
62
+ appId: this.options.wepay.appId,
64
63
  timestamp: String(Math.round(Date.now() / 1000)),
65
64
  nonceStr: Math.random().toString().substr(2, 12),
66
65
  package: `prepay_id=${res.prepay_id}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.118.0",
3
+ "version": "2.118.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -22,7 +22,7 @@
22
22
  "up_prisma": "tpm dlx npm-check-updates '/.*prisma.*/' -i --target semver"
23
23
  },
24
24
  "dependencies": {
25
- "@jayfong/x-request": "^2.118.0",
25
+ "@jayfong/x-request": "^2.118.1",
26
26
  "@aws-sdk/client-s3": "^3.1079.0",
27
27
  "@aws-sdk/s3-request-presigner": "^3.1079.0",
28
28
  "@fastify/compress": "^7.0.3",