node-easywechat 3.0.0-beta.3 → 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.
Files changed (64) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +36 -1
  3. package/dist/Core/Contracts/RefreshableAccessTokenInterface.d.ts +2 -2
  4. package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +2 -2
  5. package/dist/Core/Http/Minxins/MessageMixin.js +1 -2
  6. package/dist/Core/Http/ServerRequest.d.ts +1 -1
  7. package/dist/Core/Http/ServerRequest.js +16 -6
  8. package/dist/Core/HttpClient/HttpClient.d.ts +7 -0
  9. package/dist/Core/HttpClient/HttpClient.js +43 -7
  10. package/dist/Core/HttpClient/HttpClientResponse.d.ts +16 -5
  11. package/dist/Core/HttpClient/HttpClientResponse.js +64 -22
  12. package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +20 -1
  13. package/dist/Core/HttpClient/Mixins/PresetMixin.js +41 -2
  14. package/dist/Core/Message.d.ts +0 -127
  15. package/dist/Core/Message.js +5 -1
  16. package/dist/Core/Mixins/DecryptXmlMessageMixin.js +1 -1
  17. package/dist/Core/Mixins/ResponseXmlMessageMixin.js +2 -2
  18. package/dist/Core/Support/PrivateKey.d.ts +20 -0
  19. package/dist/Core/Support/PrivateKey.js +38 -0
  20. package/dist/Core/Support/PublicKey.d.ts +14 -0
  21. package/dist/Core/Support/PublicKey.js +36 -0
  22. package/dist/Core/Support/RSA.d.ts +2 -2
  23. package/dist/Core/Support/RSA.js +4 -4
  24. package/dist/Core/Support/Utils.d.ts +6 -0
  25. package/dist/Core/Support/Utils.js +15 -1
  26. package/dist/MiniApp/Application.d.ts +4 -4
  27. package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +2 -2
  28. package/dist/OfficialAccount/AccessToken.d.ts +2 -2
  29. package/dist/OfficialAccount/AccessToken.js +2 -2
  30. package/dist/OfficialAccount/Application.d.ts +4 -4
  31. package/dist/OfficialAccount/Application.js +0 -5
  32. package/dist/OfficialAccount/Contracts/ApplicationInterface.d.ts +2 -2
  33. package/dist/OfficialAccount/JsApiTicket.js +2 -2
  34. package/dist/OfficialAccount/Message.d.ts +139 -0
  35. package/dist/OfficialAccount/Message.js +1 -0
  36. package/dist/OfficialAccount/Server.js +1 -1
  37. package/dist/Pay/Application.d.ts +52 -0
  38. package/dist/Pay/Application.js +96 -0
  39. package/dist/Pay/Client.d.ts +42 -0
  40. package/dist/Pay/Client.js +125 -0
  41. package/dist/Pay/Config.d.ts +5 -0
  42. package/dist/Pay/Config.js +17 -0
  43. package/dist/Pay/Contracts/ApplicationInterface.d.ts +50 -0
  44. package/dist/Pay/Contracts/ApplicationInterface.js +45 -0
  45. package/dist/Pay/Contracts/MerchantInterface.d.ts +35 -0
  46. package/dist/Pay/Contracts/MerchantInterface.js +35 -0
  47. package/dist/Pay/Contracts/ResponseValidatorInterface.d.ts +9 -0
  48. package/dist/Pay/Contracts/ResponseValidatorInterface.js +10 -0
  49. package/dist/Pay/LegacySignature.d.ts +12 -0
  50. package/dist/Pay/LegacySignature.js +59 -0
  51. package/dist/Pay/Merchant.d.ts +25 -0
  52. package/dist/Pay/Merchant.js +53 -0
  53. package/dist/Pay/Message.d.ts +175 -0
  54. package/dist/Pay/Message.js +24 -0
  55. package/dist/Pay/Server.d.ts +41 -0
  56. package/dist/Pay/Server.js +122 -0
  57. package/dist/Pay/Signature.d.ts +15 -0
  58. package/dist/Pay/Signature.js +44 -0
  59. package/dist/Pay/Utils.d.ts +54 -0
  60. package/dist/Pay/Utils.js +142 -0
  61. package/dist/Types/global.d.ts +114 -1
  62. package/dist/index.d.ts +3 -3
  63. package/dist/index.js +3 -3
  64. package/package.json +2 -2
