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,50 @@
|
|
|
1
|
+
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
2
|
+
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
3
|
+
import HttpClientInterface from "../../Core/HttpClient/Contracts/HttpClientInterface";
|
|
4
|
+
import ServerInterface from "../../Core/Contracts/ServerInterface";
|
|
5
|
+
import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInterface";
|
|
6
|
+
import MerchantInterface from "./MerchantInterface";
|
|
7
|
+
import Utils from "../Utils";
|
|
8
|
+
declare abstract class ApplicationInterface {
|
|
9
|
+
/**
|
|
10
|
+
* 获取当前账户实例
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
getMerchant(): MerchantInterface;
|
|
14
|
+
/**
|
|
15
|
+
* 获取服务端实例
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
getServer(): ServerInterface;
|
|
19
|
+
/**
|
|
20
|
+
* 获取当前请求实例
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
getRequest(): ServerRequestInterface;
|
|
24
|
+
/**
|
|
25
|
+
* 获取客户端实例
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
getClient(): HttpClientInterface;
|
|
29
|
+
/**
|
|
30
|
+
* 获取网络请求客户端实例
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
getHttpClient(): HttpClientInterface;
|
|
34
|
+
/**
|
|
35
|
+
* 获取配置信息实例
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
getConfig(): ConfigInterface;
|
|
39
|
+
/**
|
|
40
|
+
* 获取缓存实例
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getCache(): CacheInterface;
|
|
44
|
+
/**
|
|
45
|
+
* 获取工具实例
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getUtils(): Utils;
|
|
49
|
+
}
|
|
50
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class ApplicationInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取当前账户实例
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getMerchant() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取服务端实例
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getServer() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取当前请求实例
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getRequest() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取客户端实例
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getClient() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取网络请求客户端实例
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getHttpClient() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 获取配置信息实例
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getConfig() { return null; }
|
|
33
|
+
/**
|
|
34
|
+
* 获取缓存实例
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getCache() { return null; }
|
|
38
|
+
/**
|
|
39
|
+
* 获取工具实例
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getUtils() { return null; }
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PrivateKey } from "../../Core/Support/PrivateKey";
|
|
2
|
+
import { PublicKey } from "../../Core/Support/PublicKey";
|
|
3
|
+
declare abstract class MerchantInterface {
|
|
4
|
+
/**
|
|
5
|
+
* 获取merchant_id
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
getMerchantId(): string;
|
|
9
|
+
/**
|
|
10
|
+
* 获取证书私钥
|
|
11
|
+
*/
|
|
12
|
+
getPrivateKey(): PrivateKey;
|
|
13
|
+
/**
|
|
14
|
+
* 获取secret_key
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getSecretKey(): string;
|
|
18
|
+
/**
|
|
19
|
+
* 获取secret_key(V2版本)
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getV2SecretKey(): string;
|
|
23
|
+
/**
|
|
24
|
+
* 获取证书
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getCertificate(): PublicKey;
|
|
28
|
+
/**
|
|
29
|
+
* 获取平台证书
|
|
30
|
+
* @param serial
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
getPlatformCert(serial: string): PublicKey;
|
|
34
|
+
}
|
|
35
|
+
export = MerchantInterface;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class MerchantInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取merchant_id
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getMerchantId() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取证书私钥
|
|
10
|
+
*/
|
|
11
|
+
getPrivateKey() { return null; }
|
|
12
|
+
/**
|
|
13
|
+
* 获取secret_key
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getSecretKey() { return null; }
|
|
17
|
+
/**
|
|
18
|
+
* 获取secret_key(V2版本)
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getV2SecretKey() { return null; }
|
|
22
|
+
/**
|
|
23
|
+
* 获取证书
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
getCertificate() { return null; }
|
|
27
|
+
/**
|
|
28
|
+
* 获取平台证书
|
|
29
|
+
* @param serial
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getPlatformCert(serial) { return null; }
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
module.exports = MerchantInterface;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import MerchantInterface from "./Contracts/MerchantInterface";
|
|
2
|
+
declare class LegacySignature {
|
|
3
|
+
protected merchant: MerchantInterface;
|
|
4
|
+
constructor(merchant: MerchantInterface);
|
|
5
|
+
/**
|
|
6
|
+
* V2版本的签名计算,并返回带签名字段的参数集合
|
|
7
|
+
* @param params 参数集合
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
sign(params: Record<string, string | number>): Record<string, string | number>;
|
|
11
|
+
}
|
|
12
|
+
export = LegacySignature;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
class LegacySignature {
|
|
8
|
+
constructor(merchant) {
|
|
9
|
+
this.merchant = merchant;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* V2版本的签名计算,并返回带签名字段的参数集合
|
|
13
|
+
* @param params 参数集合
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
sign(params) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
let nonce = (0, Utils_1.randomString)();
|
|
19
|
+
let attributes = (0, merge_1.default)(true, {
|
|
20
|
+
nonce_str: nonce,
|
|
21
|
+
sub_mch_id: (_a = params['sub_mch_id']) !== null && _a !== void 0 ? _a : null,
|
|
22
|
+
sub_appid: (_b = params['sub_appid']) !== null && _b !== void 0 ? _b : null,
|
|
23
|
+
}, params);
|
|
24
|
+
let signString = '';
|
|
25
|
+
let sparator = '';
|
|
26
|
+
let keys = Object.keys(attributes);
|
|
27
|
+
keys = keys.sort();
|
|
28
|
+
for (let i = 0; i < keys.length; i++) {
|
|
29
|
+
if (keys[i] == 'sign' || typeof attributes[keys[i]] === undefined || attributes[keys[i]] === null)
|
|
30
|
+
continue;
|
|
31
|
+
signString += sparator + keys[i] + '=' + attributes[keys[i]];
|
|
32
|
+
sparator = '&';
|
|
33
|
+
}
|
|
34
|
+
let key = this.merchant.getV2SecretKey();
|
|
35
|
+
if (!key) {
|
|
36
|
+
throw new Error('Missing V2 API key.');
|
|
37
|
+
}
|
|
38
|
+
signString += '&key=' + key;
|
|
39
|
+
let sign = '';
|
|
40
|
+
let type = params['sign_type'] ? (params['sign_type'] + '').toLowerCase() : 'md5';
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'sha1':
|
|
43
|
+
case 'md5':
|
|
44
|
+
sign = (0, Utils_1.createHash)(signString, type);
|
|
45
|
+
break;
|
|
46
|
+
case 'hmac-sha256':
|
|
47
|
+
case 'hmac_sha256':
|
|
48
|
+
type = type.replace(/^hmac[\-|_]/i, '');
|
|
49
|
+
sign = (0, Utils_1.createHmac)(signString, key, type);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (!sign) {
|
|
53
|
+
throw new Error('Failed to sign the request.');
|
|
54
|
+
}
|
|
55
|
+
params.sign = (sign + '').toUpperCase();
|
|
56
|
+
return params;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
module.exports = LegacySignature;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PrivateKey } from "../Core/Support/PrivateKey";
|
|
2
|
+
import { PublicKey } from "../Core/Support/PublicKey";
|
|
3
|
+
import MerchantInterface from "./Contracts/MerchantInterface";
|
|
4
|
+
declare class Merchant implements MerchantInterface {
|
|
5
|
+
protected mchId: string;
|
|
6
|
+
protected privateKey: PrivateKey;
|
|
7
|
+
protected certificate: PublicKey;
|
|
8
|
+
protected secretKey: string;
|
|
9
|
+
protected v2SecretKey: string;
|
|
10
|
+
protected platformCerts: Record<string, PublicKey>;
|
|
11
|
+
constructor(mchId: string, privateKey: PrivateKey, certificate: PublicKey, secretKey: string, v2SecretKey?: string, platformCerts?: Record<string, string | PublicKey> | string[] | PublicKey[]);
|
|
12
|
+
/**
|
|
13
|
+
* 统一规范化平台证书
|
|
14
|
+
* @param platformCerts 平台证书列表
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
protected normalizePlatformCerts(platformCerts: Record<string, string | PublicKey> | string[] | PublicKey[]): Record<string, PublicKey>;
|
|
18
|
+
getMerchantId(): string;
|
|
19
|
+
getPrivateKey(): PrivateKey;
|
|
20
|
+
getSecretKey(): string;
|
|
21
|
+
getV2SecretKey(): string;
|
|
22
|
+
getCertificate(): PublicKey;
|
|
23
|
+
getPlatformCert(serial: string): PublicKey;
|
|
24
|
+
}
|
|
25
|
+
export = Merchant;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const PublicKey_1 = require("../Core/Support/PublicKey");
|
|
3
|
+
class Merchant {
|
|
4
|
+
constructor(mchId, privateKey, certificate, secretKey, v2SecretKey = null, platformCerts = []) {
|
|
5
|
+
this.mchId = mchId;
|
|
6
|
+
this.privateKey = privateKey;
|
|
7
|
+
this.certificate = certificate;
|
|
8
|
+
this.secretKey = secretKey;
|
|
9
|
+
this.v2SecretKey = v2SecretKey;
|
|
10
|
+
this.platformCerts = {};
|
|
11
|
+
this.platformCerts = this.normalizePlatformCerts(platformCerts);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 统一规范化平台证书
|
|
15
|
+
* @param platformCerts 平台证书列表
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
normalizePlatformCerts(platformCerts) {
|
|
19
|
+
let certs = {};
|
|
20
|
+
let isArray = Array.isArray(platformCerts);
|
|
21
|
+
for (let key in platformCerts) {
|
|
22
|
+
let publicKey = platformCerts[key];
|
|
23
|
+
if (typeof publicKey === 'string') {
|
|
24
|
+
publicKey = new PublicKey_1.PublicKey(publicKey);
|
|
25
|
+
}
|
|
26
|
+
if (!(publicKey instanceof PublicKey_1.PublicKey)) {
|
|
27
|
+
throw new Error('Invalid platform certficate.');
|
|
28
|
+
}
|
|
29
|
+
certs[isArray ? publicKey.getSerialNo() : key] = publicKey;
|
|
30
|
+
}
|
|
31
|
+
return certs;
|
|
32
|
+
}
|
|
33
|
+
getMerchantId() {
|
|
34
|
+
return this.mchId;
|
|
35
|
+
}
|
|
36
|
+
getPrivateKey() {
|
|
37
|
+
return this.privateKey;
|
|
38
|
+
}
|
|
39
|
+
getSecretKey() {
|
|
40
|
+
return this.secretKey;
|
|
41
|
+
}
|
|
42
|
+
getV2SecretKey() {
|
|
43
|
+
return this.v2SecretKey;
|
|
44
|
+
}
|
|
45
|
+
getCertificate() {
|
|
46
|
+
return this.certificate;
|
|
47
|
+
}
|
|
48
|
+
getPlatformCert(serial) {
|
|
49
|
+
var _a;
|
|
50
|
+
return (_a = this.platformCerts[serial]) !== null && _a !== void 0 ? _a : null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
module.exports = Merchant;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import BaseMessage from '../Core/Message';
|
|
2
|
+
declare class Message extends BaseMessage {
|
|
3
|
+
getOriginalAttributes(): Record<string, any>;
|
|
4
|
+
getEventType(): string;
|
|
5
|
+
}
|
|
6
|
+
interface Message {
|
|
7
|
+
/**
|
|
8
|
+
* 应用ID
|
|
9
|
+
*/
|
|
10
|
+
appid: string;
|
|
11
|
+
/**
|
|
12
|
+
* 商户号
|
|
13
|
+
*/
|
|
14
|
+
mchid: string;
|
|
15
|
+
/**
|
|
16
|
+
* 商户订单号
|
|
17
|
+
*/
|
|
18
|
+
out_trade_no: string;
|
|
19
|
+
/**
|
|
20
|
+
* 微信支付订单号
|
|
21
|
+
*/
|
|
22
|
+
transaction_id: string;
|
|
23
|
+
/**
|
|
24
|
+
* 交易类型
|
|
25
|
+
* - `JSAPI` 公众号支付
|
|
26
|
+
* - `NATIVE` 扫码支付
|
|
27
|
+
* - `APP` APP支付
|
|
28
|
+
* - `MICROPAY` 付款码支付
|
|
29
|
+
* - `MWEB` H5支付
|
|
30
|
+
* - `FACEPAY` 刷脸支付
|
|
31
|
+
*/
|
|
32
|
+
trade_type: string;
|
|
33
|
+
/**
|
|
34
|
+
* 交易状态
|
|
35
|
+
* - `SUCCESS` 支付成功
|
|
36
|
+
* - `REFUND` 转入退款
|
|
37
|
+
* - `NOTPAY` 未支付
|
|
38
|
+
* - `CLOSED` 已关闭
|
|
39
|
+
* - `REVOKED` 已撤销(付款码支付)
|
|
40
|
+
* - `USERPAYING` 用户支付中(付款码支付)
|
|
41
|
+
* - `PAYERROR` 支付失败(其他原因,如银行返回失败)
|
|
42
|
+
*/
|
|
43
|
+
trade_state: string;
|
|
44
|
+
/**
|
|
45
|
+
* 交易状态描述
|
|
46
|
+
*/
|
|
47
|
+
trade_state_desc: string;
|
|
48
|
+
/**
|
|
49
|
+
* 付款银行
|
|
50
|
+
* @see [银行对照表](https://pay.weixin.qq.com/wiki/doc/apiv3/terms_definition/chapter1_1_3.shtml#part-6)
|
|
51
|
+
*/
|
|
52
|
+
bank_type: string;
|
|
53
|
+
/**
|
|
54
|
+
* 附加数据
|
|
55
|
+
*/
|
|
56
|
+
attach?: string;
|
|
57
|
+
/**
|
|
58
|
+
* 支付完成时间。格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE,如:2015-05-20T13:29:35+08:00
|
|
59
|
+
*/
|
|
60
|
+
success_time: string;
|
|
61
|
+
/**
|
|
62
|
+
* 支付者
|
|
63
|
+
*/
|
|
64
|
+
payer: {
|
|
65
|
+
/**
|
|
66
|
+
* 用户标识
|
|
67
|
+
*/
|
|
68
|
+
openid: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 订单金额
|
|
72
|
+
*/
|
|
73
|
+
amount: {
|
|
74
|
+
/**
|
|
75
|
+
* 总金额,单位:分
|
|
76
|
+
*/
|
|
77
|
+
total: number;
|
|
78
|
+
/**
|
|
79
|
+
* 用户支付金额 ,单位:分
|
|
80
|
+
*/
|
|
81
|
+
payer_total: number;
|
|
82
|
+
/**
|
|
83
|
+
* 货币类型,如:`CNY` 表示人民币,境内商户号仅支持人民币
|
|
84
|
+
*/
|
|
85
|
+
currency: string;
|
|
86
|
+
/**
|
|
87
|
+
* 用户支付币种,如:`CNY` 表示人民币
|
|
88
|
+
*/
|
|
89
|
+
payer_currency: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* 场景信息
|
|
93
|
+
*/
|
|
94
|
+
scene_info?: {
|
|
95
|
+
/**
|
|
96
|
+
* 商户端设备号
|
|
97
|
+
*/
|
|
98
|
+
device_id?: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* 优惠信息
|
|
102
|
+
*/
|
|
103
|
+
promotion_detail?: {
|
|
104
|
+
/**
|
|
105
|
+
* 券ID
|
|
106
|
+
*/
|
|
107
|
+
coupon_id: string;
|
|
108
|
+
/**
|
|
109
|
+
* 优惠名称
|
|
110
|
+
*/
|
|
111
|
+
name?: string;
|
|
112
|
+
/**
|
|
113
|
+
* 优惠范围
|
|
114
|
+
* - `GLOBAL` 全场代金券
|
|
115
|
+
* - `SINGLE` 单品优惠
|
|
116
|
+
*/
|
|
117
|
+
scope?: string;
|
|
118
|
+
/**
|
|
119
|
+
* 优惠类型
|
|
120
|
+
* - `CASH` 充值型代金券
|
|
121
|
+
* - `NOCASH` 免充值型代金券
|
|
122
|
+
*/
|
|
123
|
+
type?: string;
|
|
124
|
+
/**
|
|
125
|
+
* 优惠券面额
|
|
126
|
+
*/
|
|
127
|
+
amount: number;
|
|
128
|
+
/**
|
|
129
|
+
* 活动ID
|
|
130
|
+
*/
|
|
131
|
+
stock_id?: number;
|
|
132
|
+
/**
|
|
133
|
+
* 微信出资,单位:分
|
|
134
|
+
*/
|
|
135
|
+
wechatpay_contribute?: number;
|
|
136
|
+
/**
|
|
137
|
+
* 商户出资,单位:分
|
|
138
|
+
*/
|
|
139
|
+
merchant_contribute?: number;
|
|
140
|
+
/**
|
|
141
|
+
* 其他出资,单位:分
|
|
142
|
+
*/
|
|
143
|
+
other_contribute?: number;
|
|
144
|
+
/**
|
|
145
|
+
* 优惠币种,如:`CNY` 表示人民币,境内商户号仅支持人民币
|
|
146
|
+
*/
|
|
147
|
+
currency?: string;
|
|
148
|
+
/**
|
|
149
|
+
* 单品列表
|
|
150
|
+
*/
|
|
151
|
+
goods_detail?: {
|
|
152
|
+
/**
|
|
153
|
+
* 商品编码
|
|
154
|
+
*/
|
|
155
|
+
goods_id: string;
|
|
156
|
+
/**
|
|
157
|
+
* 商品数量
|
|
158
|
+
*/
|
|
159
|
+
quantity: number;
|
|
160
|
+
/**
|
|
161
|
+
* 商品单价,单位:分
|
|
162
|
+
*/
|
|
163
|
+
unit_price: number;
|
|
164
|
+
/**
|
|
165
|
+
* 商品优惠金额
|
|
166
|
+
*/
|
|
167
|
+
discount_amount: number;
|
|
168
|
+
/**
|
|
169
|
+
* 商品备注
|
|
170
|
+
*/
|
|
171
|
+
goods_remark: string;
|
|
172
|
+
}[];
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export = Message;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Message_1 = __importDefault(require("../Core/Message"));
|
|
6
|
+
class Message extends Message_1.default {
|
|
7
|
+
getOriginalAttributes() {
|
|
8
|
+
let attributes = {};
|
|
9
|
+
try {
|
|
10
|
+
attributes = JSON.parse(this.originContent);
|
|
11
|
+
}
|
|
12
|
+
catch (e) { }
|
|
13
|
+
return attributes;
|
|
14
|
+
}
|
|
15
|
+
getEventType() {
|
|
16
|
+
let eventType = this.getOriginalAttributes()['event_type'];
|
|
17
|
+
if (typeof eventType !== 'string') {
|
|
18
|
+
throw new Error('Invalid event type.');
|
|
19
|
+
}
|
|
20
|
+
return eventType;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
;
|
|
24
|
+
module.exports = Message;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
2
|
+
import Response from '../Core/Http/Response';
|
|
3
|
+
import ServerRequestInterface from '../Core/Http/Contracts/ServerRequestInterface';
|
|
4
|
+
import MerchantInterface from './Contracts/MerchantInterface';
|
|
5
|
+
import Message from './Message';
|
|
6
|
+
import { ServerHandlerClosure } from '../Types/global';
|
|
7
|
+
declare class Server extends ServerInterface {
|
|
8
|
+
protected merchant: MerchantInterface;
|
|
9
|
+
protected request: ServerRequestInterface;
|
|
10
|
+
constructor(merchant?: MerchantInterface, request?: ServerRequestInterface);
|
|
11
|
+
/**
|
|
12
|
+
* 服务端消息处理
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
serve(): Promise<Response>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取来自微信服务器的推送消息
|
|
18
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getRequestMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取解密后的消息
|
|
24
|
+
* @param request
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getDecryptedMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
28
|
+
/**
|
|
29
|
+
* 处理付款回调
|
|
30
|
+
* @param handler 消息处理器,需要接受两个参数,参数1是消息,参数2是下一个消息处理器
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
handlePaid(handler: ServerHandlerClosure): this;
|
|
34
|
+
/**
|
|
35
|
+
* 处理退款回调
|
|
36
|
+
* @param handler 消息处理器,需要接受两个参数,参数1是消息,参数2是下一个消息处理器
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
handleRefunded(handler: ServerHandlerClosure): this;
|
|
40
|
+
}
|
|
41
|
+
export = Server;
|