node-easywechat 3.0.1 → 3.1.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/CHANGELOG.md +17 -1
- package/README.md +27 -2
- package/dist/Core/Config.d.ts +1 -1
- package/dist/Core/Config.js +3 -1
- package/dist/Core/HttpClient/Contracts/HttpClientInterface.d.ts +7 -1
- package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +6 -0
- package/dist/Core/HttpClient/HttpClient.d.ts +3 -6
- package/dist/Core/HttpClient/HttpClient.js +10 -5
- package/dist/Core/Support/Obj.js +4 -2
- package/dist/MiniApp/Application.d.ts +4 -4
- package/dist/MiniApp/Application.js +1 -1
- package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OfficialAccount/Application.d.ts +4 -4
- package/dist/OfficialAccount/Application.js +1 -1
- package/dist/OfficialAccount/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OpenPlatform/Account.d.ts +13 -0
- package/dist/OpenPlatform/Account.js +22 -0
- package/dist/OpenPlatform/Application.d.ts +152 -0
- package/dist/OpenPlatform/Application.js +355 -0
- package/dist/OpenPlatform/Authorization.d.ts +23 -0
- package/dist/OpenPlatform/Authorization.js +74 -0
- package/dist/OpenPlatform/AuthorizerAccessToken.d.ts +19 -0
- package/dist/OpenPlatform/AuthorizerAccessToken.js +43 -0
- package/dist/OpenPlatform/ComponentAccessToken.d.ts +28 -0
- package/dist/OpenPlatform/ComponentAccessToken.js +85 -0
- package/dist/OpenPlatform/Config.d.ts +5 -0
- package/dist/OpenPlatform/Config.js +16 -0
- package/dist/OpenPlatform/Contracts/AccountInterface.d.ts +23 -0
- package/dist/OpenPlatform/Contracts/AccountInterface.js +25 -0
- package/dist/OpenPlatform/Contracts/ApplicationInterface.d.ts +68 -0
- package/dist/OpenPlatform/Contracts/ApplicationInterface.js +60 -0
- package/dist/OpenPlatform/Contracts/VerifyTicketInterface.d.ts +23 -0
- package/dist/OpenPlatform/Contracts/VerifyTicketInterface.js +25 -0
- package/dist/OpenPlatform/Message.d.ts +43 -0
- package/dist/OpenPlatform/Message.js +9 -0
- package/dist/OpenPlatform/Server.d.ts +61 -0
- package/dist/OpenPlatform/Server.js +136 -0
- package/dist/OpenPlatform/VerifyTicket.d.ts +13 -0
- package/dist/OpenPlatform/VerifyTicket.js +49 -0
- package/dist/Pay/Client.js +6 -3
- package/dist/Pay/Signature.js +7 -6
- package/dist/Types/global.d.ts +30 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/package.json +3 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class AccountInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取appid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAppId() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取secret
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getSecret() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取token
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getToken() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取aesKey
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getAesKey() { return null; }
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
module.exports = AccountInterface;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import ProviderInterface from "node-socialite/dist/Core/ProviderInterface";
|
|
2
|
+
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
3
|
+
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
4
|
+
import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
|
|
5
|
+
import HttpClientInterface from "../../Core/HttpClient/Contracts/HttpClientInterface";
|
|
6
|
+
import ServerInterface from "../../Core/Contracts/ServerInterface";
|
|
7
|
+
import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInterface";
|
|
8
|
+
import Encryptor from "../../Core/Encryptor";
|
|
9
|
+
import AccountInterface from "./AccountInterface";
|
|
10
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
11
|
+
declare abstract class ApplicationInterface {
|
|
12
|
+
/**
|
|
13
|
+
* 获取当前账户实例
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getAccount(): AccountInterface;
|
|
17
|
+
/**
|
|
18
|
+
* 获取加密机实例
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getEncryptor(): Encryptor;
|
|
22
|
+
/**
|
|
23
|
+
* 获取服务端实例
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
getServer(): ServerInterface;
|
|
27
|
+
/**
|
|
28
|
+
* 获取当前请求实例
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
getRequest(): ServerRequestInterface;
|
|
32
|
+
/**
|
|
33
|
+
* 获取客户端实例
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
getClient(): AccessTokenAwareClient;
|
|
37
|
+
/**
|
|
38
|
+
* 创建客户端实例
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
createClient(): AccessTokenAwareClient;
|
|
42
|
+
/**
|
|
43
|
+
* 获取网络请求客户端实例
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getHttpClient(): HttpClientInterface;
|
|
47
|
+
/**
|
|
48
|
+
* 获取配置信息实例
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
getConfig(): ConfigInterface;
|
|
52
|
+
/**
|
|
53
|
+
* 获取AccessToken实例
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getAccessToken(): AccessTokenInterface;
|
|
57
|
+
/**
|
|
58
|
+
* 获取缓存实例
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
getCache(): CacheInterface;
|
|
62
|
+
/**
|
|
63
|
+
* 获取OAuth实例
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
getOAuth(): ProviderInterface;
|
|
67
|
+
}
|
|
68
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class ApplicationInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取当前账户实例
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAccount() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取加密机实例
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getEncryptor() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取服务端实例
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getServer() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取当前请求实例
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getRequest() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取客户端实例
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getClient() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 创建客户端实例
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
createClient() { return null; }
|
|
33
|
+
/**
|
|
34
|
+
* 获取网络请求客户端实例
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getHttpClient() { return null; }
|
|
38
|
+
/**
|
|
39
|
+
* 获取配置信息实例
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getConfig() { return null; }
|
|
43
|
+
/**
|
|
44
|
+
* 获取AccessToken实例
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getAccessToken() { return null; }
|
|
48
|
+
/**
|
|
49
|
+
* 获取缓存实例
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getCache() { return null; }
|
|
53
|
+
/**
|
|
54
|
+
* 获取OAuth实例
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getOAuth() { return null; }
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare abstract class VerifyTicketInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取ticket缓存名
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getKey(): string;
|
|
7
|
+
/**
|
|
8
|
+
* 设置ticket缓存名
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
setKey(key: string): this;
|
|
12
|
+
/**
|
|
13
|
+
* 设置ticket
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
setTicket(key: string): Promise<this>;
|
|
17
|
+
/**
|
|
18
|
+
* 获取ticket
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getTicket(): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export = VerifyTicketInterface;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class VerifyTicketInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取ticket缓存名
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getKey() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 设置ticket缓存名
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
setKey(key) { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 设置ticket
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
setTicket(key) { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取ticket
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getTicket() { return null; }
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
module.exports = VerifyTicketInterface;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import BaseMessage from '../Core/Message';
|
|
2
|
+
declare class Message extends BaseMessage {
|
|
3
|
+
}
|
|
4
|
+
interface Message {
|
|
5
|
+
/**
|
|
6
|
+
* 第三方平台 appid
|
|
7
|
+
*/
|
|
8
|
+
AppId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* 时间戳
|
|
11
|
+
*/
|
|
12
|
+
CreateTime?: number;
|
|
13
|
+
/**
|
|
14
|
+
* 通知类型
|
|
15
|
+
* - authorized:授权成功
|
|
16
|
+
* - unauthorized:取消授权
|
|
17
|
+
* - updateauthorized:更新授权
|
|
18
|
+
* - component_verify_ticket:验证票据
|
|
19
|
+
* @see [授权变更通知推送](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/authorize_event.html)
|
|
20
|
+
* @see [验证票据](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/component_verify_ticket.html)
|
|
21
|
+
*/
|
|
22
|
+
InfoType?: 'authorized' | 'unauthorized' | 'updateauthorized' | 'component_verify_ticket';
|
|
23
|
+
/**
|
|
24
|
+
* 公众号或小程序的 appid
|
|
25
|
+
*/
|
|
26
|
+
AuthorizerAppid?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 授权码,可用于获取授权信息
|
|
29
|
+
* @scope InfoType='authorized' | 'updateauthorized'
|
|
30
|
+
*/
|
|
31
|
+
AuthorizationCode?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 授权码过期时间,单位:秒
|
|
34
|
+
* @scope InfoType='authorized' | 'updateauthorized'
|
|
35
|
+
*/
|
|
36
|
+
AuthorizationCodeExpiredTime?: number;
|
|
37
|
+
/**
|
|
38
|
+
* 预授权码
|
|
39
|
+
* @scope InfoType='authorized' | 'updateauthorized'
|
|
40
|
+
*/
|
|
41
|
+
PreAuthCode?: string;
|
|
42
|
+
}
|
|
43
|
+
export = Message;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
8
|
+
;
|
|
9
|
+
module.exports = Message;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import ServerRequestInterface from '../Core/Http/Contracts/ServerRequestInterface';
|
|
2
|
+
import Encryptor from '../Core/Encryptor';
|
|
3
|
+
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
4
|
+
import Response from '../Core/Http/Response';
|
|
5
|
+
import Message from './Message';
|
|
6
|
+
import { ServerHandlerClosure } from '../Types/global';
|
|
7
|
+
declare class Server extends ServerInterface {
|
|
8
|
+
protected encryptor: Encryptor;
|
|
9
|
+
protected request: ServerRequestInterface;
|
|
10
|
+
protected defaultVerifyTicketHandler: ServerHandlerClosure;
|
|
11
|
+
constructor(encryptor: Encryptor, request?: ServerRequestInterface);
|
|
12
|
+
/**
|
|
13
|
+
* 服务端消息处理
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
serve(): Promise<Response>;
|
|
17
|
+
/**
|
|
18
|
+
* 处理授权成功通知
|
|
19
|
+
* @param handler
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
handleAuthorized(handler: ServerHandlerClosure): this;
|
|
23
|
+
/**
|
|
24
|
+
* 处理取消授权通知
|
|
25
|
+
* @param handler
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
handleUnauthorized(handler: ServerHandlerClosure): this;
|
|
29
|
+
/**
|
|
30
|
+
* 处理授权更新通知
|
|
31
|
+
* @param handler
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
handleAuthorizeUpdated(handler: ServerHandlerClosure): this;
|
|
35
|
+
/**
|
|
36
|
+
* 设置默认的验证票据通知处理回调
|
|
37
|
+
* @param handler
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
withDefaultVerifyTicketHandler(handler: ServerHandlerClosure): void;
|
|
41
|
+
/**
|
|
42
|
+
* 处理验证票据通知
|
|
43
|
+
* @param handler
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
handleVerifyTicketRefreshed(handler: ServerHandlerClosure): this;
|
|
47
|
+
protected decryptRequestMessage(): ServerHandlerClosure;
|
|
48
|
+
/**
|
|
49
|
+
* 获取来自微信服务器的推送消息
|
|
50
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
getRequestMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
54
|
+
/**
|
|
55
|
+
* 获取来自微信服务器的推送消息(解密后)
|
|
56
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
getDecryptedMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
60
|
+
}
|
|
61
|
+
export = Server;
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
class Server extends ServerInterface_1.default {
|
|
18
|
+
constructor(encryptor, request = null) {
|
|
19
|
+
super();
|
|
20
|
+
this.encryptor = encryptor;
|
|
21
|
+
this.request = request;
|
|
22
|
+
this.defaultVerifyTicketHandler = null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 服务端消息处理
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
serve() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
let echostr = this.request.getQueryParams()['echostr'] || '';
|
|
31
|
+
if (!!echostr) {
|
|
32
|
+
return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
|
|
33
|
+
}
|
|
34
|
+
let message = yield this.getRequestMessage(this.request);
|
|
35
|
+
this.prepend(this.decryptRequestMessage());
|
|
36
|
+
let response = yield this.handle(new Response_1.default(200, {}, 'success'), message);
|
|
37
|
+
if (!(response instanceof Response_1.default)) {
|
|
38
|
+
response = yield this.transformToReply(response, message, this.encryptor);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 处理授权成功通知
|
|
45
|
+
* @param handler
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
handleAuthorized(handler) {
|
|
49
|
+
return this.with(function (message, next) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return message.InfoType === 'authorized' ? handler(message, next) : next(message);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 处理取消授权通知
|
|
57
|
+
* @param handler
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
handleUnauthorized(handler) {
|
|
61
|
+
return this.with(function (message, next) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return message.InfoType === 'unauthorized' ? handler(message, next) : next(message);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 处理授权更新通知
|
|
69
|
+
* @param handler
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
handleAuthorizeUpdated(handler) {
|
|
73
|
+
return this.with(function (message, next) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return message.InfoType === 'updateauthorized' ? handler(message, next) : next(message);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 设置默认的验证票据通知处理回调
|
|
81
|
+
* @param handler
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
withDefaultVerifyTicketHandler(handler) {
|
|
85
|
+
this.defaultVerifyTicketHandler = () => {
|
|
86
|
+
return handler.call(this, arguments);
|
|
87
|
+
};
|
|
88
|
+
this.handleVerifyTicketRefreshed(this.defaultVerifyTicketHandler);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 处理验证票据通知
|
|
92
|
+
* @param handler
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
handleVerifyTicketRefreshed(handler) {
|
|
96
|
+
if (this.defaultVerifyTicketHandler) {
|
|
97
|
+
this.withoutHandler(this.defaultVerifyTicketHandler);
|
|
98
|
+
}
|
|
99
|
+
return this.with(function (message, next) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return message.InfoType === 'component_verify_ticket' ? handler(message, next) : next(message);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
decryptRequestMessage() {
|
|
106
|
+
let query = this.request.getQueryParams();
|
|
107
|
+
return (message, next) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
yield this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
|
|
109
|
+
return next(message);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 获取来自微信服务器的推送消息
|
|
114
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
getRequestMessage(request = null) {
|
|
118
|
+
return Message_1.default.createFromRequest(request || this.request);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 获取来自微信服务器的推送消息(解密后)
|
|
122
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
getDecryptedMessage(request = null) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
if (!request)
|
|
128
|
+
request = this.request;
|
|
129
|
+
let message = yield Message_1.default.createFromRequest(request);
|
|
130
|
+
let query = request.getQueryParams();
|
|
131
|
+
return this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
;
|
|
136
|
+
module.exports = Server;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import CacheInterface from '../Core/Contracts/CacheInterface';
|
|
2
|
+
import VerifyTicketInterface from './Contracts/VerifyTicketInterface';
|
|
3
|
+
declare class VerifyTicket implements VerifyTicketInterface {
|
|
4
|
+
protected appId: string;
|
|
5
|
+
protected key: string;
|
|
6
|
+
protected cache: CacheInterface;
|
|
7
|
+
constructor(appId: string, key?: string, cache?: CacheInterface);
|
|
8
|
+
getKey(): string;
|
|
9
|
+
setKey(key: string): this;
|
|
10
|
+
setTicket(ticket: string): Promise<this>;
|
|
11
|
+
getTicket(): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export = VerifyTicket;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 FileCache_1 = __importDefault(require("../Core/Cache/FileCache"));
|
|
15
|
+
class VerifyTicket {
|
|
16
|
+
constructor(appId, key = null, cache = null) {
|
|
17
|
+
this.appId = appId;
|
|
18
|
+
this.key = key;
|
|
19
|
+
this.cache = cache;
|
|
20
|
+
this.cache = cache !== null && cache !== void 0 ? cache : new FileCache_1.default();
|
|
21
|
+
}
|
|
22
|
+
getKey() {
|
|
23
|
+
if (!this.key) {
|
|
24
|
+
this.key = `open_platform.verify_ticket.${this.appId}`;
|
|
25
|
+
}
|
|
26
|
+
return this.key;
|
|
27
|
+
}
|
|
28
|
+
setKey(key) {
|
|
29
|
+
this.key = key;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setTicket(ticket) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield this.cache.set(this.getKey(), ticket, 6000);
|
|
35
|
+
return this;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getTicket() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let ticket = yield this.cache.get(this.getKey());
|
|
41
|
+
if (!ticket || typeof ticket != 'string') {
|
|
42
|
+
throw new Error('No component_verify_ticket found.');
|
|
43
|
+
}
|
|
44
|
+
return ticket;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
module.exports = VerifyTicket;
|
package/dist/Pay/Client.js
CHANGED
|
@@ -16,7 +16,6 @@ const Utils_1 = require("../Core/Support/Utils");
|
|
|
16
16
|
const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
|
|
17
17
|
const HttpClientMethodsMixin_1 = __importDefault(require("../Core/HttpClient/Mixins/HttpClientMethodsMixin"));
|
|
18
18
|
const PresetMixin_1 = __importDefault(require("../Core/HttpClient/Mixins/PresetMixin"));
|
|
19
|
-
const url_1 = __importDefault(require("url"));
|
|
20
19
|
const Signature_1 = __importDefault(require("./Signature"));
|
|
21
20
|
const LegacySignature_1 = __importDefault(require("./LegacySignature"));
|
|
22
21
|
class Client {
|
|
@@ -96,9 +95,13 @@ class Client {
|
|
|
96
95
|
* @returns
|
|
97
96
|
*/
|
|
98
97
|
isV3Request(url) {
|
|
99
|
-
let
|
|
98
|
+
let pathname = url;
|
|
99
|
+
if (url.startsWith('https://') || url.startsWith('http://')) {
|
|
100
|
+
let urlObj = new URL(url);
|
|
101
|
+
pathname = urlObj.pathname;
|
|
102
|
+
}
|
|
100
103
|
for (let i = 0; i < this.V3_URI_PREFIXES.length; i++) {
|
|
101
|
-
if (
|
|
104
|
+
if (pathname.startsWith(this.V3_URI_PREFIXES[i])) {
|
|
102
105
|
return true;
|
|
103
106
|
}
|
|
104
107
|
}
|
package/dist/Pay/Signature.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const Utils_1 = require("../Core/Support/Utils");
|
|
6
6
|
const merge_1 = __importDefault(require("merge"));
|
|
7
|
-
const url_1 = __importDefault(require("url"));
|
|
8
7
|
const RSA_1 = __importDefault(require("../Core/Support/RSA"));
|
|
9
8
|
class Signature {
|
|
10
9
|
constructor(merchant) {
|
|
@@ -18,12 +17,14 @@ class Signature {
|
|
|
18
17
|
* @returns
|
|
19
18
|
*/
|
|
20
19
|
createHeader(method, url, payload) {
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
let pathname = url;
|
|
21
|
+
if (url.startsWith('https://') || url.startsWith('http://')) {
|
|
22
|
+
let urlObj = new URL(url);
|
|
23
|
+
let search = (0, Utils_1.buildQueryString)((0, merge_1.default)(true, urlObj.searchParams, payload.params));
|
|
24
|
+
pathname = urlObj.pathname + (search ? '?' + search : '');
|
|
25
|
+
}
|
|
24
26
|
let nonce = (0, Utils_1.randomString)();
|
|
25
27
|
let timestamp = (0, Utils_1.getTimestamp)();
|
|
26
|
-
let path = uri.pathname + (uri.query ? '?' + uri.query : '');
|
|
27
28
|
let body = '';
|
|
28
29
|
if (payload.data) {
|
|
29
30
|
if (typeof payload.data === 'object') {
|
|
@@ -33,7 +34,7 @@ class Signature {
|
|
|
33
34
|
body = payload.data;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
let signString = `${method.toUpperCase()}\n${
|
|
37
|
+
let signString = `${method.toUpperCase()}\n${pathname}\n${timestamp}\n${nonce}\n${body}`;
|
|
37
38
|
let rsa = new RSA_1.default;
|
|
38
39
|
rsa.setPublicKey(this.merchant.getCertificate().toString());
|
|
39
40
|
rsa.setPrivateKey(this.merchant.getPrivateKey().toString());
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -74,6 +74,35 @@ export declare interface CacheFileConfig {
|
|
|
74
74
|
ext: string
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* 网络请求配置
|
|
79
|
+
*/
|
|
80
|
+
export declare interface HttpConfig extends AxiosRequestConfig {
|
|
81
|
+
/**
|
|
82
|
+
* 是否抛出异常
|
|
83
|
+
*/
|
|
84
|
+
throw?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* 是否抛出异常
|
|
87
|
+
* @see https://github.com/softonic/axios-retry#options
|
|
88
|
+
*/
|
|
89
|
+
retry?: IAxiosRetry.IAxiosRetryConfig;
|
|
90
|
+
// retry?: {
|
|
91
|
+
// /**
|
|
92
|
+
// * 仅以下状态码重试
|
|
93
|
+
// */
|
|
94
|
+
// http_codes: number[];
|
|
95
|
+
// /**
|
|
96
|
+
// * 最大重试次数
|
|
97
|
+
// */
|
|
98
|
+
// max_retries: number;
|
|
99
|
+
// /**
|
|
100
|
+
// * 请求间隔 (毫秒)
|
|
101
|
+
// */
|
|
102
|
+
// delay: number;
|
|
103
|
+
// };
|
|
104
|
+
}
|
|
105
|
+
|
|
77
106
|
/**
|
|
78
107
|
* 基础配置
|
|
79
108
|
*/
|
|
@@ -81,7 +110,7 @@ export declare interface BaseConfig {
|
|
|
81
110
|
/**
|
|
82
111
|
* 网络请求相关配置
|
|
83
112
|
*/
|
|
84
|
-
http?:
|
|
113
|
+
http?: HttpConfig;
|
|
85
114
|
|
|
86
115
|
/**
|
|
87
116
|
* 文件缓存相关配置
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig } from './Types/global';
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig, OpenPlatformConfig } from './Types/global';
|
|
2
2
|
import OfficialAccount from './OfficialAccount/Application';
|
|
3
3
|
import MiniApp from './MiniApp/Application';
|
|
4
4
|
import Pay from './Pay/Application';
|
|
5
|
+
import OpenPlatform from './OpenPlatform/Application';
|
|
5
6
|
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
6
7
|
import ServerRequest from './Core/Http/ServerRequest';
|
|
7
8
|
import FormData from 'form-data';
|
|
8
|
-
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
9
|
+
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, OpenPlatform, OpenPlatformConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
9
10
|
/**
|
|
10
11
|
* 表单对象
|
|
11
12
|
* @see https://github.com/axios/axios#formdata
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,15 @@ 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.ServerRequest = exports.CacheInterface = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
6
|
+
exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.OpenPlatform = 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
11
|
const Application_3 = __importDefault(require("./Pay/Application"));
|
|
12
12
|
exports.Pay = Application_3.default;
|
|
13
|
+
const Application_4 = __importDefault(require("./OpenPlatform/Application"));
|
|
14
|
+
exports.OpenPlatform = Application_4.default;
|
|
13
15
|
const CacheInterface_1 = __importDefault(require("./Core/Contracts/CacheInterface"));
|
|
14
16
|
exports.CacheInterface = CacheInterface_1.default;
|
|
15
17
|
const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|