@@ -1,4 +1,143 @@
1
1
  import BaseMessage from '../Core/Message';
2
2
  declare class Message extends BaseMessage {
3
3
  }
4
+ interface Message {
5
+ /**
6
+ * 消息密文,兼容模式、安全模式才有
7
+ */
8
+ Encrypt?: string;
9
+ /**
10
+ * 开发者微信号
11
+ */
12
+ ToUserName?: string;
13
+ /**
14
+ * 发送方帐号 OpenId
15
+ */
16
+ FromUserName?: string;
17
+ /**
18
+ * 消息创建时间
19
+ */
20
+ CreateTime?: number;
21
+ /**
22
+ * 消息类型
23
+ * - `event` 事件
24
+ * - `text` 文本
25
+ * - `image` 图片
26
+ * - `voice` 语音
27
+ * - `video` 视频
28
+ * - `shortvideo` 小视频
29
+ * - `location` 地理位置
30
+ * - `link` 链接
31
+ */
32
+ MsgType?: string;
33
+ /**
34
+ * 消息id,64位整型
35
+ * @scope MsgType='text' | 'image' | 'voice' | 'video' | 'shortvideo' | 'location'
36
+ */
37
+ MsgId?: string;
38
+ /**
39
+ * 文本消息内容
40
+ * @scope MsgType='text'
41
+ */
42
+ Content?: string;
43
+ /**
44
+ * 图片链接
45
+ * @scope MsgType='image'
46
+ */
47
+ PicUrl?: string;
48
+ /**
49
+ * 媒体id,可以调用获取临时素材接口拉取数据
50
+ * @scope MsgType='image' | 'voice'
51
+ */
52
+ MediaId?: string;
53
+ /**
54
+ * 语音格式,如amr,speex等
55
+ * @scope MsgType='voice'
56
+ */
57
+ Format?: string;
58
+ /**
59
+ * 语音识别结果,UTF8编码
60
+ * @scope MsgType='voice'
61
+ */
62
+ Recognition?: string;
63
+ /**
64
+ * 缩略图的媒体id
65
+ * @scope MsgType='video' | 'shortvideo'
66
+ */
67
+ ThumbMediaId?: string;
68
+ /**
69
+ * 纬度
70
+ * @scope MsgType='location'
71
+ */
72
+ Location_X?: number;
73
+ /**
74
+ * 经度
75
+ * @scope MsgType='location'
76
+ */
77
+ Location_Y?: number;
78
+ /**
79
+ * 地图缩放大小
80
+ * @scope MsgType='location'
81
+ */
82
+ Scale?: number;
83
+ /**
84
+ * 地理位置信息
85
+ * @scope MsgType='location'
86
+ */
87
+ Label?: number;
88
+ /**
89
+ * 消息标题
90
+ * @scope MsgType='link'
91
+ */
92
+ Title?: string;
93
+ /**
94
+ * 消息描述
95
+ * @scope MsgType='link'
96
+ */
97
+ Description?: string;
98
+ /**
99
+ * 消息链接
100
+ * @scope MsgType='link'
101
+ */
102
+ Url?: string;
103
+ /**
104
+ * 事件类型
105
+ * - `subscribe` 关注
106
+ * - `unsubscribe` 取消关注
107
+ * - `SCAN` 扫描(用户已关注)
108
+ * - `LOCATION` 地理位置
109
+ * - `CLICK` 自定义菜单事件
110
+ * - `VIEW` 点击菜单跳转链接
111
+ * @scope MsgType='event'
112
+ */
113
+ Event?: string;
114
+ /**
115
+ * 事件KEY值
116
+ * - Event='subscribe' | 'SCAN'时:qrscene_为前缀,后面为二维码的参数值
117
+ * - Event='CLICK'时:自定义菜单接口中KEY值对应
118
+ * - Event='VIEW'时:设置的跳转URL
119
+ * @scope MsgType='event' && Event='subscribe' | 'SCAN' | 'CLICK' | 'VIEW'
120
+ */
121
+ EventKey?: string;
122
+ /**
123
+ * 二维码的ticket,可用来换取二维码图片
124
+ * @scope MsgType='event' && Event='subscribe' | 'SCAN'
125
+ */
126
+ Ticket?: string;
127
+ /**
128
+ * 纬度
129
+ * @scope MsgType='event' && Event='LOCATION'
130
+ */
131
+ Latitude?: number;
132
+ /**
133
+ * 经度
134
+ * @scope MsgType='event' && Event='LOCATION'
135
+ */
136
+ Longitude?: number;
137
+ /**
138
+ * 位置精度
139
+ * @scope MsgType='event' && Event='LOCATION'
140
+ */
141
+ Precision?: number;
142
+ }
4
143
  export = Message;
