node-easywechat 3.0.0 → 3.1.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 +15 -0
- package/README.md +22 -1
- 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 +1 -4
- package/dist/Core/HttpClient/HttpClient.js +4 -4
- package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +0 -12
- package/dist/Core/HttpClient/Mixins/PresetMixin.js +0 -18
- 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/Application.d.ts +4 -4
- package/dist/Pay/Application.js +1 -1
- package/dist/Pay/Client.d.ts +12 -0
- package/dist/Pay/Client.js +27 -3
- package/dist/Pay/Signature.js +7 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -9,7 +9,7 @@ import { PayConfig } from '../Types/global';
|
|
|
9
9
|
import MerchantInterface from './Contracts/MerchantInterface';
|
|
10
10
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
11
11
|
import Utils from './Utils';
|
|
12
|
-
import
|
|
12
|
+
import Client from './Client';
|
|
13
13
|
/**
|
|
14
14
|
* 微信支付应用
|
|
15
15
|
*/
|
|
@@ -18,7 +18,7 @@ declare class Application implements ApplicationInterface {
|
|
|
18
18
|
protected merchant: MerchantInterface;
|
|
19
19
|
protected encryptor: Encryptor;
|
|
20
20
|
protected server: ServerInterface;
|
|
21
|
-
protected client:
|
|
21
|
+
protected client: Client;
|
|
22
22
|
getMerchant(): MerchantInterface;
|
|
23
23
|
/**
|
|
24
24
|
* 设置当前账户实例
|
|
@@ -34,13 +34,13 @@ declare class Application implements ApplicationInterface {
|
|
|
34
34
|
*/
|
|
35
35
|
setServer(server: ServerInterface): this;
|
|
36
36
|
getUtils(): Utils;
|
|
37
|
-
getClient():
|
|
37
|
+
getClient(): Client;
|
|
38
38
|
/**
|
|
39
39
|
* 设置客户端
|
|
40
40
|
* @param client
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
|
-
setClient(client:
|
|
43
|
+
setClient(client: Client): this;
|
|
44
44
|
/**
|
|
45
45
|
* 获取请求默认配置
|
|
46
46
|
* @returns
|
package/dist/Pay/Application.js
CHANGED
package/dist/Pay/Client.d.ts
CHANGED
|
@@ -36,6 +36,18 @@ declare class Client implements HttpClientInterface {
|
|
|
36
36
|
* @returns
|
|
37
37
|
*/
|
|
38
38
|
protected attachLegacySignature(body: Record<string, any>): Record<string, string | number>;
|
|
39
|
+
/**
|
|
40
|
+
* 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
41
|
+
* @param new_mch_id
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
withMchId(new_mch_id?: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
47
|
+
* @param new_alias
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
withMchIdAs(new_alias?: string): this;
|
|
39
51
|
}
|
|
40
52
|
interface Client extends HttpClientMethodsMixin, PresetMixin {
|
|
41
53
|
}
|
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 {
|
|
@@ -81,6 +80,9 @@ class Client {
|
|
|
81
80
|
payload.headers['content-type'] = 'text/xml';
|
|
82
81
|
}
|
|
83
82
|
}
|
|
83
|
+
if (this.prependData && Object.keys(this.prependData).length > 0) {
|
|
84
|
+
payload.data = Object.assign(Object.assign({}, this.prependData), payload.data);
|
|
85
|
+
}
|
|
84
86
|
if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
|
|
85
87
|
payload.headers = Object.assign(Object.assign({}, this.prependHeaders), payload.headers);
|
|
86
88
|
}
|
|
@@ -93,9 +95,13 @@ class Client {
|
|
|
93
95
|
* @returns
|
|
94
96
|
*/
|
|
95
97
|
isV3Request(url) {
|
|
96
|
-
let
|
|
98
|
+
let pathname = url;
|
|
99
|
+
if (url.startsWith('https://') || url.startsWith('http://')) {
|
|
100
|
+
let urlObj = new URL(url);
|
|
101
|
+
pathname = urlObj.pathname;
|
|
102
|
+
}
|
|
97
103
|
for (let i = 0; i < this.V3_URI_PREFIXES.length; i++) {
|
|
98
|
-
if (
|
|
104
|
+
if (pathname.startsWith(this.V3_URI_PREFIXES[i])) {
|
|
99
105
|
return true;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
@@ -119,6 +125,24 @@ class Client {
|
|
|
119
125
|
attachLegacySignature(body) {
|
|
120
126
|
return (new LegacySignature_1.default(this.merchant)).sign(body);
|
|
121
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
130
|
+
* @param new_mch_id
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
withMchId(new_mch_id = null) {
|
|
134
|
+
this.with('mch_id', new_mch_id);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
139
|
+
* @param new_alias
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
withMchIdAs(new_alias = null) {
|
|
143
|
+
this.with(new_alias, this.presets['mch_id']);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
122
146
|
}
|
|
123
147
|
;
|
|
124
148
|
(0, Utils_1.applyMixins)(Client, [HttpClientMethodsMixin_1.default, PresetMixin_1.default]);
|
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());
|