@celljs/alipay 0.0.0-stage → 4.4.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/README.md +109 -2
- package/cell.schema.json +58 -0
- package/cell.yml +10 -0
- package/esm/node/alipay-client.d.ts +58 -0
- package/esm/node/alipay-client.js +234 -0
- package/esm/node/alipay-client.js.map +1 -0
- package/esm/node/alipay-error.d.ts +28 -0
- package/esm/node/alipay-error.js +20 -0
- package/esm/node/alipay-error.js.map +1 -0
- package/esm/node/alipay-notification-middleware.d.ts +23 -0
- package/esm/node/alipay-notification-middleware.js +102 -0
- package/esm/node/alipay-notification-middleware.js.map +1 -0
- package/esm/node/alipay-protocol.d.ts +200 -0
- package/esm/node/alipay-protocol.js +15 -0
- package/esm/node/alipay-protocol.js.map +1 -0
- package/esm/node/alipay-util.d.ts +35 -0
- package/esm/node/alipay-util.js +191 -0
- package/esm/node/alipay-util.js.map +1 -0
- package/esm/node/index.d.ts +5 -0
- package/esm/node/index.js +6 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/test/fixtures.d.ts +10 -0
- package/esm/node/test/fixtures.js +266 -0
- package/esm/node/test/fixtures.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/alipay-client.d.ts +59 -0
- package/lib/node/alipay-client.d.ts.map +1 -0
- package/lib/node/alipay-client.js +237 -0
- package/lib/node/alipay-client.js.map +1 -0
- package/lib/node/alipay-error.d.ts +29 -0
- package/lib/node/alipay-error.d.ts.map +1 -0
- package/lib/node/alipay-error.js +24 -0
- package/lib/node/alipay-error.js.map +1 -0
- package/lib/node/alipay-notification-middleware.d.ts +24 -0
- package/lib/node/alipay-notification-middleware.d.ts.map +1 -0
- package/lib/node/alipay-notification-middleware.js +105 -0
- package/lib/node/alipay-notification-middleware.js.map +1 -0
- package/lib/node/alipay-protocol.d.ts +201 -0
- package/lib/node/alipay-protocol.d.ts.map +1 -0
- package/lib/node/alipay-protocol.js +19 -0
- package/lib/node/alipay-protocol.js.map +1 -0
- package/lib/node/alipay-util.d.ts +36 -0
- package/lib/node/alipay-util.d.ts.map +1 -0
- package/lib/node/alipay-util.js +194 -0
- package/lib/node/alipay-util.js.map +1 -0
- package/lib/node/alipay-util.spec.d.ts +2 -0
- package/lib/node/alipay-util.spec.d.ts.map +1 -0
- package/lib/node/alipay-util.spec.js +49 -0
- package/lib/node/alipay-util.spec.js.map +1 -0
- package/lib/node/alipay.spec.d.ts +8 -0
- package/lib/node/alipay.spec.d.ts.map +1 -0
- package/lib/node/alipay.spec.js +314 -0
- package/lib/node/alipay.spec.js.map +1 -0
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +22 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/test/fixtures.d.ts +11 -0
- package/lib/node/test/fixtures.d.ts.map +1 -0
- package/lib/node/test/fixtures.js +269 -0
- package/lib/node/test/fixtures.js.map +1 -0
- package/lib/package.spec.d.ts +2 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +7 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +70 -4
- package/src/node/alipay-client.ts +266 -0
- package/src/node/alipay-error.ts +31 -0
- package/src/node/alipay-notification-middleware.ts +90 -0
- package/src/node/alipay-protocol.ts +210 -0
- package/src/node/alipay-util.spec.ts +56 -0
- package/src/node/alipay-util.ts +183 -0
- package/src/node/alipay.spec.ts +331 -0
- package/src/node/index.ts +5 -0
- package/src/node/module.ts +4 -0
- package/src/node/test/fixtures.ts +272 -0
- package/src/package.spec.ts +5 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Autowired, AutowiredProvider, Component, Logger, Value } from '@celljs/core';
|
|
11
|
+
import { HttpHeaders, MediaType } from '@celljs/http';
|
|
12
|
+
import { PathResolver } from '@celljs/web';
|
|
13
|
+
import { BodyParser, Middleware, RequestMatcher } from '@celljs/web/lib/node';
|
|
14
|
+
import { AlipayError } from './alipay-error.js';
|
|
15
|
+
import { ALIPAY_NOTIFICATION_HANDLER, ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY, AlipayClient, } from './alipay-protocol.js';
|
|
16
|
+
import { AlipayUtil } from './alipay-util.js';
|
|
17
|
+
/**
|
|
18
|
+
* The notification endpoint (`POST alipay.notification.url`): verifies the signature of the form and runs the
|
|
19
|
+
* `@AlipayNotificationHandler` components of its `trade_status`. It answers `success` when they succeed and `fail`
|
|
20
|
+
* otherwise (400 for a bad signature, 500 when a handler throws), so that Alipay sends the notification again.
|
|
21
|
+
*/
|
|
22
|
+
let AlipayNotificationMiddleware = class AlipayNotificationMiddleware {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.priority = ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY;
|
|
25
|
+
}
|
|
26
|
+
async handle(ctx, next) {
|
|
27
|
+
var _a;
|
|
28
|
+
var _b, _c;
|
|
29
|
+
const notification = (_a = this.options) === null || _a === void 0 ? void 0 : _a.notification;
|
|
30
|
+
if (ctx.request.method !== 'POST' ||
|
|
31
|
+
(notification === null || notification === void 0 ? void 0 : notification.enabled) === false ||
|
|
32
|
+
!(await this.requestMatcher.match(await this.pathResolver.resolve((_b = notification === null || notification === void 0 ? void 0 : notification.url) !== null && _b !== void 0 ? _b : '/alipay/notify'), 'POST'))) {
|
|
33
|
+
return next();
|
|
34
|
+
}
|
|
35
|
+
let status = 200;
|
|
36
|
+
try {
|
|
37
|
+
(_c = this.parser) !== null && _c !== void 0 ? _c : (this.parser = new BodyParser(this.bodyOptions));
|
|
38
|
+
const body = await this.parser.raw(ctx.request);
|
|
39
|
+
const params = Object.fromEntries(new URLSearchParams(body.toString('utf8')));
|
|
40
|
+
await this.dispatch(this.client.verifyNotification(params));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const refused = AlipayError.is(error, 'CELL_ALIPAY_SIGNATURE_INVALID') || AlipayError.is(error, 'CELL_ALIPAY_APP_ID_MISMATCH');
|
|
44
|
+
if (refused) {
|
|
45
|
+
this.logger.warn(`Alipay notification refused: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.logger.error(error);
|
|
49
|
+
}
|
|
50
|
+
status = refused ? 400 : 500;
|
|
51
|
+
}
|
|
52
|
+
ctx.response.statusCode = status;
|
|
53
|
+
ctx.response.setHeader(HttpHeaders.CONTENT_TYPE, `${MediaType.TEXT_PLAIN};charset=UTF-8`);
|
|
54
|
+
ctx.response.end(status === 200 ? 'success' : 'fail');
|
|
55
|
+
}
|
|
56
|
+
async dispatch(notification) {
|
|
57
|
+
var _a, _b, _c, _d;
|
|
58
|
+
(_a = this.handlers) !== null && _a !== void 0 ? _a : (this.handlers = AlipayUtil.indexHandlers(this.handlerProvider.get()));
|
|
59
|
+
const type = (_b = notification.trade_status) !== null && _b !== void 0 ? _b : notification.notify_type;
|
|
60
|
+
const handlers = [...((_c = this.handlers.get(type)) !== null && _c !== void 0 ? _c : []), ...((_d = this.handlers.get('*')) !== null && _d !== void 0 ? _d : [])];
|
|
61
|
+
if (!handlers.length) {
|
|
62
|
+
this.logger.warn(`No @AlipayNotificationHandler for ${type}; notification ${notification.notify_id} acknowledged.`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const handler of handlers) {
|
|
66
|
+
await handler.handle(notification);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
__decorate([
|
|
71
|
+
Autowired(AlipayClient),
|
|
72
|
+
__metadata("design:type", Object)
|
|
73
|
+
], AlipayNotificationMiddleware.prototype, "client", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
AutowiredProvider(ALIPAY_NOTIFICATION_HANDLER),
|
|
76
|
+
__metadata("design:type", Object)
|
|
77
|
+
], AlipayNotificationMiddleware.prototype, "handlerProvider", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Autowired(RequestMatcher),
|
|
80
|
+
__metadata("design:type", Object)
|
|
81
|
+
], AlipayNotificationMiddleware.prototype, "requestMatcher", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
Autowired(PathResolver),
|
|
84
|
+
__metadata("design:type", Object)
|
|
85
|
+
], AlipayNotificationMiddleware.prototype, "pathResolver", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
Autowired(Logger),
|
|
88
|
+
__metadata("design:type", Object)
|
|
89
|
+
], AlipayNotificationMiddleware.prototype, "logger", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
Value('alipay'),
|
|
92
|
+
__metadata("design:type", Object)
|
|
93
|
+
], AlipayNotificationMiddleware.prototype, "options", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
Value('web.body'),
|
|
96
|
+
__metadata("design:type", Object)
|
|
97
|
+
], AlipayNotificationMiddleware.prototype, "bodyOptions", void 0);
|
|
98
|
+
AlipayNotificationMiddleware = __decorate([
|
|
99
|
+
Component(Middleware)
|
|
100
|
+
], AlipayNotificationMiddleware);
|
|
101
|
+
export { AlipayNotificationMiddleware };
|
|
102
|
+
//# sourceMappingURL=alipay-notification-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alipay-notification-middleware.js","sourceRoot":"","sources":["../../src/node/alipay-notification-middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,EAAiB,KAAK,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAoB,UAAU,EAAgB,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACH,2BAA2B,EAC3B,uCAAuC,EACvC,YAAY,GAIf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;GAIG;AAEI,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAAlC;QAsBM,aAAQ,GAAG,uCAAuC,CAAC;IA8ChE,CAAC;IAzCG,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,IAAyB;;;QAChD,MAAM,YAAY,GAAG,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC;QAChD,IACI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM;YAC7B,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,MAAK,KAAK;YAC/B,CAAC,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,OAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,GAAG,mCAAI,gBAAgB,CAAC,EAAE,MAAM,CAAC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AU,CAAC;GACT,4BAA4B,CAoExC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { ComponentOption, MaybePromise } from '@celljs/core';
|
|
2
|
+
export declare const AlipayClient: unique symbol;
|
|
3
|
+
export declare const ALIPAY_NOTIFICATION_HANDLER: unique symbol;
|
|
4
|
+
/** Before the body middleware: the endpoint reads the form itself, exactly as Alipay signed it. */
|
|
5
|
+
export declare const ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY: number;
|
|
6
|
+
/**
|
|
7
|
+
* `alipay` in cell.yml (server-only). Keys and certificates are PEM, base64 (as Alipay's tools give them) or the
|
|
8
|
+
* path of a file holding them. Give `alipayPublicKey` (public key mode, 公钥模式) or the three certificates (证书模式).
|
|
9
|
+
*/
|
|
10
|
+
export interface AlipayOptions {
|
|
11
|
+
appId: string;
|
|
12
|
+
/** Private key of the application (应用私钥), PKCS#8 or PKCS#1. */
|
|
13
|
+
privateKey: string;
|
|
14
|
+
/** Alipay's public key (支付宝公钥). */
|
|
15
|
+
alipayPublicKey?: string;
|
|
16
|
+
/** Certificate of the application (`appCertPublicKey_<appId>.crt`). */
|
|
17
|
+
appCert?: string;
|
|
18
|
+
/** Alipay's certificate (`alipayCertPublicKey_RSA2.crt`). */
|
|
19
|
+
alipayPublicCert?: string;
|
|
20
|
+
/** Alipay's root certificates (`alipayRootCert.crt`). */
|
|
21
|
+
alipayRootCert?: string;
|
|
22
|
+
/** Default `https://openapi.alipay.com/gateway.do`; the sandbox is `https://openapi-sandbox.dl.alipaydev.com/gateway.do`. */
|
|
23
|
+
gateway?: string;
|
|
24
|
+
/** Absolute URL of the notification endpoint, the default `notify_url`. */
|
|
25
|
+
notifyUrl?: string;
|
|
26
|
+
/** Milliseconds a request may take. Default 10000. */
|
|
27
|
+
timeout?: number;
|
|
28
|
+
notification?: {
|
|
29
|
+
/** Default true. */
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
/** Path of the endpoint. Default `/alipay/notify`. */
|
|
32
|
+
url?: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Common parameters a call can set besides `biz_content`. */
|
|
36
|
+
export interface AlipayRequestOptions {
|
|
37
|
+
notify_url?: string;
|
|
38
|
+
return_url?: string;
|
|
39
|
+
/** For a third-party application acting for a merchant (代调用). */
|
|
40
|
+
app_auth_token?: string;
|
|
41
|
+
/** Any other common parameter. */
|
|
42
|
+
[key: string]: string | undefined;
|
|
43
|
+
}
|
|
44
|
+
export interface AlipayPageOptions extends AlipayRequestOptions {
|
|
45
|
+
/** `GET` (default) gives a URL to redirect to; `POST` gives an HTML form that submits itself. */
|
|
46
|
+
httpMethod?: 'GET' | 'POST';
|
|
47
|
+
}
|
|
48
|
+
/** Fields of the API (snake_case, as in Alipay's documentation). `total_amount` is in yuan with two decimals: `'88.88'`. */
|
|
49
|
+
export interface AlipayTradeRequest {
|
|
50
|
+
out_trade_no: string;
|
|
51
|
+
total_amount: string;
|
|
52
|
+
subject: string;
|
|
53
|
+
body?: string;
|
|
54
|
+
product_code?: string;
|
|
55
|
+
/** Absolute (`2026-11-09 12:00:00`) or relative (`timeout_express: '30m'`). */
|
|
56
|
+
time_expire?: string;
|
|
57
|
+
timeout_express?: string;
|
|
58
|
+
passback_params?: string;
|
|
59
|
+
goods_detail?: Record<string, any>[];
|
|
60
|
+
extend_params?: Record<string, any>;
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
}
|
|
63
|
+
/** 电脑网站支付 (alipay.trade.page.pay); `product_code` defaults to `FAST_INSTANT_TRADE_PAY`. */
|
|
64
|
+
export interface AlipayPagePayRequest extends AlipayTradeRequest {
|
|
65
|
+
qr_pay_mode?: '0' | '1' | '2' | '3' | '4';
|
|
66
|
+
qrcode_width?: number;
|
|
67
|
+
}
|
|
68
|
+
/** 手机网站支付 (alipay.trade.wap.pay); `product_code` defaults to `QUICK_WAP_WAY`. */
|
|
69
|
+
export interface AlipayWapPayRequest extends AlipayTradeRequest {
|
|
70
|
+
quit_url?: string;
|
|
71
|
+
}
|
|
72
|
+
/** JSAPI / 小程序 (alipay.trade.create): the buyer is required. */
|
|
73
|
+
export interface AlipayCreateRequest extends AlipayTradeRequest {
|
|
74
|
+
buyer_id?: string;
|
|
75
|
+
buyer_open_id?: string;
|
|
76
|
+
op_app_id?: string;
|
|
77
|
+
}
|
|
78
|
+
export type AlipayTradeStatus = 'WAIT_BUYER_PAY' | 'TRADE_CLOSED' | 'TRADE_SUCCESS' | 'TRADE_FINISHED';
|
|
79
|
+
/** What every gateway answer has; `code` is `'10000'` for success (other answers are rejected with an `AlipayError`). */
|
|
80
|
+
export interface AlipayResponse {
|
|
81
|
+
code: string;
|
|
82
|
+
msg: string;
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
export interface AlipayTrade extends AlipayResponse {
|
|
86
|
+
trade_no: string;
|
|
87
|
+
out_trade_no: string;
|
|
88
|
+
buyer_logon_id?: string;
|
|
89
|
+
buyer_user_id?: string;
|
|
90
|
+
buyer_open_id?: string;
|
|
91
|
+
trade_status: AlipayTradeStatus;
|
|
92
|
+
total_amount: string;
|
|
93
|
+
receipt_amount?: string;
|
|
94
|
+
buyer_pay_amount?: string;
|
|
95
|
+
send_pay_date?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface AlipayTradeQuery {
|
|
98
|
+
out_trade_no?: string;
|
|
99
|
+
trade_no?: string;
|
|
100
|
+
query_options?: string[];
|
|
101
|
+
}
|
|
102
|
+
export interface AlipayRefundRequest {
|
|
103
|
+
out_trade_no?: string;
|
|
104
|
+
trade_no?: string;
|
|
105
|
+
refund_amount: string;
|
|
106
|
+
/** Required for partial refunds: identifies the refund, and makes retries safe. */
|
|
107
|
+
out_request_no?: string;
|
|
108
|
+
refund_reason?: string;
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
}
|
|
111
|
+
export interface AlipayRefund extends AlipayResponse {
|
|
112
|
+
trade_no: string;
|
|
113
|
+
out_trade_no: string;
|
|
114
|
+
buyer_logon_id?: string;
|
|
115
|
+
fund_change: 'Y' | 'N';
|
|
116
|
+
refund_fee: string;
|
|
117
|
+
}
|
|
118
|
+
export interface AlipayRefundQuery {
|
|
119
|
+
out_trade_no?: string;
|
|
120
|
+
trade_no?: string;
|
|
121
|
+
out_request_no: string;
|
|
122
|
+
query_options?: string[];
|
|
123
|
+
}
|
|
124
|
+
export type AlipayEventType = AlipayTradeStatus | (string & {});
|
|
125
|
+
/**
|
|
126
|
+
* An asynchronous notification whose signature was verified: the form fields as Alipay sent them
|
|
127
|
+
* (`trade_status`, `out_trade_no`, `trade_no`, `total_amount`, `refund_fee`...).
|
|
128
|
+
*/
|
|
129
|
+
export interface AlipayNotification {
|
|
130
|
+
notify_id: string;
|
|
131
|
+
notify_type: string;
|
|
132
|
+
notify_time: string;
|
|
133
|
+
app_id: string;
|
|
134
|
+
trade_status?: AlipayTradeStatus;
|
|
135
|
+
out_trade_no?: string;
|
|
136
|
+
trade_no?: string;
|
|
137
|
+
total_amount?: string;
|
|
138
|
+
[key: string]: string | undefined;
|
|
139
|
+
}
|
|
140
|
+
/** The Alipay OpenAPI gateway with the application of `alipay`: requests are signed and the signatures of answers verified. */
|
|
141
|
+
export interface AlipayClient {
|
|
142
|
+
/**
|
|
143
|
+
* Any API: `method` like `alipay.trade.query`, `biz` sent as `biz_content`. Resolves with the `<method>_response`
|
|
144
|
+
* object; rejects with an `AlipayError` (`CELL_ALIPAY_API_ERROR`) when its `code` is not `10000`.
|
|
145
|
+
*/
|
|
146
|
+
execute<T extends AlipayResponse = AlipayResponse>(method: string, biz?: object, options?: AlipayRequestOptions): Promise<T>;
|
|
147
|
+
/** A signed request the browser makes (page and WAP payments): a URL with `GET`, a self-submitting HTML form with `POST`. */
|
|
148
|
+
pageExecute(method: string, biz?: object, options?: AlipayPageOptions): string;
|
|
149
|
+
/** The signed order string the App SDK takes. */
|
|
150
|
+
sdkExecute(method: string, biz?: object, options?: AlipayRequestOptions): string;
|
|
151
|
+
/** 电脑网站支付: where to send the browser (or the form). */
|
|
152
|
+
pagePay(request: AlipayPagePayRequest, options?: AlipayPageOptions): string;
|
|
153
|
+
/** 手机网站支付: where to send the mobile browser (or the form). */
|
|
154
|
+
wapPay(request: AlipayWapPayRequest, options?: AlipayPageOptions): string;
|
|
155
|
+
/** App 支付: the order string for the App SDK. */
|
|
156
|
+
appPay(request: AlipayTradeRequest, options?: AlipayRequestOptions): string;
|
|
157
|
+
/** 当面付扫码 (alipay.trade.precreate): show `qr_code` as a QR code. */
|
|
158
|
+
precreate(request: AlipayTradeRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & {
|
|
159
|
+
out_trade_no: string;
|
|
160
|
+
qr_code: string;
|
|
161
|
+
}>;
|
|
162
|
+
/** JSAPI / 小程序 (alipay.trade.create): pass `trade_no` to `my.tradePay`. */
|
|
163
|
+
create(request: AlipayCreateRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & {
|
|
164
|
+
out_trade_no: string;
|
|
165
|
+
trade_no: string;
|
|
166
|
+
}>;
|
|
167
|
+
query(query: AlipayTradeQuery, options?: AlipayRequestOptions): Promise<AlipayTrade>;
|
|
168
|
+
close(query: {
|
|
169
|
+
out_trade_no?: string;
|
|
170
|
+
trade_no?: string;
|
|
171
|
+
operator_id?: string;
|
|
172
|
+
}, options?: AlipayRequestOptions): Promise<AlipayResponse>;
|
|
173
|
+
refund(request: AlipayRefundRequest, options?: AlipayRequestOptions): Promise<AlipayRefund>;
|
|
174
|
+
queryRefund(query: AlipayRefundQuery, options?: AlipayRequestOptions): Promise<AlipayResponse & {
|
|
175
|
+
refund_status?: 'REFUND_SUCCESS';
|
|
176
|
+
refund_amount?: string;
|
|
177
|
+
}>;
|
|
178
|
+
/** URL of a bill (alipay.data.dataservice.bill.downloadurl.query); `bill_date` is `2026-11-08` or `2026-11`. */
|
|
179
|
+
billDownloadUrl(query: {
|
|
180
|
+
bill_type: 'trade' | 'signcustomer';
|
|
181
|
+
bill_date: string;
|
|
182
|
+
}): Promise<AlipayResponse & {
|
|
183
|
+
bill_download_url: string;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* Verifies the signature of an asynchronous notification (the form fields, decoded) and that it is for this application.
|
|
187
|
+
* The notification endpoint does this; call it from a route of your own instead.
|
|
188
|
+
*/
|
|
189
|
+
verifyNotification(params: Record<string, string>): AlipayNotification;
|
|
190
|
+
}
|
|
191
|
+
/** Reacts to notifications; throwing makes the endpoint answer `fail`, and Alipay sends the notification again later. */
|
|
192
|
+
export interface AlipayNotificationHandler {
|
|
193
|
+
handle(notification: AlipayNotification): MaybePromise<void>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Makes the class a component that handles the notifications of the given trade statuses (`TRADE_SUCCESS`,
|
|
197
|
+
* `TRADE_CLOSED`...; the `notify_type` for notifications without one), all of them when there are none.
|
|
198
|
+
* Handlers must be idempotent: a notification can come more than once.
|
|
199
|
+
*/
|
|
200
|
+
export declare function AlipayNotificationHandler(eventTypes?: AlipayEventType | AlipayEventType[], option?: ComponentOption): ClassDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BODY_MIDDLEWARE_PRIORITY } from '@celljs/web/lib/node';
|
|
2
|
+
import { AlipayUtil } from './alipay-util.js';
|
|
3
|
+
export const AlipayClient = Symbol('AlipayClient');
|
|
4
|
+
export const ALIPAY_NOTIFICATION_HANDLER = Symbol('AlipayNotificationHandler');
|
|
5
|
+
/** Before the body middleware: the endpoint reads the form itself, exactly as Alipay signed it. */
|
|
6
|
+
export const ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY = BODY_MIDDLEWARE_PRIORITY + 50;
|
|
7
|
+
/**
|
|
8
|
+
* Makes the class a component that handles the notifications of the given trade statuses (`TRADE_SUCCESS`,
|
|
9
|
+
* `TRADE_CLOSED`...; the `notify_type` for notifications without one), all of them when there are none.
|
|
10
|
+
* Handlers must be idempotent: a notification can come more than once.
|
|
11
|
+
*/
|
|
12
|
+
export function AlipayNotificationHandler(eventTypes, option) {
|
|
13
|
+
return target => AlipayUtil.applyHandlerDecorator(target, ALIPAY_NOTIFICATION_HANDLER, eventTypes, option);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=alipay-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alipay-protocol.js","sourceRoot":"","sources":["../../src/node/alipay-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAE/E,mGAAmG;AACnG,MAAM,CAAC,MAAM,uCAAuC,GAAG,wBAAwB,GAAG,EAAE,CAAC;AAkMrF;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAgD,EAAE,MAAwB;IAChH,OAAO,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type KeyObject, X509Certificate } from 'node:crypto';
|
|
2
|
+
import { type ComponentId, type ComponentOption } from '@celljs/core';
|
|
3
|
+
/** The signatures (RSA2: SHA256 with RSA) and certificate serial numbers of the Alipay OpenAPI gateway, on Node's crypto. */
|
|
4
|
+
export declare namespace AlipayUtil {
|
|
5
|
+
/** The content of a key or certificate setting: PEM or base64 as it is, otherwise the file it names. */
|
|
6
|
+
function content(value: string): string;
|
|
7
|
+
/** A private key in PEM, or in base64 as Alipay's key tool gives it (PKCS#8 or PKCS#1). */
|
|
8
|
+
function privateKey(value: string | KeyObject): KeyObject;
|
|
9
|
+
/** A public key in PEM (a key or a certificate), or in base64 as Alipay shows it. */
|
|
10
|
+
function publicKey(value: string | KeyObject): KeyObject;
|
|
11
|
+
/** `yyyy-MM-dd HH:mm:ss` in Beijing time, as the gateway wants it. */
|
|
12
|
+
function timestamp(date?: Date): string;
|
|
13
|
+
/** `a=1&b=2`: the parameters sorted by name, without `sign`, `exclude` and empty values, not encoded. */
|
|
14
|
+
function signContent(params: Record<string, string | undefined>, exclude?: string[]): string;
|
|
15
|
+
/** RSA2 (SHA256 with RSA), base64. */
|
|
16
|
+
function signText(text: string, key: string | KeyObject): string;
|
|
17
|
+
function verifyText(text: string, signature: string, key: string | KeyObject): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The serial number Alipay gives a certificate (`app_cert_sn`, `alipay_cert_sn`): MD5 of the issuer, its attributes in
|
|
20
|
+
* reverse order joined with commas, followed by the decimal serial number.
|
|
21
|
+
*/
|
|
22
|
+
function certSn(pem: string | X509Certificate): string;
|
|
23
|
+
/** `alipay_root_cert_sn`: the serial numbers of the RSA certificates of the root certificate file, joined with `_`. */
|
|
24
|
+
function rootCertSn(pem: string): string;
|
|
25
|
+
/** The OID of the signature algorithm of a DER certificate: its second element (after tbsCertificate). */
|
|
26
|
+
function signatureOid(der: Uint8Array): string;
|
|
27
|
+
/**
|
|
28
|
+
* The JSON text of `key` in a gateway answer, exactly as sent: what its signature covers. Undefined when it is absent.
|
|
29
|
+
*/
|
|
30
|
+
function rawJson(text: string, key: string): string | undefined;
|
|
31
|
+
/** Registers the class as a component also bound to `id`, recording the event types it handles (`[]`: all). */
|
|
32
|
+
function applyHandlerDecorator(target: any, id: ComponentId, eventTypes: string | string[] | undefined, option?: ComponentOption): void;
|
|
33
|
+
/** The handlers by event type; `'*'` holds those of all types. */
|
|
34
|
+
function indexHandlers<H extends object>(handlers: H[]): Map<string, H[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign, verify, X509Certificate } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { Component, getTargetClass, parseComponentOption } from '@celljs/core';
|
|
4
|
+
const EVENT_TYPES = 'cell:alipay:event-types';
|
|
5
|
+
const CERTIFICATE = /-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g;
|
|
6
|
+
/** Signature algorithms of RSA (sha1WithRSAEncryption, sha256WithRSAEncryption...): the root certificates Alipay counts. */
|
|
7
|
+
const RSA_SIGNATURE = '1.2.840.113549.1.1.';
|
|
8
|
+
/** The signatures (RSA2: SHA256 with RSA) and certificate serial numbers of the Alipay OpenAPI gateway, on Node's crypto. */
|
|
9
|
+
export var AlipayUtil;
|
|
10
|
+
(function (AlipayUtil) {
|
|
11
|
+
/** The content of a key or certificate setting: PEM or base64 as it is, otherwise the file it names. */
|
|
12
|
+
function content(value) {
|
|
13
|
+
return !value.includes('-----BEGIN') && value.length < 1024 && existsSync(value) ? readFileSync(value, 'utf8') : value;
|
|
14
|
+
}
|
|
15
|
+
AlipayUtil.content = content;
|
|
16
|
+
/** A private key in PEM, or in base64 as Alipay's key tool gives it (PKCS#8 or PKCS#1). */
|
|
17
|
+
function privateKey(value) {
|
|
18
|
+
if (typeof value !== 'string') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
const text = content(value);
|
|
22
|
+
if (text.includes('-----BEGIN')) {
|
|
23
|
+
return createPrivateKey(text);
|
|
24
|
+
}
|
|
25
|
+
const der = Buffer.from(text.replace(/\s+/g, ''), 'base64');
|
|
26
|
+
try {
|
|
27
|
+
return createPrivateKey({ key: der, format: 'der', type: 'pkcs8' });
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return createPrivateKey({ key: der, format: 'der', type: 'pkcs1' });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
AlipayUtil.privateKey = privateKey;
|
|
34
|
+
/** A public key in PEM (a key or a certificate), or in base64 as Alipay shows it. */
|
|
35
|
+
function publicKey(value) {
|
|
36
|
+
if (typeof value !== 'string') {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
const text = content(value);
|
|
40
|
+
if (text.includes('-----BEGIN')) {
|
|
41
|
+
return createPublicKey(text);
|
|
42
|
+
}
|
|
43
|
+
return createPublicKey({ key: Buffer.from(text.replace(/\s+/g, ''), 'base64'), format: 'der', type: 'spki' });
|
|
44
|
+
}
|
|
45
|
+
AlipayUtil.publicKey = publicKey;
|
|
46
|
+
/** `yyyy-MM-dd HH:mm:ss` in Beijing time, as the gateway wants it. */
|
|
47
|
+
function timestamp(date = new Date()) {
|
|
48
|
+
return new Date(date.getTime() + 8 * 3600000).toISOString().slice(0, 19).replace('T', ' ');
|
|
49
|
+
}
|
|
50
|
+
AlipayUtil.timestamp = timestamp;
|
|
51
|
+
/** `a=1&b=2`: the parameters sorted by name, without `sign`, `exclude` and empty values, not encoded. */
|
|
52
|
+
function signContent(params, exclude = []) {
|
|
53
|
+
return Object.keys(params)
|
|
54
|
+
.filter(key => key !== 'sign' && !exclude.includes(key) && params[key] !== undefined && params[key] !== '')
|
|
55
|
+
.sort()
|
|
56
|
+
.map(key => `${key}=${params[key]}`)
|
|
57
|
+
.join('&');
|
|
58
|
+
}
|
|
59
|
+
AlipayUtil.signContent = signContent;
|
|
60
|
+
/** RSA2 (SHA256 with RSA), base64. */
|
|
61
|
+
function signText(text, key) {
|
|
62
|
+
return sign('sha256', Buffer.from(text), privateKey(key)).toString('base64');
|
|
63
|
+
}
|
|
64
|
+
AlipayUtil.signText = signText;
|
|
65
|
+
function verifyText(text, signature, key) {
|
|
66
|
+
try {
|
|
67
|
+
return verify('sha256', Buffer.from(text), publicKey(key), Buffer.from(signature, 'base64'));
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
AlipayUtil.verifyText = verifyText;
|
|
74
|
+
/**
|
|
75
|
+
* The serial number Alipay gives a certificate (`app_cert_sn`, `alipay_cert_sn`): MD5 of the issuer, its attributes in
|
|
76
|
+
* reverse order joined with commas, followed by the decimal serial number.
|
|
77
|
+
*/
|
|
78
|
+
function certSn(pem) {
|
|
79
|
+
const certificate = typeof pem === 'string' ? new X509Certificate(content(pem)) : pem;
|
|
80
|
+
const issuer = certificate.issuer.split('\n').reverse().join(',');
|
|
81
|
+
return createHash('md5')
|
|
82
|
+
.update(issuer + BigInt(`0x${certificate.serialNumber}`).toString(10))
|
|
83
|
+
.digest('hex');
|
|
84
|
+
}
|
|
85
|
+
AlipayUtil.certSn = certSn;
|
|
86
|
+
/** `alipay_root_cert_sn`: the serial numbers of the RSA certificates of the root certificate file, joined with `_`. */
|
|
87
|
+
function rootCertSn(pem) {
|
|
88
|
+
var _a;
|
|
89
|
+
return ((_a = content(pem).match(CERTIFICATE)) !== null && _a !== void 0 ? _a : [])
|
|
90
|
+
.map(text => new X509Certificate(text))
|
|
91
|
+
.filter(certificate => signatureOid(certificate.raw).startsWith(RSA_SIGNATURE))
|
|
92
|
+
.map(certificate => certSn(certificate))
|
|
93
|
+
.join('_');
|
|
94
|
+
}
|
|
95
|
+
AlipayUtil.rootCertSn = rootCertSn;
|
|
96
|
+
/** The OID of the signature algorithm of a DER certificate: its second element (after tbsCertificate). */
|
|
97
|
+
function signatureOid(der) {
|
|
98
|
+
const certificate = readTlv(der, 0);
|
|
99
|
+
const tbs = readTlv(der, certificate.start);
|
|
100
|
+
const algorithm = readTlv(der, tbs.end);
|
|
101
|
+
const oid = readTlv(der, algorithm.start);
|
|
102
|
+
const bytes = der.subarray(oid.start, oid.end);
|
|
103
|
+
const arcs = [Math.floor(bytes[0] / 40), bytes[0] % 40];
|
|
104
|
+
let value = 0;
|
|
105
|
+
for (const byte of bytes.subarray(1)) {
|
|
106
|
+
value = value * 128 + (byte & 0x7f);
|
|
107
|
+
if (!(byte & 0x80)) {
|
|
108
|
+
arcs.push(value);
|
|
109
|
+
value = 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return arcs.join('.');
|
|
113
|
+
}
|
|
114
|
+
AlipayUtil.signatureOid = signatureOid;
|
|
115
|
+
/**
|
|
116
|
+
* The JSON text of `key` in a gateway answer, exactly as sent: what its signature covers. Undefined when it is absent.
|
|
117
|
+
*/
|
|
118
|
+
function rawJson(text, key) {
|
|
119
|
+
const name = text.indexOf(`"${key}"`);
|
|
120
|
+
if (name < 0) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
let start = text.indexOf(':', name + key.length + 2) + 1;
|
|
124
|
+
while (/\s/.test(text[start])) {
|
|
125
|
+
start++;
|
|
126
|
+
}
|
|
127
|
+
if (text[start] !== '{') {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
let depth = 0;
|
|
131
|
+
let string = false;
|
|
132
|
+
for (let i = start; i < text.length; i++) {
|
|
133
|
+
const char = text[i];
|
|
134
|
+
if (string) {
|
|
135
|
+
if (char === '\\') {
|
|
136
|
+
i++;
|
|
137
|
+
}
|
|
138
|
+
else if (char === '"') {
|
|
139
|
+
string = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (char === '"') {
|
|
143
|
+
string = true;
|
|
144
|
+
}
|
|
145
|
+
else if (char === '{') {
|
|
146
|
+
depth++;
|
|
147
|
+
}
|
|
148
|
+
else if (char === '}' && --depth === 0) {
|
|
149
|
+
return text.slice(start, i + 1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
AlipayUtil.rawJson = rawJson;
|
|
155
|
+
/** Registers the class as a component also bound to `id`, recording the event types it handles (`[]`: all). */
|
|
156
|
+
function applyHandlerDecorator(target, id, eventTypes, option) {
|
|
157
|
+
const parsed = parseComponentOption(target, option);
|
|
158
|
+
parsed.id.push(id);
|
|
159
|
+
Reflect.defineMetadata(EVENT_TYPES, eventTypes === undefined ? [] : Array.isArray(eventTypes) ? eventTypes : [eventTypes], target);
|
|
160
|
+
Component(parsed)(target);
|
|
161
|
+
}
|
|
162
|
+
AlipayUtil.applyHandlerDecorator = applyHandlerDecorator;
|
|
163
|
+
/** The handlers by event type; `'*'` holds those of all types. */
|
|
164
|
+
function indexHandlers(handlers) {
|
|
165
|
+
var _a;
|
|
166
|
+
const result = new Map();
|
|
167
|
+
for (const handler of handlers) {
|
|
168
|
+
const types = Reflect.getOwnMetadata(EVENT_TYPES, getTargetClass(handler)) || [];
|
|
169
|
+
for (const type of types.length ? types : ['*']) {
|
|
170
|
+
result.set(type, [...((_a = result.get(type)) !== null && _a !== void 0 ? _a : []), handler]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
AlipayUtil.indexHandlers = indexHandlers;
|
|
176
|
+
})(AlipayUtil || (AlipayUtil = {}));
|
|
177
|
+
/** Where the content of the DER element at `offset` starts and ends. */
|
|
178
|
+
function readTlv(der, offset) {
|
|
179
|
+
let length = der[offset + 1];
|
|
180
|
+
let start = offset + 2;
|
|
181
|
+
if (length & 0x80) {
|
|
182
|
+
const bytes = length & 0x7f;
|
|
183
|
+
length = 0;
|
|
184
|
+
for (let i = 0; i < bytes; i++) {
|
|
185
|
+
length = length * 256 + der[start + i];
|
|
186
|
+
}
|
|
187
|
+
start += bytes;
|
|
188
|
+
}
|
|
189
|
+
return { start, end: start + length };
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=alipay-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alipay-util.js","sourceRoot":"","sources":["../../src/node/alipay-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAkB,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3H,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,SAAS,EAA0C,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAA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CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|