@@ -5,4 +5,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const Message_1 = __importDefault(require("../Core/Message"));
6
6
  class Message extends Message_1.default {
7
7
  }
8
+ ;
8
9
  module.exports = Message;
@@ -28,7 +28,7 @@ class Server extends ServerInterface_1.default {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  let echostr = this.request.getQueryParams()['echostr'] || '';
30
30
  if (!!echostr) {
31
- return new Response_1.default(200, {}, echostr);
31
+ return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
32
32
  }
33
33
  let message = yield this.getRequestMessage(this.request);
34
34
  let query = this.request.getQueryParams();
@@ -0,0 +1,52 @@
1
+ import ConfigInterface from '../Core/Contracts/ConfigInterface';
2
+ import ServerInterface from '../Core/Contracts/ServerInterface';
3
+ import Encryptor from '../Core/Encryptor';
4
+ import CacheMixin from '../Core/Mixins/CacheMixin';
5
+ import ConfigMixin from '../Core/Mixins/ConfigMixin';
6
+ import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
7
+ import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
8
+ import { PayConfig } from '../Types/global';
9
+ import MerchantInterface from './Contracts/MerchantInterface';
10
+ import ApplicationInterface from './Contracts/ApplicationInterface';
11
+ import Utils from './Utils';
12
+ import HttpClientInterface from '../Core/HttpClient/Contracts/HttpClientInterface';
13
+ /**
14
+ * 微信支付应用
15
+ */
16
+ declare class Application implements ApplicationInterface {
17
+ constructor(config: ConfigInterface | PayConfig);
18
+ protected merchant: MerchantInterface;
19
+ protected encryptor: Encryptor;
20
+ protected server: ServerInterface;
21
+ protected client: HttpClientInterface;
22
+ getMerchant(): MerchantInterface;
23
+ /**
24
+ * 设置当前账户实例
25
+ * @param merchant
26
+ * @returns
27
+ */
28
+ setMerchant(merchant: MerchantInterface): this;
29
+ getServer(): ServerInterface;
30
+ /**
31
+ * 设置服务端实例
32
+ * @param server
33
+ * @returns
34
+ */
35
+ setServer(server: ServerInterface): this;
36
+ getUtils(): Utils;
37
+ getClient(): HttpClientInterface;
38
+ /**
39
+ * 设置客户端
40
+ * @param client
41
+ * @returns
42
+ */
43
+ setClient(client: HttpClientInterface): this;
44
+ /**
45
+ * 获取请求默认配置
46
+ * @returns
47
+ */
48
+ protected getHttpClientDefaultOptions(): Record<string, any>;
49
+ }
50
+ interface Application extends ConfigMixin, CacheMixin, ServerRequestMixin, HttpClientMixin {
51
+ }
52
+ export = Application;
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const merge_1 = __importDefault(require("merge"));
6
+ const ConfigInterface_1 = __importDefault(require("../Core/Contracts/ConfigInterface"));
7
+ const CacheMixin_1 = __importDefault(require("../Core/Mixins/CacheMixin"));
8
+ const ConfigMixin_1 = __importDefault(require("../Core/Mixins/ConfigMixin"));
9
+ const HttpClientMixin_1 = __importDefault(require("../Core/Mixins/HttpClientMixin"));
10
+ const ServerRequestMixin_1 = __importDefault(require("../Core/Mixins/ServerRequestMixin"));
11
+ const Utils_1 = require("../Core/Support/Utils");
12
+ const Merchant_1 = __importDefault(require("./Merchant"));
13
+ const Server_1 = __importDefault(require("./Server"));
14
+ const Utils_2 = __importDefault(require("./Utils"));
15
+ const Config_1 = __importDefault(require("../OfficialAccount/Config"));
16
+ const PrivateKey_1 = require("../Core/Support/PrivateKey");
17
+ const PublicKey_1 = require("../Core/Support/PublicKey");
18
+ const Client_1 = __importDefault(require("./Client"));
19
+ /**
20
+ * 微信支付应用
21
+ */
22
+ class Application {
23
+ constructor(config) {
24
+ this.merchant = null;
25
+ this.encryptor = null;
26
+ this.server = null;
27
+ if (config instanceof ConfigInterface_1.default) {
28
+ this.setConfig(config);
29
+ }
30
+ else {
31
+ this.setConfig(new Config_1.default(config));
32
+ }
33
+ }
34
+ getMerchant() {
35
+ var _a;
36
+ if (!this.merchant) {
37
+ this.merchant = new Merchant_1.default(this.config.get('mch_id'), new PrivateKey_1.PrivateKey(this.config.get('private_key')), new PublicKey_1.PublicKey(this.config.get('certificate')), this.config.get('secret_key'), this.config.get('v2_secret_key'), (_a = this.config.get('platform_certs')) !== null && _a !== void 0 ? _a : []);
38
+ }
39
+ return this.merchant;
40
+ }
41
+ /**
42
+ * 设置当前账户实例
43
+ * @param merchant
44
+ * @returns
45
+ */
46
+ setMerchant(merchant) {
47
+ this.merchant = merchant;
48
+ return this;
49
+ }
50
+ getServer() {
51
+ if (!this.server) {
52
+ this.server = new Server_1.default(this.getMerchant(), this.getRequest());
53
+ }
54
+ return this.server;
55
+ }
56
+ /**
57
+ * 设置服务端实例
58
+ * @param server
59
+ * @returns
60
+ */
61
+ setServer(server) {
62
+ this.server = server;
63
+ return this;
64
+ }
65
+ getUtils() {
66
+ return new Utils_2.default(this.getMerchant());
67
+ }
68
+ getClient() {
69
+ if (!this.client) {
70
+ this.client = (new Client_1.default(this.getMerchant(), this.getHttpClient(), this.config.get('http', {}))).setPresets(this.config.all());
71
+ }
72
+ return this.client;
73
+ }
74
+ /**
75
+ * 设置客户端
76
+ * @param client
77
+ * @returns
78
+ */
79
+ setClient(client) {
80
+ this.client = client;
81
+ return this;
82
+ }
83
+ /**
84
+ * 获取请求默认配置
85
+ * @returns
86
+ */
87
+ getHttpClientDefaultOptions() {
88
+ return (0, merge_1.default)(true, {
89
+ baseURL: 'https://api.weixin.qq.com/',
90
+ }, this.getConfig().get('http'));
91
+ }
92
+ }
93
+ ;
94
+ ;
95
+ (0, Utils_1.applyMixins)(Application, [ConfigMixin_1.default, CacheMixin_1.default, ServerRequestMixin_1.default, HttpClientMixin_1.default]);
96
+ module.exports = Application;
@@ -0,0 +1,42 @@
1
+ import { Method, AxiosRequestConfig, AxiosInstance } from "axios";
2
+ import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
3
+ import HttpClientMethodsMixin from '../Core/HttpClient/Mixins/HttpClientMethodsMixin';
4
+ import { LogHandler } from '../Types/global';
5
+ import HttpClientResponse from '../Core/HttpClient/HttpClientResponse';
6
+ import PresetMixin from '../Core/HttpClient/Mixins/PresetMixin';
7
+ import MerchantInterface from './Contracts/MerchantInterface';
8
+ declare class Client implements HttpClientInterface {
9
+ protected merchant: MerchantInterface;
10
+ protected throw: boolean;
11
+ protected client: HttpClientInterface;
12
+ protected defaultOptions: AxiosRequestConfig<any>;
13
+ V3_URI_PREFIXES: string[];
14
+ constructor(merchant: MerchantInterface, client: HttpClientInterface, defaultOptions?: Record<string, any>);
15
+ getInstance(): AxiosInstance;
16
+ setInstance(instance: AxiosInstance): this;
17
+ setLogger(logger: LogHandler): this;
18
+ request(method: Method, url: string, payload?: AxiosRequestConfig<any>): Promise<HttpClientResponse>;
19
+ /**
20
+ * 判断是否是V3请求
21
+ * @param url 请求地址
22
+ * @returns
23
+ */
24
+ protected isV3Request(url: string): boolean;
25
+ /**
26
+ * 创建签名(V3)
27
+ * @param method 请求方式
28
+ * @param url 请求地址
29
+ * @param payload 请求载荷
30
+ * @returns
31
+ */
32
+ protected createSignature(method: string, url: string, payload: AxiosRequestConfig<any>): string;
33
+ /**
34
+ * 创建签名(V2)
35
+ * @param body 请求参数
36
+ * @returns
37
+ */
38
+ protected attachLegacySignature(body: Record<string, any>): Record<string, string | number>;
39
+ }
40
+ interface Client extends HttpClientMethodsMixin, PresetMixin {
41
+ }
42
+ export = Client;
@@ -0,0 +1,125 @@
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 merge_1 = __importDefault(require("merge"));
15
+ const Utils_1 = require("../Core/Support/Utils");
16
+ const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
17
+ const HttpClientMethodsMixin_1 = __importDefault(require("../Core/HttpClient/Mixins/HttpClientMethodsMixin"));
18
+ const PresetMixin_1 = __importDefault(require("../Core/HttpClient/Mixins/PresetMixin"));
19
+ const url_1 = __importDefault(require("url"));
20
+ const Signature_1 = __importDefault(require("./Signature"));
21
+ const LegacySignature_1 = __importDefault(require("./LegacySignature"));
22
+ class Client {
23
+ constructor(merchant, client, defaultOptions = {}) {
24
+ var _a;
25
+ this.merchant = merchant;
26
+ this.throw = true;
27
+ this.client = null;
28
+ this.defaultOptions = {
29
+ baseURL: 'https://api.mch.weixin.qq.com',
30
+ headers: {
31
+ 'Content-Type': 'application/json',
32
+ 'Accept': 'application/json',
33
+ },
34
+ };
35
+ this.V3_URI_PREFIXES = [
36
+ '/v3/',
37
+ '/sandbox/v3/',
38
+ '/hk/v3/',
39
+ '/global/v3/',
40
+ ];
41
+ this.throw = !!((_a = defaultOptions['throw']) !== null && _a !== void 0 ? _a : true);
42
+ this.defaultOptions = merge_1.default.recursive(true, this.defaultOptions, defaultOptions);
43
+ this.client = client || HttpClient_1.default.create();
44
+ }
45
+ getInstance() {
46
+ return this.client.getInstance();
47
+ }
48
+ setInstance(instance) {
49
+ this.client.setInstance(instance);
50
+ return this;
51
+ }
52
+ setLogger(logger) {
53
+ this.client.setLogger(logger);
54
+ return this;
55
+ }
56
+ request(method, url, payload = {}) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (!payload.headers)
59
+ payload.headers = {};
60
+ if (!payload.headers['user-agent'] && !payload.headers['User-Agent']) {
61
+ payload.headers['user-agent'] = (0, Utils_1.createUserAgent)();
62
+ }
63
+ if (this.isV3Request(url)) {
64
+ payload.headers['authorization'] = this.createSignature(method, url, payload);
65
+ }
66
+ else {
67
+ if (payload.xml) {
68
+ if (Array.isArray(payload.xml)) {
69
+ payload.xml = (0, Utils_1.buildXml)(this.attachLegacySignature(payload.xml));
70
+ }
71
+ if (typeof payload.xml !== 'string') {
72
+ throw new Error('The `xml` option must be a string or object.');
73
+ }
74
+ payload.data = payload.xml;
75
+ delete payload.xml;
76
+ }
77
+ if (payload.data && typeof payload.data === 'object') {
78
+ payload.data = (0, Utils_1.buildXml)(this.attachLegacySignature(payload.data));
79
+ }
80
+ if (!payload.headers['content-type'] && !payload.headers['Content-Type']) {
81
+ payload.headers['content-type'] = 'text/xml';
82
+ }
83
+ }
84
+ if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
85
+ payload.headers = Object.assign(Object.assign({}, this.prependHeaders), payload.headers);
86
+ }
87
+ return this.client.request(method, (0, Utils_1.ltrim)(url, '\\/+'), payload);
88
+ });
89
+ }
90
+ /**
91
+ * 判断是否是V3请求
92
+ * @param url 请求地址
93
+ * @returns
94
+ */
95
+ isV3Request(url) {
96
+ let urlObj = url_1.default.parse(url);
97
+ for (let i = 0; i < this.V3_URI_PREFIXES.length; i++) {
98
+ if (urlObj.pathname.startsWith(this.V3_URI_PREFIXES[i])) {
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ }
104
+ /**
105
+ * 创建签名(V3)
106
+ * @param method 请求方式
107
+ * @param url 请求地址
108
+ * @param payload 请求载荷
109
+ * @returns
110
+ */
111
+ createSignature(method, url, payload) {
112
+ return (new Signature_1.default(this.merchant)).createHeader(method, url, payload);
113
+ }
114
+ /**
115
+ * 创建签名(V2)
116
+ * @param body 请求参数
117
+ * @returns
118
+ */
119
+ attachLegacySignature(body) {
120
+ return (new LegacySignature_1.default(this.merchant)).sign(body);
121
+ }
122
+ }
123
+ ;
124
+ (0, Utils_1.applyMixins)(Client, [HttpClientMethodsMixin_1.default, PresetMixin_1.default]);
125
+ module.exports = Client;
@@ -0,0 +1,5 @@
1
+ import BaseConfig from '../Core/Config';
2
+ declare class Config extends BaseConfig {
3
+ protected requiredKeys: string[];
4
+ }
5
+ export = Config;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const Config_1 = __importDefault(require("../Core/Config"));
6
+ class Config extends Config_1.default {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.requiredKeys = [
10
+ 'mch_id',
11
+ 'secret_key',
12
+ 'private_key',
13
+ 'certificate',
14
+ ];
15
+ }
16
+ }
17
+ module.exports = Config;
@@ -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,9 @@
1
+ import ResponseInterface from "../../Core/Http/Contracts/ResponseInterface";
2
+ declare abstract class ResponseValidatorInterface {
3
+ /**
4
+ * 验证响应对象
5
+ * @returns
6
+ */
7
+ validate(response: ResponseInterface): void;
8
+ }
9
+ export = ResponseValidatorInterface;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+ class ResponseValidatorInterface {
3
+ /**
4
+ * 验证响应对象
5
+ * @returns
6
+ */
7
+ validate(response) { }
8
+ }
9
+ ;
10
+ module.exports = ResponseValidatorInterface;