@celljs/alipay 0.0.0-stage → 4.4.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.
- 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,266 @@
|
|
|
1
|
+
import { type KeyObject, X509Certificate } from 'node:crypto';
|
|
2
|
+
import { Component, Value } from '@celljs/core';
|
|
3
|
+
import { AlipayError } from './alipay-error';
|
|
4
|
+
import {
|
|
5
|
+
AlipayClient,
|
|
6
|
+
type AlipayCreateRequest,
|
|
7
|
+
type AlipayNotification,
|
|
8
|
+
type AlipayOptions,
|
|
9
|
+
type AlipayPageOptions,
|
|
10
|
+
type AlipayPagePayRequest,
|
|
11
|
+
type AlipayRefund,
|
|
12
|
+
type AlipayRefundQuery,
|
|
13
|
+
type AlipayRefundRequest,
|
|
14
|
+
type AlipayRequestOptions,
|
|
15
|
+
type AlipayResponse,
|
|
16
|
+
type AlipayTrade,
|
|
17
|
+
type AlipayTradeQuery,
|
|
18
|
+
type AlipayTradeRequest,
|
|
19
|
+
type AlipayWapPayRequest,
|
|
20
|
+
} from './alipay-protocol';
|
|
21
|
+
import { AlipayUtil } from './alipay-util';
|
|
22
|
+
|
|
23
|
+
const SUCCESS = '10000';
|
|
24
|
+
|
|
25
|
+
interface Keys {
|
|
26
|
+
privateKey: KeyObject;
|
|
27
|
+
alipayPublicKey: KeyObject;
|
|
28
|
+
/** Certificate mode only. */
|
|
29
|
+
appCertSn?: string;
|
|
30
|
+
alipayCertSn?: string;
|
|
31
|
+
alipayRootCertSn?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Component(AlipayClient)
|
|
35
|
+
export class AlipayClientImpl implements AlipayClient {
|
|
36
|
+
@Value('alipay')
|
|
37
|
+
protected readonly options?: AlipayOptions;
|
|
38
|
+
|
|
39
|
+
protected loaded?: Keys;
|
|
40
|
+
|
|
41
|
+
async execute<T extends AlipayResponse = AlipayResponse>(method: string, biz?: object, options?: AlipayRequestOptions): Promise<T> {
|
|
42
|
+
const config = this.config();
|
|
43
|
+
const { biz_content, ...common } = this.params(method, biz, options);
|
|
44
|
+
const response = await fetch(`${this.gateway()}?${encode(common)}`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', Accept: 'application/json' },
|
|
47
|
+
body: biz_content === undefined ? undefined : encode({ biz_content }),
|
|
48
|
+
signal: AbortSignal.timeout(config.timeout ?? 10_000),
|
|
49
|
+
});
|
|
50
|
+
const text = await response.text();
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new AlipayError({
|
|
53
|
+
code: 'CELL_ALIPAY_HTTP_ERROR',
|
|
54
|
+
message: `The Alipay gateway answered ${response.status} to ${method}.`,
|
|
55
|
+
hint: 'Check alipay.gateway (production https://openapi.alipay.com/gateway.do, sandbox https://openapi-sandbox.dl.alipaydev.com/gateway.do).',
|
|
56
|
+
detail: { body: text.slice(0, 500) },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return this.answer<T>(method, text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
pageExecute(method: string, biz?: object, options: AlipayPageOptions = {}): string {
|
|
63
|
+
const { httpMethod, ...rest } = options;
|
|
64
|
+
const params = this.params(method, biz, rest);
|
|
65
|
+
if (httpMethod === 'POST') {
|
|
66
|
+
const inputs = Object.entries(params)
|
|
67
|
+
.map(([name, value]) => `<input type="hidden" name="${escapeHtml(name)}" value="${escapeHtml(value)}">`)
|
|
68
|
+
.join('');
|
|
69
|
+
return `<form id="alipay" action="${escapeHtml(this.gateway())}?charset=utf-8" method="post">${inputs}</form><script>document.getElementById('alipay').submit();</script>`;
|
|
70
|
+
}
|
|
71
|
+
return `${this.gateway()}?${encode(params)}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
sdkExecute(method: string, biz?: object, options?: AlipayRequestOptions): string {
|
|
75
|
+
return encode(this.params(method, biz, options));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pagePay(request: AlipayPagePayRequest, options?: AlipayPageOptions): string {
|
|
79
|
+
return this.pageExecute('alipay.trade.page.pay', { product_code: 'FAST_INSTANT_TRADE_PAY', ...request }, this.notify(options));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
wapPay(request: AlipayWapPayRequest, options?: AlipayPageOptions): string {
|
|
83
|
+
return this.pageExecute('alipay.trade.wap.pay', { product_code: 'QUICK_WAP_WAY', ...request }, this.notify(options));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
appPay(request: AlipayTradeRequest, options?: AlipayRequestOptions): string {
|
|
87
|
+
return this.sdkExecute('alipay.trade.app.pay', { product_code: 'QUICK_MSECURITY_PAY', ...request }, this.notify(options));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
precreate(request: AlipayTradeRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & { out_trade_no: string; qr_code: string }> {
|
|
91
|
+
return this.execute('alipay.trade.precreate', request, this.notify(options));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
create(request: AlipayCreateRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & { out_trade_no: string; trade_no: string }> {
|
|
95
|
+
return this.execute('alipay.trade.create', { product_code: 'JSAPI_PAY', ...request }, this.notify(options));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
query(query: AlipayTradeQuery, options?: AlipayRequestOptions): Promise<AlipayTrade> {
|
|
99
|
+
return this.execute('alipay.trade.query', query, options);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
close(query: { out_trade_no?: string; trade_no?: string; operator_id?: string }, options?: AlipayRequestOptions): Promise<AlipayResponse> {
|
|
103
|
+
return this.execute('alipay.trade.close', query, options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
refund(request: AlipayRefundRequest, options?: AlipayRequestOptions): Promise<AlipayRefund> {
|
|
107
|
+
return this.execute('alipay.trade.refund', request, options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
queryRefund(
|
|
111
|
+
query: AlipayRefundQuery,
|
|
112
|
+
options?: AlipayRequestOptions,
|
|
113
|
+
): Promise<AlipayResponse & { refund_status?: 'REFUND_SUCCESS'; refund_amount?: string }> {
|
|
114
|
+
return this.execute('alipay.trade.fastpay.refund.query', query, options);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
billDownloadUrl(query: { bill_type: 'trade' | 'signcustomer'; bill_date: string }): Promise<AlipayResponse & { bill_download_url: string }> {
|
|
118
|
+
return this.execute('alipay.data.dataservice.bill.downloadurl.query', query);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
verifyNotification(params: Record<string, string>): AlipayNotification {
|
|
122
|
+
const keys = this.keys();
|
|
123
|
+
if (!params.sign || !AlipayUtil.verifyText(AlipayUtil.signContent(params, ['sign_type']), params.sign, keys.alipayPublicKey)) {
|
|
124
|
+
throw this.invalidSignature('The signature of the notification does not match.');
|
|
125
|
+
}
|
|
126
|
+
if (params.app_id !== this.config().appId) {
|
|
127
|
+
throw new AlipayError({
|
|
128
|
+
code: 'CELL_ALIPAY_APP_ID_MISMATCH',
|
|
129
|
+
message: `The notification is for the application ${params.app_id}, not ${this.config().appId}.`,
|
|
130
|
+
hint: 'Give each application its own notify_url, or check alipay.appId.',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return params as AlipayNotification;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The configuration; throws when the application is not configured. */
|
|
137
|
+
protected config(): AlipayOptions {
|
|
138
|
+
const options = this.options;
|
|
139
|
+
const missing = (['appId', 'privateKey'] as const).filter(key => !options?.[key]);
|
|
140
|
+
const certificates = [options?.appCert, options?.alipayPublicCert, options?.alipayRootCert].filter(Boolean).length;
|
|
141
|
+
if (missing.length || (certificates > 0 && certificates < 3) || (!certificates && !options?.alipayPublicKey)) {
|
|
142
|
+
throw new AlipayError({
|
|
143
|
+
code: 'CELL_ALIPAY_NOT_CONFIGURED',
|
|
144
|
+
message: missing.length
|
|
145
|
+
? `alipay is missing ${missing.join(', ')}.`
|
|
146
|
+
: 'alipay needs alipayPublicKey (public key mode) or all of appCert, alipayPublicCert and alipayRootCert (certificate mode).',
|
|
147
|
+
hint: 'Set them under alipay in cell.yml, from the environment: privateKey: ${env.ALIPAY_PRIVATE_KEY}; a key or certificate can also be the path of its file.',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return options as AlipayOptions;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected keys(): Keys {
|
|
154
|
+
if (!this.loaded) {
|
|
155
|
+
const { privateKey, alipayPublicKey, appCert, alipayPublicCert, alipayRootCert } = this.config();
|
|
156
|
+
if (appCert && alipayPublicCert && alipayRootCert) {
|
|
157
|
+
const alipayCert = new X509Certificate(AlipayUtil.content(alipayPublicCert));
|
|
158
|
+
this.loaded = {
|
|
159
|
+
privateKey: AlipayUtil.privateKey(privateKey),
|
|
160
|
+
alipayPublicKey: alipayCert.publicKey,
|
|
161
|
+
appCertSn: AlipayUtil.certSn(appCert),
|
|
162
|
+
alipayCertSn: AlipayUtil.certSn(alipayCert),
|
|
163
|
+
alipayRootCertSn: AlipayUtil.rootCertSn(alipayRootCert),
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
166
|
+
this.loaded = { privateKey: AlipayUtil.privateKey(privateKey), alipayPublicKey: AlipayUtil.publicKey(alipayPublicKey as string) };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return this.loaded;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
protected gateway(): string {
|
|
173
|
+
return this.config().gateway ?? 'https://openapi.alipay.com/gateway.do';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected notify<O extends AlipayRequestOptions>(options?: O): O {
|
|
177
|
+
const notifyUrl = options?.notify_url ?? this.options?.notifyUrl;
|
|
178
|
+
return { ...options, notify_url: notifyUrl } as O;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The common parameters, `biz_content` and `sign`. */
|
|
182
|
+
protected params(method: string, biz?: object, options?: AlipayRequestOptions): Record<string, string> {
|
|
183
|
+
const config = this.config();
|
|
184
|
+
const keys = this.keys();
|
|
185
|
+
const params: Record<string, string | undefined> = {
|
|
186
|
+
app_id: config.appId,
|
|
187
|
+
method,
|
|
188
|
+
format: 'JSON',
|
|
189
|
+
charset: 'utf-8',
|
|
190
|
+
sign_type: 'RSA2',
|
|
191
|
+
timestamp: AlipayUtil.timestamp(),
|
|
192
|
+
version: '1.0',
|
|
193
|
+
app_cert_sn: keys.appCertSn,
|
|
194
|
+
alipay_root_cert_sn: keys.alipayRootCertSn,
|
|
195
|
+
...options,
|
|
196
|
+
biz_content: biz === undefined ? undefined : JSON.stringify(biz),
|
|
197
|
+
};
|
|
198
|
+
const result: Record<string, string> = {};
|
|
199
|
+
for (const [key, value] of Object.entries(params)) {
|
|
200
|
+
if (value !== undefined && value !== '') {
|
|
201
|
+
result[key] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
result.sign = AlipayUtil.signText(AlipayUtil.signContent(result), keys.privateKey);
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The `<method>_response` of a gateway answer, after checking its signature and its code. */
|
|
209
|
+
protected answer<T>(method: string, text: string): T {
|
|
210
|
+
const key = `${method.replace(/\./g, '_')}_response`;
|
|
211
|
+
let json: Record<string, any>;
|
|
212
|
+
try {
|
|
213
|
+
json = JSON.parse(text);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw new AlipayError({
|
|
216
|
+
code: 'CELL_ALIPAY_HTTP_ERROR',
|
|
217
|
+
message: `The answer of the Alipay gateway to ${method} is not JSON.`,
|
|
218
|
+
hint: 'Check alipay.gateway: it must be the gateway.do URL of Alipay.',
|
|
219
|
+
detail: { body: text.slice(0, 500) },
|
|
220
|
+
cause: error,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const name = json[key] ? key : 'error_response';
|
|
224
|
+
const node = json[name];
|
|
225
|
+
const keys = this.keys();
|
|
226
|
+
if (json.sign) {
|
|
227
|
+
const raw = AlipayUtil.rawJson(text, name);
|
|
228
|
+
if (!raw || !AlipayUtil.verifyText(raw, json.sign, keys.alipayPublicKey)) {
|
|
229
|
+
throw this.invalidSignature(`The signature of the answer to ${method} does not match.`);
|
|
230
|
+
}
|
|
231
|
+
if (json.alipay_cert_sn && keys.alipayCertSn && json.alipay_cert_sn !== keys.alipayCertSn) {
|
|
232
|
+
throw this.invalidSignature(`The answer to ${method} is signed with the Alipay certificate ${json.alipay_cert_sn}, not the configured one.`);
|
|
233
|
+
}
|
|
234
|
+
} else if (node?.code === SUCCESS) {
|
|
235
|
+
throw this.invalidSignature(`The answer to ${method} is not signed.`);
|
|
236
|
+
}
|
|
237
|
+
if (node?.code !== SUCCESS) {
|
|
238
|
+
throw new AlipayError({
|
|
239
|
+
code: 'CELL_ALIPAY_API_ERROR',
|
|
240
|
+
message: `Alipay answered ${method} with ${node?.code} ${node?.msg}: ${node?.sub_code ?? ''} ${node?.sub_msg ?? ''}`.trim(),
|
|
241
|
+
hint: "detail.sub_code is Alipay's error code; look it up in the documentation of the API (opendocs.alipay.com).",
|
|
242
|
+
detail: node,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return node as T;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
protected invalidSignature(message: string): AlipayError {
|
|
249
|
+
return new AlipayError({
|
|
250
|
+
code: 'CELL_ALIPAY_SIGNATURE_INVALID',
|
|
251
|
+
message,
|
|
252
|
+
hint: "Set alipay.alipayPublicKey to Alipay's public key (not the application's), or update alipayPublicCert when Alipay changed its certificate.",
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** `a=1&b=x%20y`: spaces as %20, as the gateway expects. */
|
|
258
|
+
function encode(params: Record<string, string>): string {
|
|
259
|
+
return Object.entries(params)
|
|
260
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
261
|
+
.join('&');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function escapeHtml(value: string): string {
|
|
265
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
266
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failure of Alipay or of its configuration. `code` is stable and `hint` says how to fix it in one sentence
|
|
3
|
+
* (docs/design/agent-first.md R5).
|
|
4
|
+
*/
|
|
5
|
+
export class AlipayError extends Error {
|
|
6
|
+
override readonly name = 'AlipayError';
|
|
7
|
+
readonly code: AlipayError.Code;
|
|
8
|
+
readonly hint: string;
|
|
9
|
+
/** Alipay's answer, for `CELL_ALIPAY_API_ERROR`: `{ code: '40004', msg, sub_code: 'ACQ.TRADE_NOT_EXIST', sub_msg }`. */
|
|
10
|
+
readonly detail?: { code?: string; msg?: string; sub_code?: string; sub_msg?: string; [key: string]: any };
|
|
11
|
+
|
|
12
|
+
constructor(options: { code: AlipayError.Code; message: string; hint: string; detail?: AlipayError['detail']; cause?: unknown }) {
|
|
13
|
+
super(options.message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.hint = options.hint;
|
|
16
|
+
this.detail = options.detail;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export namespace AlipayError {
|
|
21
|
+
export type Code =
|
|
22
|
+
| 'CELL_ALIPAY_NOT_CONFIGURED'
|
|
23
|
+
| 'CELL_ALIPAY_API_ERROR'
|
|
24
|
+
| 'CELL_ALIPAY_HTTP_ERROR'
|
|
25
|
+
| 'CELL_ALIPAY_SIGNATURE_INVALID'
|
|
26
|
+
| 'CELL_ALIPAY_APP_ID_MISMATCH';
|
|
27
|
+
|
|
28
|
+
export function is(error: unknown, code?: Code): error is AlipayError {
|
|
29
|
+
return error instanceof AlipayError && (code === undefined || error.code === code);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Autowired, AutowiredProvider, Component, Logger, type Provider, Value } from '@celljs/core';
|
|
2
|
+
import { HttpHeaders, MediaType } from '@celljs/http';
|
|
3
|
+
import { PathResolver } from '@celljs/web';
|
|
4
|
+
import { type BodyOptions, BodyParser, type Context, Middleware, RequestMatcher } from '@celljs/web/lib/node';
|
|
5
|
+
import { AlipayError } from './alipay-error';
|
|
6
|
+
import {
|
|
7
|
+
ALIPAY_NOTIFICATION_HANDLER,
|
|
8
|
+
ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY,
|
|
9
|
+
AlipayClient,
|
|
10
|
+
type AlipayNotification,
|
|
11
|
+
type AlipayNotificationHandler,
|
|
12
|
+
type AlipayOptions,
|
|
13
|
+
} from './alipay-protocol';
|
|
14
|
+
import { AlipayUtil } from './alipay-util';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The notification endpoint (`POST alipay.notification.url`): verifies the signature of the form and runs the
|
|
18
|
+
* `@AlipayNotificationHandler` components of its `trade_status`. It answers `success` when they succeed and `fail`
|
|
19
|
+
* otherwise (400 for a bad signature, 500 when a handler throws), so that Alipay sends the notification again.
|
|
20
|
+
*/
|
|
21
|
+
@Component(Middleware)
|
|
22
|
+
export class AlipayNotificationMiddleware implements Middleware {
|
|
23
|
+
@Autowired(AlipayClient)
|
|
24
|
+
protected readonly client: AlipayClient;
|
|
25
|
+
|
|
26
|
+
@AutowiredProvider(ALIPAY_NOTIFICATION_HANDLER)
|
|
27
|
+
protected readonly handlerProvider: Provider<AlipayNotificationHandler>;
|
|
28
|
+
|
|
29
|
+
@Autowired(RequestMatcher)
|
|
30
|
+
protected readonly requestMatcher: RequestMatcher;
|
|
31
|
+
|
|
32
|
+
@Autowired(PathResolver)
|
|
33
|
+
protected readonly pathResolver: PathResolver;
|
|
34
|
+
|
|
35
|
+
@Autowired(Logger)
|
|
36
|
+
protected readonly logger: Logger;
|
|
37
|
+
|
|
38
|
+
@Value('alipay')
|
|
39
|
+
protected readonly options?: AlipayOptions;
|
|
40
|
+
|
|
41
|
+
@Value('web.body')
|
|
42
|
+
protected readonly bodyOptions?: BodyOptions;
|
|
43
|
+
|
|
44
|
+
readonly priority = ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY;
|
|
45
|
+
|
|
46
|
+
protected handlers?: Map<string, AlipayNotificationHandler[]>;
|
|
47
|
+
protected parser?: BodyParser;
|
|
48
|
+
|
|
49
|
+
async handle(ctx: Context, next: () => Promise<void>): Promise<void> {
|
|
50
|
+
const notification = this.options?.notification;
|
|
51
|
+
if (
|
|
52
|
+
ctx.request.method !== 'POST' ||
|
|
53
|
+
notification?.enabled === false ||
|
|
54
|
+
!(await this.requestMatcher.match(await this.pathResolver.resolve(notification?.url ?? '/alipay/notify'), 'POST'))
|
|
55
|
+
) {
|
|
56
|
+
return next();
|
|
57
|
+
}
|
|
58
|
+
let status = 200;
|
|
59
|
+
try {
|
|
60
|
+
this.parser ??= new BodyParser(this.bodyOptions);
|
|
61
|
+
const body = await this.parser.raw(ctx.request);
|
|
62
|
+
const params = Object.fromEntries(new URLSearchParams(body.toString('utf8')));
|
|
63
|
+
await this.dispatch(this.client.verifyNotification(params));
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const refused = AlipayError.is(error, 'CELL_ALIPAY_SIGNATURE_INVALID') || AlipayError.is(error, 'CELL_ALIPAY_APP_ID_MISMATCH');
|
|
66
|
+
if (refused) {
|
|
67
|
+
this.logger.warn(`Alipay notification refused: ${(error as Error).message}`);
|
|
68
|
+
} else {
|
|
69
|
+
this.logger.error(error);
|
|
70
|
+
}
|
|
71
|
+
status = refused ? 400 : 500;
|
|
72
|
+
}
|
|
73
|
+
ctx.response.statusCode = status;
|
|
74
|
+
ctx.response.setHeader(HttpHeaders.CONTENT_TYPE, `${MediaType.TEXT_PLAIN};charset=UTF-8`);
|
|
75
|
+
ctx.response.end(status === 200 ? 'success' : 'fail');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected async dispatch(notification: AlipayNotification): Promise<void> {
|
|
79
|
+
this.handlers ??= AlipayUtil.indexHandlers(this.handlerProvider.get());
|
|
80
|
+
const type = notification.trade_status ?? notification.notify_type;
|
|
81
|
+
const handlers = [...(this.handlers.get(type) ?? []), ...(this.handlers.get('*') ?? [])];
|
|
82
|
+
if (!handlers.length) {
|
|
83
|
+
this.logger.warn(`No @AlipayNotificationHandler for ${type}; notification ${notification.notify_id} acknowledged.`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const handler of handlers) {
|
|
87
|
+
await handler.handle(notification);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { ComponentOption, MaybePromise } from '@celljs/core';
|
|
2
|
+
import { BODY_MIDDLEWARE_PRIORITY } from '@celljs/web/lib/node';
|
|
3
|
+
import { AlipayUtil } from './alipay-util';
|
|
4
|
+
|
|
5
|
+
export const AlipayClient = Symbol('AlipayClient');
|
|
6
|
+
export const ALIPAY_NOTIFICATION_HANDLER = Symbol('AlipayNotificationHandler');
|
|
7
|
+
|
|
8
|
+
/** Before the body middleware: the endpoint reads the form itself, exactly as Alipay signed it. */
|
|
9
|
+
export const ALIPAY_NOTIFICATION_MIDDLEWARE_PRIORITY = BODY_MIDDLEWARE_PRIORITY + 50;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `alipay` in cell.yml (server-only). Keys and certificates are PEM, base64 (as Alipay's tools give them) or the
|
|
13
|
+
* path of a file holding them. Give `alipayPublicKey` (public key mode, 公钥模式) or the three certificates (证书模式).
|
|
14
|
+
*/
|
|
15
|
+
export interface AlipayOptions {
|
|
16
|
+
appId: string;
|
|
17
|
+
/** Private key of the application (应用私钥), PKCS#8 or PKCS#1. */
|
|
18
|
+
privateKey: string;
|
|
19
|
+
/** Alipay's public key (支付宝公钥). */
|
|
20
|
+
alipayPublicKey?: string;
|
|
21
|
+
/** Certificate of the application (`appCertPublicKey_<appId>.crt`). */
|
|
22
|
+
appCert?: string;
|
|
23
|
+
/** Alipay's certificate (`alipayCertPublicKey_RSA2.crt`). */
|
|
24
|
+
alipayPublicCert?: string;
|
|
25
|
+
/** Alipay's root certificates (`alipayRootCert.crt`). */
|
|
26
|
+
alipayRootCert?: string;
|
|
27
|
+
/** Default `https://openapi.alipay.com/gateway.do`; the sandbox is `https://openapi-sandbox.dl.alipaydev.com/gateway.do`. */
|
|
28
|
+
gateway?: string;
|
|
29
|
+
/** Absolute URL of the notification endpoint, the default `notify_url`. */
|
|
30
|
+
notifyUrl?: string;
|
|
31
|
+
/** Milliseconds a request may take. Default 10000. */
|
|
32
|
+
timeout?: number;
|
|
33
|
+
notification?: {
|
|
34
|
+
/** Default true. */
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
/** Path of the endpoint. Default `/alipay/notify`. */
|
|
37
|
+
url?: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Common parameters a call can set besides `biz_content`. */
|
|
42
|
+
export interface AlipayRequestOptions {
|
|
43
|
+
notify_url?: string;
|
|
44
|
+
return_url?: string;
|
|
45
|
+
/** For a third-party application acting for a merchant (代调用). */
|
|
46
|
+
app_auth_token?: string;
|
|
47
|
+
/** Any other common parameter. */
|
|
48
|
+
[key: string]: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AlipayPageOptions extends AlipayRequestOptions {
|
|
52
|
+
/** `GET` (default) gives a URL to redirect to; `POST` gives an HTML form that submits itself. */
|
|
53
|
+
httpMethod?: 'GET' | 'POST';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Fields of the API (snake_case, as in Alipay's documentation). `total_amount` is in yuan with two decimals: `'88.88'`. */
|
|
57
|
+
export interface AlipayTradeRequest {
|
|
58
|
+
out_trade_no: string;
|
|
59
|
+
total_amount: string;
|
|
60
|
+
subject: string;
|
|
61
|
+
body?: string;
|
|
62
|
+
product_code?: string;
|
|
63
|
+
/** Absolute (`2026-11-09 12:00:00`) or relative (`timeout_express: '30m'`). */
|
|
64
|
+
time_expire?: string;
|
|
65
|
+
timeout_express?: string;
|
|
66
|
+
passback_params?: string;
|
|
67
|
+
goods_detail?: Record<string, any>[];
|
|
68
|
+
extend_params?: Record<string, any>;
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 电脑网站支付 (alipay.trade.page.pay); `product_code` defaults to `FAST_INSTANT_TRADE_PAY`. */
|
|
73
|
+
export interface AlipayPagePayRequest extends AlipayTradeRequest {
|
|
74
|
+
qr_pay_mode?: '0' | '1' | '2' | '3' | '4';
|
|
75
|
+
qrcode_width?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 手机网站支付 (alipay.trade.wap.pay); `product_code` defaults to `QUICK_WAP_WAY`. */
|
|
79
|
+
export interface AlipayWapPayRequest extends AlipayTradeRequest {
|
|
80
|
+
quit_url?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** JSAPI / 小程序 (alipay.trade.create): the buyer is required. */
|
|
84
|
+
export interface AlipayCreateRequest extends AlipayTradeRequest {
|
|
85
|
+
buyer_id?: string;
|
|
86
|
+
buyer_open_id?: string;
|
|
87
|
+
op_app_id?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type AlipayTradeStatus = 'WAIT_BUYER_PAY' | 'TRADE_CLOSED' | 'TRADE_SUCCESS' | 'TRADE_FINISHED';
|
|
91
|
+
|
|
92
|
+
/** What every gateway answer has; `code` is `'10000'` for success (other answers are rejected with an `AlipayError`). */
|
|
93
|
+
export interface AlipayResponse {
|
|
94
|
+
code: string;
|
|
95
|
+
msg: string;
|
|
96
|
+
[key: string]: any;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AlipayTrade extends AlipayResponse {
|
|
100
|
+
trade_no: string;
|
|
101
|
+
out_trade_no: string;
|
|
102
|
+
buyer_logon_id?: string;
|
|
103
|
+
buyer_user_id?: string;
|
|
104
|
+
buyer_open_id?: string;
|
|
105
|
+
trade_status: AlipayTradeStatus;
|
|
106
|
+
total_amount: string;
|
|
107
|
+
receipt_amount?: string;
|
|
108
|
+
buyer_pay_amount?: string;
|
|
109
|
+
send_pay_date?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface AlipayTradeQuery {
|
|
113
|
+
out_trade_no?: string;
|
|
114
|
+
trade_no?: string;
|
|
115
|
+
query_options?: string[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface AlipayRefundRequest {
|
|
119
|
+
out_trade_no?: string;
|
|
120
|
+
trade_no?: string;
|
|
121
|
+
refund_amount: string;
|
|
122
|
+
/** Required for partial refunds: identifies the refund, and makes retries safe. */
|
|
123
|
+
out_request_no?: string;
|
|
124
|
+
refund_reason?: string;
|
|
125
|
+
[key: string]: any;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface AlipayRefund extends AlipayResponse {
|
|
129
|
+
trade_no: string;
|
|
130
|
+
out_trade_no: string;
|
|
131
|
+
buyer_logon_id?: string;
|
|
132
|
+
fund_change: 'Y' | 'N';
|
|
133
|
+
refund_fee: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface AlipayRefundQuery {
|
|
137
|
+
out_trade_no?: string;
|
|
138
|
+
trade_no?: string;
|
|
139
|
+
out_request_no: string;
|
|
140
|
+
query_options?: string[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type AlipayEventType = AlipayTradeStatus | (string & {});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* An asynchronous notification whose signature was verified: the form fields as Alipay sent them
|
|
147
|
+
* (`trade_status`, `out_trade_no`, `trade_no`, `total_amount`, `refund_fee`...).
|
|
148
|
+
*/
|
|
149
|
+
export interface AlipayNotification {
|
|
150
|
+
notify_id: string;
|
|
151
|
+
notify_type: string;
|
|
152
|
+
notify_time: string;
|
|
153
|
+
app_id: string;
|
|
154
|
+
trade_status?: AlipayTradeStatus;
|
|
155
|
+
out_trade_no?: string;
|
|
156
|
+
trade_no?: string;
|
|
157
|
+
total_amount?: string;
|
|
158
|
+
[key: string]: string | undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The Alipay OpenAPI gateway with the application of `alipay`: requests are signed and the signatures of answers verified. */
|
|
162
|
+
export interface AlipayClient {
|
|
163
|
+
/**
|
|
164
|
+
* Any API: `method` like `alipay.trade.query`, `biz` sent as `biz_content`. Resolves with the `<method>_response`
|
|
165
|
+
* object; rejects with an `AlipayError` (`CELL_ALIPAY_API_ERROR`) when its `code` is not `10000`.
|
|
166
|
+
*/
|
|
167
|
+
execute<T extends AlipayResponse = AlipayResponse>(method: string, biz?: object, options?: AlipayRequestOptions): Promise<T>;
|
|
168
|
+
/** A signed request the browser makes (page and WAP payments): a URL with `GET`, a self-submitting HTML form with `POST`. */
|
|
169
|
+
pageExecute(method: string, biz?: object, options?: AlipayPageOptions): string;
|
|
170
|
+
/** The signed order string the App SDK takes. */
|
|
171
|
+
sdkExecute(method: string, biz?: object, options?: AlipayRequestOptions): string;
|
|
172
|
+
/** 电脑网站支付: where to send the browser (or the form). */
|
|
173
|
+
pagePay(request: AlipayPagePayRequest, options?: AlipayPageOptions): string;
|
|
174
|
+
/** 手机网站支付: where to send the mobile browser (or the form). */
|
|
175
|
+
wapPay(request: AlipayWapPayRequest, options?: AlipayPageOptions): string;
|
|
176
|
+
/** App 支付: the order string for the App SDK. */
|
|
177
|
+
appPay(request: AlipayTradeRequest, options?: AlipayRequestOptions): string;
|
|
178
|
+
/** 当面付扫码 (alipay.trade.precreate): show `qr_code` as a QR code. */
|
|
179
|
+
precreate(request: AlipayTradeRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & { out_trade_no: string; qr_code: string }>;
|
|
180
|
+
/** JSAPI / 小程序 (alipay.trade.create): pass `trade_no` to `my.tradePay`. */
|
|
181
|
+
create(request: AlipayCreateRequest, options?: AlipayRequestOptions): Promise<AlipayResponse & { out_trade_no: string; trade_no: string }>;
|
|
182
|
+
query(query: AlipayTradeQuery, options?: AlipayRequestOptions): Promise<AlipayTrade>;
|
|
183
|
+
close(query: { out_trade_no?: string; trade_no?: string; operator_id?: string }, options?: AlipayRequestOptions): Promise<AlipayResponse>;
|
|
184
|
+
refund(request: AlipayRefundRequest, options?: AlipayRequestOptions): Promise<AlipayRefund>;
|
|
185
|
+
queryRefund(
|
|
186
|
+
query: AlipayRefundQuery,
|
|
187
|
+
options?: AlipayRequestOptions,
|
|
188
|
+
): Promise<AlipayResponse & { refund_status?: 'REFUND_SUCCESS'; refund_amount?: string }>;
|
|
189
|
+
/** URL of a bill (alipay.data.dataservice.bill.downloadurl.query); `bill_date` is `2026-11-08` or `2026-11`. */
|
|
190
|
+
billDownloadUrl(query: { bill_type: 'trade' | 'signcustomer'; bill_date: string }): Promise<AlipayResponse & { bill_download_url: string }>;
|
|
191
|
+
/**
|
|
192
|
+
* Verifies the signature of an asynchronous notification (the form fields, decoded) and that it is for this application.
|
|
193
|
+
* The notification endpoint does this; call it from a route of your own instead.
|
|
194
|
+
*/
|
|
195
|
+
verifyNotification(params: Record<string, string>): AlipayNotification;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Reacts to notifications; throwing makes the endpoint answer `fail`, and Alipay sends the notification again later. */
|
|
199
|
+
export interface AlipayNotificationHandler {
|
|
200
|
+
handle(notification: AlipayNotification): MaybePromise<void>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Makes the class a component that handles the notifications of the given trade statuses (`TRADE_SUCCESS`,
|
|
205
|
+
* `TRADE_CLOSED`...; the `notify_type` for notifications without one), all of them when there are none.
|
|
206
|
+
* Handlers must be idempotent: a notification can come more than once.
|
|
207
|
+
*/
|
|
208
|
+
export function AlipayNotificationHandler(eventTypes?: AlipayEventType | AlipayEventType[], option?: ComponentOption): ClassDecorator {
|
|
209
|
+
return target => AlipayUtil.applyHandlerDecorator(target, ALIPAY_NOTIFICATION_HANDLER, eventTypes, option);
|
|
210
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { createHash, generateKeyPairSync, X509Certificate } from 'node:crypto';
|
|
3
|
+
import { AlipayUtil } from './alipay-util';
|
|
4
|
+
import { OFFICIAL_ALIPAY_CERT, OFFICIAL_APP_CERT, OFFICIAL_ROOT_CERT, TEST_APP_CERT, TEST_ROOT_CERT } from './test/fixtures';
|
|
5
|
+
|
|
6
|
+
describe('AlipayUtil', () => {
|
|
7
|
+
it("gives the certificate serial numbers that Alipay's SDK gives", () => {
|
|
8
|
+
expect(AlipayUtil.certSn(OFFICIAL_APP_CERT)).toBe('866efef280dec9137a87d047ac446315');
|
|
9
|
+
expect(AlipayUtil.certSn(OFFICIAL_ALIPAY_CERT)).toBe('7513daaaa48aa3ba2e4018d84402479c');
|
|
10
|
+
expect(AlipayUtil.rootCertSn(OFFICIAL_ROOT_CERT)).toBe('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('hashes the issuer in reverse order with the decimal serial number, and skips the EC roots', () => {
|
|
14
|
+
const issuer = 'CN=Cell Test Root CA,OU=Certification Authority,O=Cell Test,C=CN';
|
|
15
|
+
const md5 = (text: string) => createHash('md5').update(text).digest('hex');
|
|
16
|
+
expect(AlipayUtil.certSn(TEST_APP_CERT)).toBe(md5(issuer + BigInt('0xD561B13397456FB0').toString(10)));
|
|
17
|
+
expect(AlipayUtil.rootCertSn(TEST_ROOT_CERT)).toBe(md5(issuer + BigInt('0x10DF4AE67285F4F974067BCD281D856E9D7FAE8C').toString(10)));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('reads the OID of the signature algorithm of a certificate', () => {
|
|
21
|
+
const [rsa, ec] = (TEST_ROOT_CERT.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g) ?? []).map(
|
|
22
|
+
pem => new X509Certificate(pem).raw,
|
|
23
|
+
);
|
|
24
|
+
expect(AlipayUtil.signatureOid(rsa)).toBe('1.2.840.113549.1.1.11');
|
|
25
|
+
expect(AlipayUtil.signatureOid(ec)).toBe('1.2.840.10045.4.3.2');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('sorts the parameters, leaving out sign, empty values and the excluded ones', () => {
|
|
29
|
+
expect(AlipayUtil.signContent({ b: '2', a: '1', sign: 'x', sign_type: 'RSA2', c: '', d: undefined })).toBe('a=1&b=2&sign_type=RSA2');
|
|
30
|
+
expect(AlipayUtil.signContent({ b: '2 3', a: '中文', sign_type: 'RSA2' }, ['sign_type'])).toBe('a=中文&b=2 3');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('formats timestamps in Beijing time', () => {
|
|
34
|
+
expect(AlipayUtil.timestamp(new Date('2026-11-09T16:30:05Z'))).toBe('2026-11-10 00:30:05');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('reads keys in PEM and in base64, PKCS#8 and PKCS#1', () => {
|
|
38
|
+
const { privateKey, publicKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });
|
|
39
|
+
const pkcs1 = privateKey.export({ type: 'pkcs1', format: 'der' }).toString('base64');
|
|
40
|
+
const pkcs8 = privateKey.export({ type: 'pkcs8', format: 'der' }).toString('base64');
|
|
41
|
+
const spki = publicKey.export({ type: 'spki', format: 'der' }).toString('base64');
|
|
42
|
+
for (const key of [pkcs1, pkcs8, privateKey.export({ type: 'pkcs8', format: 'pem' }) as string]) {
|
|
43
|
+
const signature = AlipayUtil.signText('a=1', key);
|
|
44
|
+
expect(AlipayUtil.verifyText('a=1', signature, spki)).toBe(true);
|
|
45
|
+
expect(AlipayUtil.verifyText('a=2', signature, publicKey.export({ type: 'spki', format: 'pem' }) as string)).toBe(false);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('takes the JSON of a node of the answer as it was sent', () => {
|
|
50
|
+
const text = '{"alipay_trade_query_response" : {"code":"10000","msg":"Success","a":"} \\" {","url":"https:\\/\\/x","n":{"m":1}},"sign":"abc"}';
|
|
51
|
+
expect(AlipayUtil.rawJson(text, 'alipay_trade_query_response')).toBe(
|
|
52
|
+
'{"code":"10000","msg":"Success","a":"} \\" {","url":"https:\\/\\/x","n":{"m":1}}',
|
|
53
|
+
);
|
|
54
|
+
expect(AlipayUtil.rawJson(text, 'error_response')).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|