node-easywechat 3.1.3 → 3.2.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/.github/workflows/build-2.yml +21 -0
- package/.github/workflows/build-3.yml +21 -0
- package/.github/workflows/publish-npm-2.yml +24 -0
- package/.github/workflows/publish-npm-3.yml +24 -0
- package/CHANGELOG.md +6 -0
- package/README.md +23 -2
- package/dist/Types/global.d.ts +8 -0
- package/dist/Work/AccessToken.d.ts +26 -0
- package/dist/Work/AccessToken.js +84 -0
- package/dist/Work/Account.d.ts +13 -0
- package/dist/Work/Account.js +25 -0
- package/dist/Work/Application.d.ts +75 -0
- package/dist/Work/Application.js +177 -0
- package/dist/Work/Config.d.ts +5 -0
- package/dist/Work/Config.js +17 -0
- package/dist/Work/Contracts/AccountInterface.d.ts +23 -0
- package/dist/Work/Contracts/AccountInterface.js +25 -0
- package/dist/Work/Contracts/ApplicationInterface.d.ts +87 -0
- package/dist/Work/Contracts/ApplicationInterface.js +76 -0
- package/dist/Work/Encryptor.d.ts +9 -0
- package/dist/Work/Encryptor.js +17 -0
- package/dist/Work/JsApiTicket.d.ts +45 -0
- package/dist/Work/JsApiTicket.js +141 -0
- package/dist/Work/Message.d.ts +142 -0
- package/dist/Work/Message.js +9 -0
- package/dist/Work/Server.d.ts +90 -0
- package/dist/Work/Server.js +212 -0
- package/dist/Work/Utils.d.ts +25 -0
- package/dist/Work/Utils.js +56 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
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 { WorkOAuthFactory } from "../../Types/global";
|
|
11
|
+
import JsApiTicket from "../JsApiTicket";
|
|
12
|
+
import Utils from "../Utils";
|
|
13
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
14
|
+
declare abstract class ApplicationInterface {
|
|
15
|
+
/**
|
|
16
|
+
* 获取当前账户实例
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
getAccount(): AccountInterface;
|
|
20
|
+
/**
|
|
21
|
+
* 获取加密机实例
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
getEncryptor(): Encryptor;
|
|
25
|
+
/**
|
|
26
|
+
* 获取服务端实例
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getServer(): ServerInterface;
|
|
30
|
+
/**
|
|
31
|
+
* 获取当前请求实例
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getRequest(): ServerRequestInterface;
|
|
35
|
+
/**
|
|
36
|
+
* 获取客户端实例
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
getClient(): AccessTokenAwareClient;
|
|
40
|
+
/**
|
|
41
|
+
* 创建客户端实例
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
createClient(): AccessTokenAwareClient;
|
|
45
|
+
/**
|
|
46
|
+
* 获取网络请求客户端实例
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
getHttpClient(): HttpClientInterface;
|
|
50
|
+
/**
|
|
51
|
+
* 获取配置信息实例
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
getConfig(): ConfigInterface;
|
|
55
|
+
/**
|
|
56
|
+
* 获取AccessToken实例
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
getAccessToken(): AccessTokenInterface;
|
|
60
|
+
/**
|
|
61
|
+
* 获取缓存实例
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getCache(): CacheInterface;
|
|
65
|
+
/**
|
|
66
|
+
* 获取OAuth实例
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
getOAuth(): Promise<ProviderInterface>;
|
|
70
|
+
/**
|
|
71
|
+
* 获取JsApiTicket实例
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
getTicket(): JsApiTicket;
|
|
75
|
+
/**
|
|
76
|
+
* 获取工具实例
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
getUtils(): Utils;
|
|
80
|
+
/**
|
|
81
|
+
* 设置OAuth工厂方法
|
|
82
|
+
* @param oauthFactory
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
setOAuthFactory(oauthFactory: WorkOAuthFactory): this;
|
|
86
|
+
}
|
|
87
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* 获取JsApiTicket实例
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
getTicket() { return null; }
|
|
63
|
+
/**
|
|
64
|
+
* 获取工具实例
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
getUtils() { return null; }
|
|
68
|
+
/**
|
|
69
|
+
* 设置OAuth工厂方法
|
|
70
|
+
* @param oauthFactory
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
setOAuthFactory(oauthFactory) { return this; }
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import BaseEncryptor from '../Core/Encryptor';
|
|
3
|
+
declare class Encryptor extends BaseEncryptor {
|
|
4
|
+
protected corpId: string;
|
|
5
|
+
protected token: string;
|
|
6
|
+
protected aesKey: string | Buffer;
|
|
7
|
+
constructor(corpId?: string, token?: string, aesKey?: string | Buffer);
|
|
8
|
+
}
|
|
9
|
+
export = Encryptor;
|
|
@@ -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 Encryptor_1 = __importDefault(require("../Core/Encryptor"));
|
|
6
|
+
class Encryptor extends Encryptor_1.default {
|
|
7
|
+
constructor(corpId = null, token = null, aesKey = null) {
|
|
8
|
+
super(corpId, token, aesKey, null);
|
|
9
|
+
this.corpId = corpId;
|
|
10
|
+
this.token = token;
|
|
11
|
+
this.aesKey = aesKey;
|
|
12
|
+
if (typeof this.aesKey === 'string') {
|
|
13
|
+
this.aesKey = Buffer.from(this.aesKey + '=', 'base64');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
module.exports = Encryptor;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import AccessToken from './AccessToken';
|
|
2
|
+
declare class JsApiTicket extends AccessToken {
|
|
3
|
+
protected agentKey: string;
|
|
4
|
+
/**
|
|
5
|
+
* 获取jsapi_ticket的缓存名称
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
getKey(): string;
|
|
9
|
+
/**
|
|
10
|
+
* 获取签名凭证jsapi_ticket
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
getTicket(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* 获取签名配置
|
|
16
|
+
* @param url 完整URL地址
|
|
17
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
18
|
+
* @param timestamp 时间长,默认:当前时间
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
createConfigSignature(url: string, nonce?: string, timestamp?: number): Promise<Record<string, any>>;
|
|
22
|
+
protected getTicketSignature(ticket: string, nonce: string, timestamp: number, url: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 获取代理应用的签名配置
|
|
25
|
+
* @param agentId 代理应用的id
|
|
26
|
+
* @param url 完整URL地址
|
|
27
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
28
|
+
* @param timestamp 时间长,默认:当前时间
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
createAgentConfigSignature(agentId: number, url: string, nonce?: string, timestamp?: number): Promise<Record<string, any>>;
|
|
32
|
+
/**
|
|
33
|
+
* 获取代理应用的签名凭证jsapi_ticket
|
|
34
|
+
* @param agentId 代理应用的id
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getAgentTicket(agentId: number): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取代理应用的jsapi_ticket的缓存名称
|
|
40
|
+
* @param agentId 代理应用的id
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getAgentKey(agentId: number): string;
|
|
44
|
+
}
|
|
45
|
+
export = JsApiTicket;
|
|
@@ -0,0 +1,141 @@
|
|
|
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 Utils_1 = require("../Core/Support/Utils");
|
|
15
|
+
const AccessToken_1 = __importDefault(require("./AccessToken"));
|
|
16
|
+
class JsApiTicket extends AccessToken_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.agentKey = null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 获取jsapi_ticket的缓存名称
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getKey() {
|
|
26
|
+
if (!this.key) {
|
|
27
|
+
this.key = `work.jsapi_ticket.${this.corpId}`;
|
|
28
|
+
}
|
|
29
|
+
return this.key;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 获取签名凭证jsapi_ticket
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
getTicket() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
let key = this.getKey();
|
|
38
|
+
let ticket = '';
|
|
39
|
+
if (this.cache) {
|
|
40
|
+
ticket = yield this.cache.get(key);
|
|
41
|
+
}
|
|
42
|
+
if (!!ticket && typeof ticket === 'string') {
|
|
43
|
+
return ticket;
|
|
44
|
+
}
|
|
45
|
+
let response = (yield this.httpClient.request('get', '/cgi-bin/get_jsapi_ticket', {})).toObject();
|
|
46
|
+
if (!response['ticket']) {
|
|
47
|
+
throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
|
|
48
|
+
}
|
|
49
|
+
if (this.cache) {
|
|
50
|
+
yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
|
|
51
|
+
}
|
|
52
|
+
return response['ticket'];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 获取签名配置
|
|
57
|
+
* @param url 完整URL地址
|
|
58
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
59
|
+
* @param timestamp 时间长,默认:当前时间
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
createConfigSignature(url, nonce = null, timestamp = null) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
nonce = nonce || (0, Utils_1.randomString)(10);
|
|
65
|
+
timestamp = timestamp || (0, Utils_1.getTimestamp)();
|
|
66
|
+
let ticket = yield this.getTicket();
|
|
67
|
+
return {
|
|
68
|
+
url,
|
|
69
|
+
nonceStr: nonce,
|
|
70
|
+
timestamp,
|
|
71
|
+
appId: this.corpId,
|
|
72
|
+
signature: this.getTicketSignature(ticket, nonce, timestamp, url),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getTicketSignature(ticket, nonce, timestamp, url) {
|
|
77
|
+
return (0, Utils_1.createHash)(`jsapi_ticket=${ticket}&noncestr=${nonce}×tamp=${timestamp}&url=${url}`, 'sha1');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 获取代理应用的签名配置
|
|
81
|
+
* @param agentId 代理应用的id
|
|
82
|
+
* @param url 完整URL地址
|
|
83
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
84
|
+
* @param timestamp 时间长,默认:当前时间
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
createAgentConfigSignature(agentId, url, nonce = null, timestamp = null) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
nonce = nonce || (0, Utils_1.randomString)(10);
|
|
90
|
+
timestamp = timestamp || (0, Utils_1.getTimestamp)();
|
|
91
|
+
let ticket = yield this.getTicket();
|
|
92
|
+
return {
|
|
93
|
+
corpid: this.corpId,
|
|
94
|
+
agentid: agentId,
|
|
95
|
+
url,
|
|
96
|
+
nonceStr: nonce,
|
|
97
|
+
timestamp,
|
|
98
|
+
signature: this.getTicketSignature(ticket, nonce, timestamp, url),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 获取代理应用的签名凭证jsapi_ticket
|
|
104
|
+
* @param agentId 代理应用的id
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
getAgentTicket(agentId) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
let key = this.getAgentKey(agentId);
|
|
110
|
+
let ticket = '';
|
|
111
|
+
if (this.cache) {
|
|
112
|
+
ticket = yield this.cache.get(key);
|
|
113
|
+
}
|
|
114
|
+
if (!!ticket && typeof ticket === 'string') {
|
|
115
|
+
return ticket;
|
|
116
|
+
}
|
|
117
|
+
let response = (yield this.httpClient.request('get', '/cgi-bin/ticket/get', {
|
|
118
|
+
params: {
|
|
119
|
+
type: 'agent_config',
|
|
120
|
+
}
|
|
121
|
+
})).toObject();
|
|
122
|
+
if (!response['ticket']) {
|
|
123
|
+
throw new Error('Failed to get jssdk agentTicket: ' + JSON.stringify(response));
|
|
124
|
+
}
|
|
125
|
+
if (this.cache) {
|
|
126
|
+
yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
|
|
127
|
+
}
|
|
128
|
+
return response['ticket'];
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 获取代理应用的jsapi_ticket的缓存名称
|
|
133
|
+
* @param agentId 代理应用的id
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
getAgentKey(agentId) {
|
|
137
|
+
return `${this.getKey()}.${agentId}`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
;
|
|
141
|
+
module.exports = JsApiTicket;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import BaseMessage from '../Core/Message';
|
|
2
|
+
declare class Message extends BaseMessage {
|
|
3
|
+
}
|
|
4
|
+
interface Message extends Record<string, any> {
|
|
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
|
+
* - `location` 地理位置
|
|
29
|
+
* - `link` 链接
|
|
30
|
+
*/
|
|
31
|
+
MsgType?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 事件类型
|
|
34
|
+
* - `change_contact` 通讯录变更事件
|
|
35
|
+
* - `change_chain` 上下游变更事件
|
|
36
|
+
* - `batch_job_result` 上下游异步任务完成事件
|
|
37
|
+
* @scope MsgType='event'
|
|
38
|
+
*/
|
|
39
|
+
Event?: string;
|
|
40
|
+
/**
|
|
41
|
+
* 变更类型
|
|
42
|
+
*
|
|
43
|
+
* 通讯录变更事件:
|
|
44
|
+
* - `create_user` 新增成员
|
|
45
|
+
* - `update_user` 更新成员
|
|
46
|
+
* - `delete_user` 删除成员
|
|
47
|
+
* - `create_party` 新增部门
|
|
48
|
+
* - `update_party` 更新部门
|
|
49
|
+
* - `delete_party` 删除部门
|
|
50
|
+
* - `update_tag` 标签变更
|
|
51
|
+
*
|
|
52
|
+
* 上下游变更事件:
|
|
53
|
+
* - `create_chain` 新增上下游空间
|
|
54
|
+
* - `update_chain` 更新上下游空间
|
|
55
|
+
* - `delete_chain` 删除上下游空间
|
|
56
|
+
* - `create_group` 新增上下游分组
|
|
57
|
+
* - `update_group` 更新上下游空间
|
|
58
|
+
* - `delete_group` 删除上下游空间
|
|
59
|
+
* - `corp_join` 企业加入上下游
|
|
60
|
+
* - `update_corp` 更新加入上下游企业
|
|
61
|
+
* - `remove_corp` 删除上下游企业
|
|
62
|
+
*
|
|
63
|
+
* @scope Event='change_contact' | 'change_chain'
|
|
64
|
+
*/
|
|
65
|
+
ChangeType?: string;
|
|
66
|
+
/**
|
|
67
|
+
* 企业应用的id
|
|
68
|
+
* @scope MsgType='text' | 'image' | 'voice' | 'video' | 'location' | 'link'
|
|
69
|
+
*/
|
|
70
|
+
AgentID?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 消息id,64位整型
|
|
73
|
+
* @scope MsgType='text' | 'image' | 'voice' | 'video' | 'location' | 'link'
|
|
74
|
+
*/
|
|
75
|
+
MsgId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* 文本消息内容
|
|
78
|
+
* @scope MsgType='text'
|
|
79
|
+
*/
|
|
80
|
+
Content?: string;
|
|
81
|
+
/**
|
|
82
|
+
* 图片链接
|
|
83
|
+
* @scope MsgType='image' | 'link'
|
|
84
|
+
*/
|
|
85
|
+
PicUrl?: string;
|
|
86
|
+
/**
|
|
87
|
+
* 媒体id,可以调用获取临时素材接口拉取数据
|
|
88
|
+
* @scope MsgType='image' | 'voice' | 'video'
|
|
89
|
+
*/
|
|
90
|
+
MediaId?: string;
|
|
91
|
+
/**
|
|
92
|
+
* 语音格式,如amr,speex等
|
|
93
|
+
* @scope MsgType='voice'
|
|
94
|
+
*/
|
|
95
|
+
Format?: string;
|
|
96
|
+
/**
|
|
97
|
+
* 缩略图的媒体id
|
|
98
|
+
* @scope MsgType='video'
|
|
99
|
+
*/
|
|
100
|
+
ThumbMediaId?: string;
|
|
101
|
+
/**
|
|
102
|
+
* 纬度
|
|
103
|
+
* @scope MsgType='location'
|
|
104
|
+
*/
|
|
105
|
+
Location_X?: number;
|
|
106
|
+
/**
|
|
107
|
+
* 经度
|
|
108
|
+
* @scope MsgType='location'
|
|
109
|
+
*/
|
|
110
|
+
Location_Y?: number;
|
|
111
|
+
/**
|
|
112
|
+
* 地图缩放大小
|
|
113
|
+
* @scope MsgType='location'
|
|
114
|
+
*/
|
|
115
|
+
Scale?: number;
|
|
116
|
+
/**
|
|
117
|
+
* 地理位置信息
|
|
118
|
+
* @scope MsgType='location'
|
|
119
|
+
*/
|
|
120
|
+
Label?: number;
|
|
121
|
+
/**
|
|
122
|
+
* app类型,在企业微信固定返回wxwork,在微信不返回该字段
|
|
123
|
+
* @scope MsgType='location'
|
|
124
|
+
*/
|
|
125
|
+
AppType?: number;
|
|
126
|
+
/**
|
|
127
|
+
* 消息标题
|
|
128
|
+
* @scope MsgType='link'
|
|
129
|
+
*/
|
|
130
|
+
Title?: string;
|
|
131
|
+
/**
|
|
132
|
+
* 消息描述
|
|
133
|
+
* @scope MsgType='link'
|
|
134
|
+
*/
|
|
135
|
+
Description?: string;
|
|
136
|
+
/**
|
|
137
|
+
* 消息链接
|
|
138
|
+
* @scope MsgType='link'
|
|
139
|
+
*/
|
|
140
|
+
Url?: string;
|
|
141
|
+
}
|
|
142
|
+
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,90 @@
|
|
|
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 { ServerEventType, ServerHandlerClosure, ServerMessageType } from '../Types/global';
|
|
7
|
+
declare class Server extends ServerInterface {
|
|
8
|
+
protected encryptor: Encryptor;
|
|
9
|
+
protected request: ServerRequestInterface;
|
|
10
|
+
constructor(encryptor: Encryptor, request?: ServerRequestInterface);
|
|
11
|
+
/**
|
|
12
|
+
* 服务端消息处理
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
serve(): Promise<Response>;
|
|
16
|
+
/**
|
|
17
|
+
* 设置联系人变化的消息处理器
|
|
18
|
+
* @param handler
|
|
19
|
+
*/
|
|
20
|
+
handleContactChanged(handler: ServerHandlerClosure): this;
|
|
21
|
+
/**
|
|
22
|
+
* 设置用户标签变化的消息处理器
|
|
23
|
+
* @param handler
|
|
24
|
+
*/
|
|
25
|
+
handleUserTagUpdated(handler: ServerHandlerClosure): this;
|
|
26
|
+
/**
|
|
27
|
+
* 设置用户创建的消息处理器
|
|
28
|
+
* @param handler
|
|
29
|
+
*/
|
|
30
|
+
handleUserCreated(handler: ServerHandlerClosure): this;
|
|
31
|
+
/**
|
|
32
|
+
* 设置用户更新的消息处理器
|
|
33
|
+
* @param handler
|
|
34
|
+
*/
|
|
35
|
+
handleUserUpdated(handler: ServerHandlerClosure): this;
|
|
36
|
+
/**
|
|
37
|
+
* 设置用户删除的消息处理器
|
|
38
|
+
* @param handler
|
|
39
|
+
*/
|
|
40
|
+
handleUserDeleted(handler: ServerHandlerClosure): this;
|
|
41
|
+
/**
|
|
42
|
+
* 设置部门创建的消息处理器
|
|
43
|
+
* @param handler
|
|
44
|
+
*/
|
|
45
|
+
handlePartyCreated(handler: ServerHandlerClosure): this;
|
|
46
|
+
/**
|
|
47
|
+
* 设置部门更新的消息处理器
|
|
48
|
+
* @param handler
|
|
49
|
+
*/
|
|
50
|
+
handlePartyUpdated(handler: ServerHandlerClosure): this;
|
|
51
|
+
/**
|
|
52
|
+
* 设置部门删除的消息处理器
|
|
53
|
+
* @param handler
|
|
54
|
+
*/
|
|
55
|
+
handlePartyDeleted(handler: ServerHandlerClosure): this;
|
|
56
|
+
/**
|
|
57
|
+
* 设置异步任务完成的消息处理器
|
|
58
|
+
* @param handler
|
|
59
|
+
*/
|
|
60
|
+
handleBatchJobsFinished(handler: ServerHandlerClosure): this;
|
|
61
|
+
/**
|
|
62
|
+
* 添加普通消息处理器
|
|
63
|
+
* @param type
|
|
64
|
+
* @param handler
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
addMessageListener(type: ServerMessageType, handler: ServerHandlerClosure): this;
|
|
68
|
+
/**
|
|
69
|
+
* 添加事件消息处理器
|
|
70
|
+
* @param event
|
|
71
|
+
* @param handler
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
addEventListener(event: ServerEventType, handler: ServerHandlerClosure): this;
|
|
75
|
+
/**
|
|
76
|
+
* 获取来自微信服务器的推送消息
|
|
77
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
getRequestMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
81
|
+
protected validateUrl(): (message: Message, next: ServerHandlerClosure) => Promise<Response>;
|
|
82
|
+
protected decryptRequestMessage(query: Record<string, any>): ServerHandlerClosure;
|
|
83
|
+
/**
|
|
84
|
+
* 获取解密后的消息
|
|
85
|
+
* @param request 未设置该参数时,则从当前服务端收到的请求中获取
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
getDecryptedMessage(request?: ServerRequestInterface): Promise<import("../Core/Message")>;
|
|
89
|
+
}
|
|
90
|
+
export = Server;
|