node-easywechat 3.0.0-beta.5 → 3.0.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/CHANGELOG.md +21 -0
- package/README.md +36 -1
- package/dist/Core/Contracts/RefreshableAccessTokenInterface.d.ts +2 -2
- package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +2 -2
- package/dist/Core/HttpClient/HttpClient.js +3 -1
- package/dist/Core/HttpClient/HttpClientResponse.d.ts +16 -5
- package/dist/Core/HttpClient/HttpClientResponse.js +64 -22
- package/dist/Core/Message.d.ts +0 -127
- package/dist/Core/Mixins/DecryptXmlMessageMixin.js +1 -1
- package/dist/Core/Mixins/ResponseXmlMessageMixin.js +2 -2
- package/dist/Core/Support/PrivateKey.d.ts +20 -0
- package/dist/Core/Support/PrivateKey.js +38 -0
- package/dist/Core/Support/PublicKey.d.ts +14 -0
- package/dist/Core/Support/PublicKey.js +36 -0
- package/dist/Core/Support/RSA.d.ts +2 -2
- package/dist/Core/Support/RSA.js +4 -4
- package/dist/Core/Support/Utils.d.ts +6 -0
- package/dist/Core/Support/Utils.js +15 -1
- package/dist/MiniApp/Application.d.ts +4 -4
- package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OfficialAccount/AccessToken.d.ts +2 -2
- package/dist/OfficialAccount/AccessToken.js +2 -2
- package/dist/OfficialAccount/Application.d.ts +4 -4
- package/dist/OfficialAccount/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OfficialAccount/JsApiTicket.js +2 -2
- package/dist/OfficialAccount/Message.d.ts +139 -0
- package/dist/OfficialAccount/Message.js +1 -0
- package/dist/Pay/Application.d.ts +52 -0
- package/dist/Pay/Application.js +96 -0
- package/dist/Pay/Client.d.ts +42 -0
- package/dist/Pay/Client.js +125 -0
- package/dist/Pay/Config.d.ts +5 -0
- package/dist/Pay/Config.js +17 -0
- package/dist/Pay/Contracts/ApplicationInterface.d.ts +50 -0
- package/dist/Pay/Contracts/ApplicationInterface.js +45 -0
- package/dist/Pay/Contracts/MerchantInterface.d.ts +35 -0
- package/dist/Pay/Contracts/MerchantInterface.js +35 -0
- package/dist/Pay/Contracts/ResponseValidatorInterface.d.ts +9 -0
- package/dist/Pay/Contracts/ResponseValidatorInterface.js +10 -0
- package/dist/Pay/LegacySignature.d.ts +12 -0
- package/dist/Pay/LegacySignature.js +59 -0
- package/dist/Pay/Merchant.d.ts +25 -0
- package/dist/Pay/Merchant.js +53 -0
- package/dist/Pay/Message.d.ts +175 -0
- package/dist/Pay/Message.js +24 -0
- package/dist/Pay/Server.d.ts +41 -0
- package/dist/Pay/Server.js +122 -0
- package/dist/Pay/Signature.d.ts +15 -0
- package/dist/Pay/Signature.js +44 -0
- package/dist/Pay/Utils.d.ts +54 -0
- package/dist/Pay/Utils.js +142 -0
- package/dist/Types/global.d.ts +110 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const ServerInterface_1 = __importDefault(require("../Core/Contracts/ServerInterface"));
|
|
15
|
+
const Response_1 = __importDefault(require("../Core/Http/Response"));
|
|
16
|
+
const Message_1 = __importDefault(require("./Message"));
|
|
17
|
+
const AES_1 = require("../Core/Support/AES");
|
|
18
|
+
class Server extends ServerInterface_1.default {
|
|
19
|
+
constructor(merchant = null, request = null) {
|
|
20
|
+
super();
|
|
21
|
+
this.merchant = merchant;
|
|
22
|
+
this.request = request;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 服务端消息处理
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
serve() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
let message = yield this.getRequestMessage();
|
|
31
|
+
try {
|
|
32
|
+
let defaultResponse = new Response_1.default(200, {}, JSON.stringify({
|
|
33
|
+
code: 'SUCCESS', message: '成功',
|
|
34
|
+
}));
|
|
35
|
+
let response = yield this.handle(defaultResponse, message);
|
|
36
|
+
if (!(response instanceof Response_1.default)) {
|
|
37
|
+
response = defaultResponse;
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return new Response_1.default(200, {}, JSON.stringify({
|
|
43
|
+
code: 'ERROR', message: e.message,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 获取来自微信服务器的推送消息
|
|
50
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
getRequestMessage(request = null) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
if (!request) {
|
|
56
|
+
request = this.request;
|
|
57
|
+
}
|
|
58
|
+
let originContent = '';
|
|
59
|
+
let body = request.getBody();
|
|
60
|
+
if (body) {
|
|
61
|
+
originContent = body.toString();
|
|
62
|
+
}
|
|
63
|
+
let attributes = {};
|
|
64
|
+
try {
|
|
65
|
+
attributes = JSON.parse(originContent);
|
|
66
|
+
}
|
|
67
|
+
catch (e) { }
|
|
68
|
+
if (Object.keys(attributes).length === 0) {
|
|
69
|
+
throw new Error('Invalid request body.');
|
|
70
|
+
}
|
|
71
|
+
if (!attributes['resource']['ciphertext']) {
|
|
72
|
+
throw new Error('Invalid request.');
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
let decryptMessage = AES_1.AES_GCM.decrypt(attributes['resource']['ciphertext'], this.merchant.getSecretKey(), attributes['resource']['nonce'], attributes['resource']['associated_data']);
|
|
76
|
+
attributes = JSON.parse(decryptMessage.toString());
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error('Failed to decrypt request message.');
|
|
80
|
+
}
|
|
81
|
+
return new Message_1.default(attributes, originContent);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 获取解密后的消息
|
|
86
|
+
* @param request
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
getDecryptedMessage(request = null) {
|
|
90
|
+
return this.getRequestMessage(request);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 处理付款回调
|
|
94
|
+
* @param handler 消息处理器,需要接受两个参数,参数1是消息,参数2是下一个消息处理器
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
handlePaid(handler) {
|
|
98
|
+
this.with((message, next) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return message.getEventType() === 'TRANSACTION.SUCCESS' && message.trade_state === 'SUCCESS'
|
|
100
|
+
? handler(message, next) : next(message);
|
|
101
|
+
}));
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 处理退款回调
|
|
106
|
+
* @param handler 消息处理器,需要接受两个参数,参数1是消息,参数2是下一个消息处理器
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
handleRefunded(handler) {
|
|
110
|
+
this.with((message, next) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
let eventType = message.getEventType();
|
|
112
|
+
return [
|
|
113
|
+
'REFUND.SUCCESS',
|
|
114
|
+
'REFUND.ABNORMAL',
|
|
115
|
+
'REFUND.CLOSED',
|
|
116
|
+
].findIndex(o => o === eventType) > -1 ? handler(message, next) : next(message);
|
|
117
|
+
}));
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
;
|
|
122
|
+
module.exports = Server;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import MerchantInterface from "./Contracts/MerchantInterface";
|
|
2
|
+
import { AxiosRequestConfig } from "axios";
|
|
3
|
+
declare class Signature {
|
|
4
|
+
protected merchant: MerchantInterface;
|
|
5
|
+
constructor(merchant: MerchantInterface);
|
|
6
|
+
/**
|
|
7
|
+
* V3版本的签名计算
|
|
8
|
+
* @param method 请求方式
|
|
9
|
+
* @param url 请求地址
|
|
10
|
+
* @param payload 请求载荷
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
createHeader(method: string, url: string, payload: AxiosRequestConfig<any>): string;
|
|
14
|
+
}
|
|
15
|
+
export = Signature;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
6
|
+
const merge_1 = __importDefault(require("merge"));
|
|
7
|
+
const url_1 = __importDefault(require("url"));
|
|
8
|
+
const RSA_1 = __importDefault(require("../Core/Support/RSA"));
|
|
9
|
+
class Signature {
|
|
10
|
+
constructor(merchant) {
|
|
11
|
+
this.merchant = merchant;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* V3版本的签名计算
|
|
15
|
+
* @param method 请求方式
|
|
16
|
+
* @param url 请求地址
|
|
17
|
+
* @param payload 请求载荷
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
createHeader(method, url, payload) {
|
|
21
|
+
let uri = url_1.default.parse(url);
|
|
22
|
+
let query = (0, Utils_1.parseQueryString)(uri.query);
|
|
23
|
+
uri.query = (0, Utils_1.buildQueryString)((0, merge_1.default)(true, query, payload.params));
|
|
24
|
+
let nonce = (0, Utils_1.randomString)();
|
|
25
|
+
let timestamp = (0, Utils_1.getTimestamp)();
|
|
26
|
+
let path = uri.pathname + (uri.query ? '?' + uri.query : '');
|
|
27
|
+
let body = '';
|
|
28
|
+
if (payload.data) {
|
|
29
|
+
if (typeof payload.data === 'object') {
|
|
30
|
+
body = JSON.stringify(payload.data);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
body = payload.data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let signString = `${method.toUpperCase()}\n${path}\n${timestamp}\n${nonce}\n${body}`;
|
|
37
|
+
let rsa = new RSA_1.default;
|
|
38
|
+
rsa.setPublicKey(this.merchant.getCertificate().toString());
|
|
39
|
+
rsa.setPrivateKey(this.merchant.getPrivateKey().toString());
|
|
40
|
+
let sign = rsa.sign(signString);
|
|
41
|
+
return `WECHATPAY2-SHA256-RSA2048 mchid="${this.merchant.getMerchantId()}",nonce_str="${nonce}",timestamp="${timestamp}",serial_no="${this.merchant.getCertificate().getSerialNo()}",signature="${sign}"`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
module.exports = Signature;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PayAppConfig, PayBridgeConfig, PaySdkConfig } from '../Types/global';
|
|
2
|
+
import MerchantInterface from './Contracts/MerchantInterface';
|
|
3
|
+
declare class Utils {
|
|
4
|
+
protected merchant: MerchantInterface;
|
|
5
|
+
constructor(merchant: MerchantInterface);
|
|
6
|
+
/**
|
|
7
|
+
* 创建签名(V3),并返回签名字符串
|
|
8
|
+
* @param params 参数集合
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
protected createSignature(message: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* 创建签名(V2),并返回签名字符串
|
|
14
|
+
* @param params 参数集合
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
createV2Signature(params: Record<string, string | number>): string;
|
|
18
|
+
/**
|
|
19
|
+
* 构建JSBridge支付参数
|
|
20
|
+
* @see [v3文档](https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_4.shtml)
|
|
21
|
+
* @see [v2文档](https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)
|
|
22
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
23
|
+
* @param appId 应用id
|
|
24
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
buildBridgeConfig(prepayId: string, appId: string, signType?: string): PayBridgeConfig;
|
|
28
|
+
/**
|
|
29
|
+
* 构建JS-SDK支付参数
|
|
30
|
+
* @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#58
|
|
31
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
32
|
+
* @param appId 应用id
|
|
33
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
34
|
+
*/
|
|
35
|
+
buildSdkConfig(prepayId: string, appId: string, signType?: string): PaySdkConfig;
|
|
36
|
+
/**
|
|
37
|
+
* 构建小程序支付参数
|
|
38
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html
|
|
39
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
40
|
+
* @param appId 应用id
|
|
41
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
buildMiniAppConfig(prepayId: string, appId: string, signType?: string): PayBridgeConfig;
|
|
45
|
+
/**
|
|
46
|
+
* 构建App支付参数
|
|
47
|
+
* @see https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_2_4.shtml
|
|
48
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
49
|
+
* @param appId 应用id
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
buildAppConfig(prepayId: string, appId: string): PayAppConfig;
|
|
53
|
+
}
|
|
54
|
+
export = Utils;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const RSA_1 = __importDefault(require("../Core/Support/RSA"));
|
|
6
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
7
|
+
class Utils {
|
|
8
|
+
constructor(merchant) {
|
|
9
|
+
this.merchant = merchant;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 创建签名(V3),并返回签名字符串
|
|
13
|
+
* @param params 参数集合
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
createSignature(message) {
|
|
17
|
+
let rsa = new RSA_1.default;
|
|
18
|
+
rsa.setPublicKey(this.merchant.getCertificate().toString());
|
|
19
|
+
rsa.setPrivateKey(this.merchant.getPrivateKey().toString());
|
|
20
|
+
return rsa.sign(message);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 创建签名(V2),并返回签名字符串
|
|
24
|
+
* @param params 参数集合
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
createV2Signature(params) {
|
|
28
|
+
let signString = '';
|
|
29
|
+
let sparator = '';
|
|
30
|
+
let keys = Object.keys(params);
|
|
31
|
+
keys = keys.sort();
|
|
32
|
+
for (let i = 0; i < keys.length; i++) {
|
|
33
|
+
if (keys[i] == 'sign' || keys[i] == 'paySign' || typeof params[keys[i]] === undefined || params[keys[i]] === null)
|
|
34
|
+
continue;
|
|
35
|
+
signString += sparator + keys[i] + '=' + params[keys[i]];
|
|
36
|
+
sparator = '&';
|
|
37
|
+
}
|
|
38
|
+
let key = this.merchant.getV2SecretKey();
|
|
39
|
+
if (!key) {
|
|
40
|
+
throw new Error('Missing V2 API key.');
|
|
41
|
+
}
|
|
42
|
+
signString += '&key=' + key;
|
|
43
|
+
let sign = '';
|
|
44
|
+
let type = params['signType'] ? (params['signType'] + '').toLowerCase() : 'md5';
|
|
45
|
+
switch (type) {
|
|
46
|
+
case 'sha1':
|
|
47
|
+
case 'md5':
|
|
48
|
+
sign = (0, Utils_1.createHash)(signString, type);
|
|
49
|
+
break;
|
|
50
|
+
case 'hmac-sha256':
|
|
51
|
+
case 'hmac_sha256':
|
|
52
|
+
type = type.replace(/^hmac[\-|_]/i, '');
|
|
53
|
+
sign = (0, Utils_1.createHmac)(signString, key, type);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (!sign) {
|
|
57
|
+
throw new Error('Failed to sign the request.');
|
|
58
|
+
}
|
|
59
|
+
return (sign + '').toUpperCase();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 构建JSBridge支付参数
|
|
63
|
+
* @see [v3文档](https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_4.shtml)
|
|
64
|
+
* @see [v2文档](https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)
|
|
65
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
66
|
+
* @param appId 应用id
|
|
67
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
buildBridgeConfig(prepayId, appId, signType = 'RSA') {
|
|
71
|
+
let params = {
|
|
72
|
+
appId,
|
|
73
|
+
timeStamp: (0, Utils_1.getTimestamp)(),
|
|
74
|
+
nonceStr: (0, Utils_1.randomString)(),
|
|
75
|
+
package: 'prepay_id=' + prepayId,
|
|
76
|
+
signType,
|
|
77
|
+
paySign: '',
|
|
78
|
+
};
|
|
79
|
+
// v2
|
|
80
|
+
if (signType != 'RSA') {
|
|
81
|
+
params.paySign = this.createV2Signature(params);
|
|
82
|
+
}
|
|
83
|
+
// v3
|
|
84
|
+
else {
|
|
85
|
+
let message = `${params.appId}\n${params.timeStamp}\n${params.nonceStr}\n${params.package}\n`;
|
|
86
|
+
params.paySign = this.createSignature(message);
|
|
87
|
+
}
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 构建JS-SDK支付参数
|
|
92
|
+
* @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#58
|
|
93
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
94
|
+
* @param appId 应用id
|
|
95
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
96
|
+
*/
|
|
97
|
+
buildSdkConfig(prepayId, appId, signType = 'RSA') {
|
|
98
|
+
let config = this.buildBridgeConfig(prepayId, appId, signType);
|
|
99
|
+
return {
|
|
100
|
+
appId: config.appId,
|
|
101
|
+
timestamp: config.timeStamp,
|
|
102
|
+
nonceStr: config.nonceStr,
|
|
103
|
+
package: config.package,
|
|
104
|
+
signType: config.signType,
|
|
105
|
+
paySign: config.paySign,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 构建小程序支付参数
|
|
110
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html
|
|
111
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
112
|
+
* @param appId 应用id
|
|
113
|
+
* @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
buildMiniAppConfig(prepayId, appId, signType = 'RSA') {
|
|
117
|
+
return this.buildBridgeConfig(prepayId, appId, signType);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 构建App支付参数
|
|
121
|
+
* @see https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_2_4.shtml
|
|
122
|
+
* @param prepayId 下单接口返回的prepay_id
|
|
123
|
+
* @param appId 应用id
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
buildAppConfig(prepayId, appId) {
|
|
127
|
+
let params = {
|
|
128
|
+
appId,
|
|
129
|
+
partnerid: this.merchant.getMerchantId(),
|
|
130
|
+
prepayid: prepayId,
|
|
131
|
+
nonceStr: (0, Utils_1.randomString)(),
|
|
132
|
+
timestamp: (0, Utils_1.getTimestamp)(),
|
|
133
|
+
package: 'Sign=WXPay',
|
|
134
|
+
sign: '',
|
|
135
|
+
};
|
|
136
|
+
let message = `${params.appId}\n${params.timestamp}\n${params.nonceStr}\n${params.prepayid}\n`;
|
|
137
|
+
params.sign = this.createSignature(message);
|
|
138
|
+
return params;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
;
|
|
142
|
+
module.exports = Utils;
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
|
|
|
3
3
|
import OfficialAccountApplicationInterface from '../OfficialAccount/Contracts/ApplicationInterface';
|
|
4
4
|
import Message from '../Core/Message';
|
|
5
5
|
import HttpClientResponseInterface from '../Core/HttpClient/Contracts/HttpClientResponseInterface';
|
|
6
|
+
import { PublicKey } from "../Core/Support/PublicKey";
|
|
6
7
|
|
|
7
8
|
declare module 'axios' {
|
|
8
9
|
export interface AxiosRequestConfig {
|
|
@@ -153,10 +154,24 @@ export declare interface PayConfig extends BaseConfig {
|
|
|
153
154
|
mch_id?: string;
|
|
154
155
|
|
|
155
156
|
/**
|
|
156
|
-
*
|
|
157
|
+
* 商户证书路径
|
|
157
158
|
*/
|
|
158
159
|
certificate?: string;
|
|
159
160
|
|
|
161
|
+
/**
|
|
162
|
+
* 商户证书私钥路径
|
|
163
|
+
*/
|
|
164
|
+
private_key?: string;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 平台证书(v3接口需要)
|
|
168
|
+
*
|
|
169
|
+
* 支持路径列表或者PublicKey对象列表或者,以serial_no为key,证书内容或PublicKey对象为value的对象
|
|
170
|
+
*
|
|
171
|
+
* 下载工具:https://github.com/wechatpay-apiv3/CertificateDownloader
|
|
172
|
+
*/
|
|
173
|
+
platform_certs?: string[] | PublicKey[] | Record<string, string | PublicKey>;
|
|
174
|
+
|
|
160
175
|
/**
|
|
161
176
|
* v3 API密钥
|
|
162
177
|
*/
|
|
@@ -324,3 +339,97 @@ export declare type PaymentScannedHandler = (message: Message, fail: PaymentFail
|
|
|
324
339
|
* @param response 响应对象,仅在 type 为 after 时返回
|
|
325
340
|
*/
|
|
326
341
|
export declare type LogHandler = (type: 'before' | 'after', options: AxiosRequestConfig, usedTime?: number, response?: AxiosResponse) => void | Promise<void>;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 支付参数 JsBridge
|
|
345
|
+
*/
|
|
346
|
+
export declare interface PayBridgeConfig {
|
|
347
|
+
/**
|
|
348
|
+
* 应用id
|
|
349
|
+
*/
|
|
350
|
+
appId: string;
|
|
351
|
+
/**
|
|
352
|
+
* 时间戳
|
|
353
|
+
*/
|
|
354
|
+
timeStamp: number;
|
|
355
|
+
/**
|
|
356
|
+
* 随机字符串
|
|
357
|
+
*/
|
|
358
|
+
nonceStr: string;
|
|
359
|
+
/**
|
|
360
|
+
* 订单详情扩展字符串
|
|
361
|
+
*/
|
|
362
|
+
package: string;
|
|
363
|
+
/**
|
|
364
|
+
* 签名方式
|
|
365
|
+
*/
|
|
366
|
+
signType: string;
|
|
367
|
+
/**
|
|
368
|
+
* 签名
|
|
369
|
+
*/
|
|
370
|
+
paySign: string;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* 支付参数 JsSdk
|
|
375
|
+
*/
|
|
376
|
+
export declare interface PaySdkConfig {
|
|
377
|
+
/**
|
|
378
|
+
* 应用id
|
|
379
|
+
*/
|
|
380
|
+
appId: string;
|
|
381
|
+
/**
|
|
382
|
+
* 时间戳
|
|
383
|
+
*/
|
|
384
|
+
timestamp: number;
|
|
385
|
+
/**
|
|
386
|
+
* 随机字符串
|
|
387
|
+
*/
|
|
388
|
+
nonceStr: string;
|
|
389
|
+
/**
|
|
390
|
+
* 订单详情扩展字符串
|
|
391
|
+
*/
|
|
392
|
+
package: string;
|
|
393
|
+
/**
|
|
394
|
+
* 签名方式
|
|
395
|
+
*/
|
|
396
|
+
signType: string;
|
|
397
|
+
/**
|
|
398
|
+
* 签名
|
|
399
|
+
*/
|
|
400
|
+
paySign: string;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 支付参数 App
|
|
405
|
+
*/
|
|
406
|
+
export declare interface PayAppConfig {
|
|
407
|
+
/**
|
|
408
|
+
* 应用id
|
|
409
|
+
*/
|
|
410
|
+
appId: string;
|
|
411
|
+
/**
|
|
412
|
+
* 商户id
|
|
413
|
+
*/
|
|
414
|
+
partnerid: string;
|
|
415
|
+
/**
|
|
416
|
+
* 预支付交易会话ID
|
|
417
|
+
*/
|
|
418
|
+
prepayid: string;
|
|
419
|
+
/**
|
|
420
|
+
* 订单详情扩展字符串
|
|
421
|
+
*/
|
|
422
|
+
package: string;
|
|
423
|
+
/**
|
|
424
|
+
* 随机字符串
|
|
425
|
+
*/
|
|
426
|
+
nonceStr: string;
|
|
427
|
+
/**
|
|
428
|
+
* 时间戳
|
|
429
|
+
*/
|
|
430
|
+
timestamp: number;
|
|
431
|
+
/**
|
|
432
|
+
* 签名
|
|
433
|
+
*/
|
|
434
|
+
sign: string;
|
|
435
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure } from './Types/global';
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig } from './Types/global';
|
|
2
2
|
import OfficialAccount from './OfficialAccount/Application';
|
|
3
3
|
import MiniApp from './MiniApp/Application';
|
|
4
|
+
import Pay from './Pay/Application';
|
|
4
5
|
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
5
6
|
import ServerRequest from './Core/Http/ServerRequest';
|
|
6
|
-
import Message from './Core/Message';
|
|
7
7
|
import FormData from 'form-data';
|
|
8
|
-
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
8
|
+
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
9
9
|
/**
|
|
10
10
|
* 表单对象
|
|
11
11
|
* @see https://github.com/axios/axios#formdata
|
package/dist/index.js
CHANGED
|
@@ -3,16 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FormData = exports.
|
|
6
|
+
exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
7
7
|
const Application_1 = __importDefault(require("./OfficialAccount/Application"));
|
|
8
8
|
exports.OfficialAccount = Application_1.default;
|
|
9
9
|
const Application_2 = __importDefault(require("./MiniApp/Application"));
|
|
10
10
|
exports.MiniApp = Application_2.default;
|
|
11
|
+
const Application_3 = __importDefault(require("./Pay/Application"));
|
|
12
|
+
exports.Pay = Application_3.default;
|
|
11
13
|
const CacheInterface_1 = __importDefault(require("./Core/Contracts/CacheInterface"));
|
|
12
14
|
exports.CacheInterface = CacheInterface_1.default;
|
|
13
15
|
const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|
|
14
16
|
exports.ServerRequest = ServerRequest_1.default;
|
|
15
|
-
const Message_1 = __importDefault(require("./Core/Message"));
|
|
16
|
-
exports.Message = Message_1.default;
|
|
17
17
|
const form_data_1 = __importDefault(require("form-data"));
|
|
18
18
|
exports.FormData = form_data_1.default;
|