@jayfong/x-server 1.24.1 → 1.24.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/CHANGELOG.md +8 -0
- package/lib/_cjs/services/pay.js +19 -18
- package/lib/services/pay.d.ts +3 -3
- package/lib/services/pay.js +19 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.24.2](https://github.com/jfWorks/x-server/compare/v1.24.1...v1.24.2) (2022-05-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* returnUrl? ([fb46884](https://github.com/jfWorks/x-server/commit/fb4688405c16986727be2785695e9faa6a2db386))
|
|
11
|
+
* verifyNotifyData ([a4b76e3](https://github.com/jfWorks/x-server/commit/a4b76e3c63babc2f789646f932b1375a1c0a76e4))
|
|
12
|
+
|
|
5
13
|
### [1.24.1](https://github.com/jfWorks/x-server/compare/v1.24.0...v1.24.1) (2022-05-02)
|
|
6
14
|
|
|
7
15
|
## [1.24.0](https://github.com/jfWorks/x-server/compare/v1.23.0...v1.24.0) (2022-05-02)
|
package/lib/_cjs/services/pay.js
CHANGED
|
@@ -15,8 +15,6 @@ var _got = _interopRequireDefault(require("got"));
|
|
|
15
15
|
|
|
16
16
|
var _http_error = require("../core/http_error");
|
|
17
17
|
|
|
18
|
-
var _x = require("../x");
|
|
19
|
-
|
|
20
18
|
class PayService {
|
|
21
19
|
constructor(options) {
|
|
22
20
|
this.options = options;
|
|
@@ -33,18 +31,21 @@ class PayService {
|
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
const token = await _x.x.cache.save('x', '1h');
|
|
37
34
|
const formData = new _form.default();
|
|
38
35
|
formData.setMethod('get');
|
|
39
36
|
formData.addField('notifyUrl', options.notifyUrl);
|
|
40
|
-
|
|
37
|
+
|
|
38
|
+
if (options.returnUrl) {
|
|
39
|
+
formData.addField('returnUrl', options.returnUrl);
|
|
40
|
+
}
|
|
41
|
+
|
|
41
42
|
formData.addField('bizContent', {
|
|
42
43
|
outTradeNo: options.tradeNumber,
|
|
43
44
|
productCode: 'FAST_INSTANT_TRADE_PAY',
|
|
44
45
|
totalAmount: options.totalMoney,
|
|
45
46
|
subject: options.goodsName,
|
|
46
47
|
goodsType: '0',
|
|
47
|
-
passbackParams:
|
|
48
|
+
passbackParams: 'alipay'
|
|
48
49
|
});
|
|
49
50
|
const payUrl = await this.alipaySdk.exec('alipay.trade.page.pay', {}, {
|
|
50
51
|
formData: formData
|
|
@@ -55,13 +56,12 @@ class PayService {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
async prepareWepay(options) {
|
|
58
|
-
const token = await _x.x.cache.save('x', '1h');
|
|
59
59
|
const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
|
|
60
60
|
appid: this.options.wepay.appId,
|
|
61
61
|
mchid: this.options.wepay.merchantId,
|
|
62
62
|
description: options.goodsName,
|
|
63
63
|
out_trade_no: options.tradeNumber,
|
|
64
|
-
attach:
|
|
64
|
+
attach: 'wepay',
|
|
65
65
|
notify_url: options.notifyUrl,
|
|
66
66
|
amount: {
|
|
67
67
|
total: options.totalMoney * 100,
|
|
@@ -91,19 +91,20 @@ class PayService {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
verifyNotifyData(data) {
|
|
95
|
+
try {
|
|
96
|
+
var _this$alipaySdk;
|
|
97
|
+
|
|
98
|
+
return !!data && typeof data === 'object' && ( // 支付宝
|
|
99
|
+
data.passback_params === 'alipay' ? !!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data)) : // 微信支付
|
|
100
|
+
data.resource ? JSON.parse(this.wepayDecrypt(data.resource)).attach === 'wepay' : false);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
if (!
|
|
106
|
+
verifyNotifyDataOrFail(data, message) {
|
|
107
|
+
if (!this.verifyNotifyData(data)) {
|
|
107
108
|
throw new _http_error.HttpError.BadRequest(message);
|
|
108
109
|
}
|
|
109
110
|
}
|
package/lib/services/pay.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface PayPrepareAlipayOptions {
|
|
|
33
33
|
/** 通知地址(POST) */
|
|
34
34
|
notifyUrl: string;
|
|
35
35
|
/** 返回地址 */
|
|
36
|
-
returnUrl
|
|
36
|
+
returnUrl?: string;
|
|
37
37
|
}
|
|
38
38
|
export interface PayPrepareAlipayResult {
|
|
39
39
|
/** 支付地址,需跳转过去 */
|
|
@@ -69,8 +69,8 @@ export declare class PayService implements BaseService {
|
|
|
69
69
|
constructor(options: PayOptions);
|
|
70
70
|
prepareAlipay(options: PayPrepareAlipayOptions): Promise<PayPrepareAlipayResult>;
|
|
71
71
|
prepareWepay(options: PayPrepareWepayOptions): Promise<PayPrepareWepayResult>;
|
|
72
|
-
verifyNotifyData(data: any):
|
|
73
|
-
verifyNotifyDataOrFail(data: any, message?: string):
|
|
72
|
+
verifyNotifyData(data: any): boolean;
|
|
73
|
+
verifyNotifyDataOrFail(data: any, message?: string): void;
|
|
74
74
|
private wepaySign;
|
|
75
75
|
private wepayDecrypt;
|
|
76
76
|
private wepayRequest;
|
package/lib/services/pay.js
CHANGED
|
@@ -3,7 +3,6 @@ import AlipaySdk from 'alipay-sdk';
|
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import got from 'got';
|
|
5
5
|
import { HttpError } from "../core/http_error";
|
|
6
|
-
import { x } from "../x";
|
|
7
6
|
export class PayService {
|
|
8
7
|
constructor(options) {
|
|
9
8
|
this.options = options;
|
|
@@ -20,18 +19,21 @@ export class PayService {
|
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
const token = await x.cache.save('x', '1h');
|
|
24
22
|
const formData = new AlipayFormData();
|
|
25
23
|
formData.setMethod('get');
|
|
26
24
|
formData.addField('notifyUrl', options.notifyUrl);
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
if (options.returnUrl) {
|
|
27
|
+
formData.addField('returnUrl', options.returnUrl);
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
formData.addField('bizContent', {
|
|
29
31
|
outTradeNo: options.tradeNumber,
|
|
30
32
|
productCode: 'FAST_INSTANT_TRADE_PAY',
|
|
31
33
|
totalAmount: options.totalMoney,
|
|
32
34
|
subject: options.goodsName,
|
|
33
35
|
goodsType: '0',
|
|
34
|
-
passbackParams:
|
|
36
|
+
passbackParams: 'alipay'
|
|
35
37
|
});
|
|
36
38
|
const payUrl = await this.alipaySdk.exec('alipay.trade.page.pay', {}, {
|
|
37
39
|
formData: formData
|
|
@@ -42,13 +44,12 @@ export class PayService {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async prepareWepay(options) {
|
|
45
|
-
const token = await x.cache.save('x', '1h');
|
|
46
47
|
const res = await this.wepayRequest('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', {
|
|
47
48
|
appid: this.options.wepay.appId,
|
|
48
49
|
mchid: this.options.wepay.merchantId,
|
|
49
50
|
description: options.goodsName,
|
|
50
51
|
out_trade_no: options.tradeNumber,
|
|
51
|
-
attach:
|
|
52
|
+
attach: 'wepay',
|
|
52
53
|
notify_url: options.notifyUrl,
|
|
53
54
|
amount: {
|
|
54
55
|
total: options.totalMoney * 100,
|
|
@@ -78,19 +79,20 @@ export class PayService {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
verifyNotifyData(data) {
|
|
83
|
+
try {
|
|
84
|
+
var _this$alipaySdk;
|
|
85
|
+
|
|
86
|
+
return !!data && typeof data === 'object' && ( // 支付宝
|
|
87
|
+
data.passback_params === 'alipay' ? !!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data)) : // 微信支付
|
|
88
|
+
data.resource ? JSON.parse(this.wepayDecrypt(data.resource)).attach === 'wepay' : false);
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
if (!
|
|
94
|
+
verifyNotifyDataOrFail(data, message) {
|
|
95
|
+
if (!this.verifyNotifyData(data)) {
|
|
94
96
|
throw new HttpError.BadRequest(message);
|
|
95
97
|
}
|
|
96
98
|
}
|