baja-lite 1.6.2 → 1.6.4
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +9 -0
- package/ci.js +33 -0
- package/package-cjs.json +17 -0
- package/package.json +80 -80
- package/pnpm-lock.yaml +2840 -0
- package/pnpm-workspace.yaml +2 -0
- package/{boot-remote.js → src/boot-remote.ts} +64 -63
- package/{boot.js → src/boot.ts} +170 -163
- package/{code.js → src/code.ts} +526 -517
- package/{convert-xml.js → src/convert-xml.ts} +460 -410
- package/src/error.ts +11 -0
- package/src/event.ts +34 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +11 -10
- package/src/math.ts +405 -0
- package/src/object.ts +342 -0
- package/{snowflake.js → src/snowflake.ts} +127 -108
- package/src/sql.ts +5529 -0
- package/{sqlite.js → src/sqlite.ts} +157 -156
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +148 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +70 -70
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +77 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +549 -560
- package/{wx.d.ts → src/wx.ts} +3 -3
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1977 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/event.d.ts +0 -10
- package/event.js +0 -38
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -126
- package/object.js +0 -321
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -2148
- package/sql.js +0 -5372
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-mysql.js +0 -114
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
package/src/wx/mini.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { Throw } from '../error.js';
|
|
3
|
+
import { BaseWx } from './base.js';
|
|
4
|
+
import { WxLiveInfo, WxLiveReplay, WxMiniConfig } from './types.js';
|
|
5
|
+
export class WxMini extends BaseWx {
|
|
6
|
+
protected name = 'wxMini';
|
|
7
|
+
private config: WxMiniConfig;
|
|
8
|
+
private templNameCache: { [name: string]: { page: string; tmplId: string }[] }; // 订阅消息缓存
|
|
9
|
+
private templKeyCache: { [key: string]: string[] }; // 订阅消息场景分组id
|
|
10
|
+
constructor(config: WxMiniConfig) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.tokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${this.config.appId}&secret=${this.config.appSecret}`;
|
|
14
|
+
this.templNameCache = {};
|
|
15
|
+
this.templKeyCache = {};
|
|
16
|
+
if (this.config.messages) {
|
|
17
|
+
for (const item of this.config.messages) {
|
|
18
|
+
if (!this.templNameCache[item.name]) {
|
|
19
|
+
this.templNameCache[item.name] = [];
|
|
20
|
+
}
|
|
21
|
+
this.templNameCache[item.name]!.push({
|
|
22
|
+
tmplId: item.tmplId,
|
|
23
|
+
page: `pages/${item.model}/${item.page}/${item.page}`
|
|
24
|
+
});
|
|
25
|
+
for (const key of item.keys) {
|
|
26
|
+
if (!this.templKeyCache[key]) {
|
|
27
|
+
this.templKeyCache[key] = [];
|
|
28
|
+
}
|
|
29
|
+
this.templKeyCache[key]!.push(item.tmplId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async getUnlimited({ scene, model, page, fullpath, png, width, lineColor }: { scene: string; model?: string; page?: string; fullpath?: string; png?: '0' | '1' | 0 | 1 | true | false | 'true' | 'false'; width?: number; lineColor?: { r: number; g: number; b: number } }) {
|
|
35
|
+
Throw.if(!fullpath && (!model || !page), '路径不完整,fullpath或者model+page必须传一个');
|
|
36
|
+
const pageto = fullpath ?? `pages/${model}/${page}/${page}`;
|
|
37
|
+
return await this.fetch(
|
|
38
|
+
(token: string) => `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${token}`,
|
|
39
|
+
'post',
|
|
40
|
+
{
|
|
41
|
+
scene,
|
|
42
|
+
page: pageto,
|
|
43
|
+
line_color: lineColor ?? this.config.qrcode?.lineColor,
|
|
44
|
+
is_hyaline: png === 'true' || png === '1' || png === true || png === 1,
|
|
45
|
+
width: width ?? this.config.qrcode?.width ?? 500
|
|
46
|
+
},
|
|
47
|
+
true,
|
|
48
|
+
true
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
async sendMs(
|
|
52
|
+
{ openids, name, data, scene }: {
|
|
53
|
+
openids: string[];
|
|
54
|
+
name: string;
|
|
55
|
+
data: { [key: string]: string | number };
|
|
56
|
+
scene: string;
|
|
57
|
+
}) {
|
|
58
|
+
const temps = this.templNameCache[name]!;
|
|
59
|
+
const dataSend: { [key: string]: { value: string | number } } = {};
|
|
60
|
+
for (const [key, value] of Object.entries(data)) {
|
|
61
|
+
dataSend[key] = { value: value ?? '' };
|
|
62
|
+
}
|
|
63
|
+
if (scene) {
|
|
64
|
+
scene = `?${scene}`;
|
|
65
|
+
} else {
|
|
66
|
+
scene = '';
|
|
67
|
+
}
|
|
68
|
+
for (const temp of temps) {
|
|
69
|
+
for (const touser of openids) {
|
|
70
|
+
await this.fetch(
|
|
71
|
+
(token: string) => `https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${token}`,
|
|
72
|
+
'post',
|
|
73
|
+
{
|
|
74
|
+
touser,
|
|
75
|
+
data: dataSend,
|
|
76
|
+
template_id: temp.tmplId,
|
|
77
|
+
page: `${temp.page}${scene}`
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async code2session(code: string): Promise<{ openid: string; session_key: string; unionid?: string }> {
|
|
84
|
+
const data = await this.fetch(
|
|
85
|
+
() => `https://api.weixin.qq.com/sns/jscode2session?appid=${this.config.appId}&secret=${this.config.appSecret}&js_code=${code}&grant_type=authorization_code`,
|
|
86
|
+
'get',
|
|
87
|
+
{},
|
|
88
|
+
false
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
openid: data.openid,
|
|
92
|
+
session_key: data.session_key,
|
|
93
|
+
unionid: data.unionid
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
getTemplIds() {
|
|
97
|
+
return this.templKeyCache;
|
|
98
|
+
}
|
|
99
|
+
decrypt<T>({ sessionKey, encryptedData, iv }: { iv: string; sessionKey: string; encryptedData: string }): T | undefined {
|
|
100
|
+
Throw.if(!sessionKey, '会话过期,请重新登陆!');
|
|
101
|
+
const sessionKeyBuf = Buffer.from(sessionKey, 'base64');
|
|
102
|
+
const encryptedDataBuf = Buffer.from(encryptedData, 'base64');
|
|
103
|
+
const ivBuf = Buffer.from(iv, 'base64');
|
|
104
|
+
try {
|
|
105
|
+
// 解密
|
|
106
|
+
const decipher = crypto.createDecipheriv('aes-128-cbc', sessionKeyBuf, ivBuf);
|
|
107
|
+
// 设置自动 padding 为 true,删除填充补位
|
|
108
|
+
decipher.setAutoPadding(true);
|
|
109
|
+
const decoded = decipher.update(encryptedDataBuf, undefined, 'utf8') + decipher.final('utf8');
|
|
110
|
+
const decodedData = JSON.parse(decoded);
|
|
111
|
+
Throw.if(decodedData.watermark.appid !== this.config.appId, '加密验证失败');
|
|
112
|
+
return decodedData as T;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw new Error('加密验证失败');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async getLiveInfo(start: number, limit: number): Promise<WxLiveInfo[]> {
|
|
118
|
+
const data = await this.fetch(
|
|
119
|
+
(token: string) => `https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=${token}`,
|
|
120
|
+
'post',
|
|
121
|
+
{ start, limit }
|
|
122
|
+
);
|
|
123
|
+
return data.room_info;
|
|
124
|
+
}
|
|
125
|
+
async getLiveReplay(room_id: number, start: number, limit: number): Promise<WxLiveReplay[]> {
|
|
126
|
+
const data = await this.fetch(
|
|
127
|
+
(token: string) => `https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=${token}`,
|
|
128
|
+
'post',
|
|
129
|
+
{ room_id, start, limit, action: 'get_replay' }
|
|
130
|
+
);
|
|
131
|
+
return data.live_replay;
|
|
132
|
+
}
|
|
133
|
+
async getPhone(code: string, openid: string) {
|
|
134
|
+
const data = await this.fetch(
|
|
135
|
+
(token: string) => `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`,
|
|
136
|
+
'post',
|
|
137
|
+
{ code, openid }
|
|
138
|
+
);
|
|
139
|
+
return {
|
|
140
|
+
phoneNumber: data.phone_info.phoneNumber,
|
|
141
|
+
purePhoneNumber: data.phone_info.purePhoneNumber,
|
|
142
|
+
countryCode: data.phone_info.countryCode,
|
|
143
|
+
timestamp: data.phone_info.watermark.timestamp,
|
|
144
|
+
appid: data.phone_info.watermark.appid
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
package/src/wx/organ.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { BaseWx } from './base.js';
|
|
2
|
+
import { WxDepartment, WxOrganConfig, WxOrganFile, WxOrganImage, WxOrganMarkDown, WxOrganMini, WxOrganMpNews, WxOrganNews, WxOrganTaskCard, WxOrganText, WxOrganTextCard, WxOrganUser, WxOrganUserSimply, WxOrganVideo, WxOrganVoice } from './types.js';
|
|
3
|
+
export class WxOrgan extends BaseWx {
|
|
4
|
+
protected name = 'wxOrgan';
|
|
5
|
+
private config: WxOrganConfig;
|
|
6
|
+
private miniMessCache: {[name: string]: Array<{appid: string; page: string}>}; // 小程序消息缓存
|
|
7
|
+
private messCache: {[name: string]: Array<{agentid: number; msgtype: string; safe?: number}>}; // 非小程序消息缓存
|
|
8
|
+
// private aesKey: Buffer | undefined;
|
|
9
|
+
// private iv: Buffer | undefined;
|
|
10
|
+
constructor (config: WxOrganConfig) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.tokenUrl = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${ this.config.corpid }&corpsecret=${ this.config.corpsecret }`;
|
|
14
|
+
this.miniMessCache = {};
|
|
15
|
+
this.messCache = {};
|
|
16
|
+
// if (this.config.msHook) {
|
|
17
|
+
// this.aesKey = Buffer.from(this.config.encodingAESKey + '=', 'base64');
|
|
18
|
+
// this.iv = this.aesKey.slice(0, 16);
|
|
19
|
+
// }
|
|
20
|
+
if (this.config.miniMessages) {
|
|
21
|
+
for (const item of this.config.miniMessages) {
|
|
22
|
+
if (!this.miniMessCache[item.name]) {
|
|
23
|
+
this.miniMessCache[item.name] = [];
|
|
24
|
+
}
|
|
25
|
+
this.miniMessCache[item.name]!.push({
|
|
26
|
+
appid: this.config.appid!,
|
|
27
|
+
page: `pages/${ item.model }/${ item.page }/${ item.page }`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (this.config.messages) {
|
|
32
|
+
for (const item of this.config.messages) {
|
|
33
|
+
if (!this.messCache[item.name]) {
|
|
34
|
+
this.messCache[item.name] = [];
|
|
35
|
+
}
|
|
36
|
+
this.messCache[item.name]!.push({
|
|
37
|
+
agentid: this.config.agentid!,
|
|
38
|
+
...item
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.mock = this.config.mock === true;
|
|
44
|
+
}
|
|
45
|
+
async createDepartment(param: WxDepartment): Promise<number> {
|
|
46
|
+
const data = await this.fetch(
|
|
47
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=${ token }`,
|
|
48
|
+
'post',
|
|
49
|
+
param
|
|
50
|
+
);
|
|
51
|
+
return data.id;
|
|
52
|
+
}
|
|
53
|
+
async updateDepartment(param: WxDepartment): Promise<void> {
|
|
54
|
+
await this.fetch(
|
|
55
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=${ token }`,
|
|
56
|
+
'post',
|
|
57
|
+
param
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
async deleteDepartment(id: number): Promise<void> {
|
|
61
|
+
await this.fetch(
|
|
62
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=${ token }`,
|
|
63
|
+
'get',
|
|
64
|
+
{id}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
async getDepartmentList(id?: number): Promise<WxDepartment[]> {
|
|
68
|
+
const data = await this.fetch(
|
|
69
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=${ token }`,
|
|
70
|
+
'get',
|
|
71
|
+
{id}
|
|
72
|
+
);
|
|
73
|
+
return data.department;
|
|
74
|
+
}
|
|
75
|
+
async createUser(param: WxOrganUser): Promise<string | number> {
|
|
76
|
+
const data = await this.fetch(
|
|
77
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=${ token }`,
|
|
78
|
+
'post',
|
|
79
|
+
param
|
|
80
|
+
);
|
|
81
|
+
return data.id;
|
|
82
|
+
}
|
|
83
|
+
async getUser(userid: number | string): Promise<WxOrganUser> {
|
|
84
|
+
return await this.fetch(
|
|
85
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=${ token }`,
|
|
86
|
+
'get',
|
|
87
|
+
{userid}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
async updateUser(param: WxOrganUser): Promise<void> {
|
|
91
|
+
await this.fetch(
|
|
92
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=${ token }`,
|
|
93
|
+
'post',
|
|
94
|
+
param
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async deleteUser(userid: number | string): Promise<void> {
|
|
98
|
+
await this.fetch(
|
|
99
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=${ token }`,
|
|
100
|
+
'get',
|
|
101
|
+
{userid}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
async batchDeleteUser(useridlist: Array<number | string>): Promise<void> {
|
|
105
|
+
await this.fetch(
|
|
106
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=${ token }`,
|
|
107
|
+
'post',
|
|
108
|
+
{useridlist}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
async getDeptUserSimply(department_id: number, fetch_child: boolean): Promise<WxOrganUserSimply[]> {
|
|
112
|
+
const data = await this.fetch(
|
|
113
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=${ token }`,
|
|
114
|
+
'get',
|
|
115
|
+
{department_id, fetch_child: fetch_child ? 'FETCH_CHILD' : undefined}
|
|
116
|
+
);
|
|
117
|
+
return data.userlist;
|
|
118
|
+
}
|
|
119
|
+
async getDeptUser(department_id: number, fetch_child: boolean): Promise<WxOrganUser[]> {
|
|
120
|
+
const data = await this.fetch(
|
|
121
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=${ token }`,
|
|
122
|
+
'get',
|
|
123
|
+
{department_id, fetch_child: fetch_child ? 'FETCH_CHILD' : undefined}
|
|
124
|
+
);
|
|
125
|
+
return data.userlist;
|
|
126
|
+
}
|
|
127
|
+
async userid2openid(userid: number | string): Promise<string> {
|
|
128
|
+
const data = await this.fetch(
|
|
129
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=${ token }`,
|
|
130
|
+
'post',
|
|
131
|
+
{userid}
|
|
132
|
+
);
|
|
133
|
+
return data.openid;
|
|
134
|
+
}
|
|
135
|
+
async openid2userid(openid: string): Promise<number | string> {
|
|
136
|
+
const data = await this.fetch(
|
|
137
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?access_token=${ token }`,
|
|
138
|
+
'post',
|
|
139
|
+
{openid}
|
|
140
|
+
);
|
|
141
|
+
return data.userid;
|
|
142
|
+
}
|
|
143
|
+
async authsucc(userid: string): Promise<void> {
|
|
144
|
+
await this.fetch(
|
|
145
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?access_token=${ token }`,
|
|
146
|
+
'get',
|
|
147
|
+
{userid}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
async inviteUsers({user, party, tag}: {user?: Array<number | string>; party?: number[]; tag?: number[]}): Promise<{invaliduser?: Array<number | string>; invalidparty?: number[]; invalidtag?: number[]}> {
|
|
151
|
+
const data = await this.fetch(
|
|
152
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/batch/invite?access_token=${ token }`,
|
|
153
|
+
'post',
|
|
154
|
+
{user, party, tag}
|
|
155
|
+
);
|
|
156
|
+
return {
|
|
157
|
+
invaliduser: data.invaliduser,
|
|
158
|
+
invalidparty: data.invalidparty,
|
|
159
|
+
invalidtag: data.invalidtag
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async createTag(tagname: string, tagid: number): Promise<number> {
|
|
163
|
+
const data = await this.fetch(
|
|
164
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=${ token }`,
|
|
165
|
+
'post',
|
|
166
|
+
{tagname, tagid}
|
|
167
|
+
);
|
|
168
|
+
return data.id;
|
|
169
|
+
}
|
|
170
|
+
async updateTag(tagname: string, tagid: number): Promise<void> {
|
|
171
|
+
await this.fetch(
|
|
172
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token=${ token }`,
|
|
173
|
+
'post',
|
|
174
|
+
{tagname, tagid}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
async deleteTag(tagid: number): Promise<void> {
|
|
178
|
+
await this.fetch(
|
|
179
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=${ token }`,
|
|
180
|
+
'get',
|
|
181
|
+
{tagid}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
async createTagUser(tagid: number, userlist: Array<string | number>): Promise<void> {
|
|
185
|
+
await this.fetch(
|
|
186
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers?access_token=${ token }`,
|
|
187
|
+
'post',
|
|
188
|
+
{tagid, userlist}
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
async deleteTagUser(tagid: number, userlist: Array<string | number>): Promise<void> {
|
|
192
|
+
await this.fetch(
|
|
193
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=${ token }`,
|
|
194
|
+
'post',
|
|
195
|
+
{tagid, userlist}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
async getTagUser(tagid: number): Promise<{tagname: string; userlist: Array<{userid: string | number; name: string}>; partylist: number[]}> {
|
|
199
|
+
const data = await this.fetch(
|
|
200
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=${ token }`,
|
|
201
|
+
'get',
|
|
202
|
+
{tagid}
|
|
203
|
+
);
|
|
204
|
+
return data;
|
|
205
|
+
}
|
|
206
|
+
async getTag(): Promise<Array<{tagid: number; tagname: string}>> {
|
|
207
|
+
const data = await this.fetch(
|
|
208
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=${ token }`,
|
|
209
|
+
'get',
|
|
210
|
+
{}
|
|
211
|
+
);
|
|
212
|
+
return data.taglist;
|
|
213
|
+
}
|
|
214
|
+
async updateTaskCard(userids: Array<string | number>, task_id: string, clicked_key: string): Promise<void> {
|
|
215
|
+
await this.fetch(
|
|
216
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/message/update_taskcard?access_token=${ token }`,
|
|
217
|
+
'post',
|
|
218
|
+
{userids, task_id, clicked_key}
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
async sendMiniMs(
|
|
222
|
+
{touser, toparty, totag, name, scene, ms}: {
|
|
223
|
+
touser?: Array<number | string>;
|
|
224
|
+
toparty?: number[];
|
|
225
|
+
totag?: number[];
|
|
226
|
+
name: string;
|
|
227
|
+
scene?: string;
|
|
228
|
+
ms: WxOrganMini;
|
|
229
|
+
}): Promise<void> {
|
|
230
|
+
const touser_ = touser ? touser.join('|') : undefined;
|
|
231
|
+
const toparty_ = toparty ? toparty.join('|') : undefined;
|
|
232
|
+
const totag_ = totag ? totag.join('|') : undefined;
|
|
233
|
+
if (scene) {
|
|
234
|
+
scene = `?${ scene }`;
|
|
235
|
+
} else {
|
|
236
|
+
scene = '';
|
|
237
|
+
}
|
|
238
|
+
if (ms.content_item) {
|
|
239
|
+
for (const [key, value] of Object.entries(ms.content_item)) {
|
|
240
|
+
ms.content_item[key] = value ?? '';
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const temps = this.miniMessCache[name];
|
|
245
|
+
for (const item of temps!) {
|
|
246
|
+
await this.fetch(
|
|
247
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${ token }`,
|
|
248
|
+
'post',
|
|
249
|
+
{
|
|
250
|
+
touser: touser_,
|
|
251
|
+
toparty: toparty_,
|
|
252
|
+
totag: totag_,
|
|
253
|
+
'msgtype': 'miniprogram_notice',
|
|
254
|
+
miniprogram_notice: {
|
|
255
|
+
...item,
|
|
256
|
+
page: `${ item.page }${ scene }`,
|
|
257
|
+
...ms
|
|
258
|
+
},
|
|
259
|
+
enable_id_trans: 0
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async sendMs(
|
|
265
|
+
{touser, toparty, totag, name, ms}: {
|
|
266
|
+
touser?: Array<number | string>;
|
|
267
|
+
toparty?: number[];
|
|
268
|
+
totag?: number[];
|
|
269
|
+
name: string;
|
|
270
|
+
ms: WxOrganText | WxOrganImage | WxOrganVoice | WxOrganVideo | WxOrganFile | WxOrganTextCard | WxOrganNews | WxOrganMpNews | WxOrganMarkDown | WxOrganTaskCard;
|
|
271
|
+
}): Promise<void> {
|
|
272
|
+
const touser_ = touser ? touser.join('|') : undefined;
|
|
273
|
+
const toparty_ = toparty ? toparty.join('|') : undefined;
|
|
274
|
+
const totag_ = totag ? totag.join('|') : undefined;
|
|
275
|
+
const temps = this.messCache[name];
|
|
276
|
+
for (const item of temps!) {
|
|
277
|
+
await this.fetch(
|
|
278
|
+
(token: string) => `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${ token }`,
|
|
279
|
+
'post',
|
|
280
|
+
{
|
|
281
|
+
touser: touser_,
|
|
282
|
+
toparty: toparty_,
|
|
283
|
+
totag: totag_,
|
|
284
|
+
...item,
|
|
285
|
+
[item.msgtype]: ms,
|
|
286
|
+
enable_id_trans: 0
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|