baja-lite 1.1.4 → 1.1.8
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/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +6 -7
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +32 -39
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +69 -69
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +105 -155
- package/enum.d.ts +18 -0
- package/enum.js +59 -0
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +11 -11
- package/index.js +11 -0
- package/list.d.ts +10 -0
- package/{src/list.ts → list.js} +8 -9
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +83 -0
- package/object.js +221 -0
- package/package.json +2 -1
- package/set-ex.d.ts +198 -0
- package/set-ex.js +338 -0
- package/sql.d.ts +1858 -0
- package/sql.js +5025 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +53 -52
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/{src/test-mysql.ts → test-mysql.js} +135 -126
- package/test-postgresql.d.ts +2 -0
- package/test-postgresql.js +90 -0
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +89 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +1 -1
- package/test.d.ts +1 -0
- package/test.js +2 -0
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +45 -0
- package/wx/mini.js +102 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +21 -10
- package/wx/types.js +1 -0
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -4
- package/ci.js +0 -29
- package/package-cjs.json +0 -17
- package/src/enum.ts +0 -71
- package/src/error.ts +0 -11
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -247
- package/src/set-ex.ts +0 -374
- package/src/sql.ts +0 -5281
- package/src/string.ts +0 -111
- package/src/test-postgresql.ts +0 -79
- package/src/test.ts +0 -2
- package/src/wx/base.ts +0 -76
- package/src/wx/mini.ts +0 -133
- package/src/wx/organ.ts +0 -290
- package/test.json +0 -0
- package/tsconfig.base.json +0 -80
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1493
- /package/{Readme.md → README.md} +0 -0
- /package/{src/wx.ts → wx.d.ts} +0 -0
package/src/string.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 通过uri获取key
|
|
3
|
-
* @param uri
|
|
4
|
-
*/
|
|
5
|
-
export const getPicKey = (uri: string): string => {
|
|
6
|
-
const arr = /key=([0-9a-zA-Z.]+)/.exec(uri);
|
|
7
|
-
if (arr && arr.length === 2) {
|
|
8
|
-
return arr[1]!;
|
|
9
|
-
}
|
|
10
|
-
return uri;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const emptyString = (source: any, skipEmptyString = true): boolean => {
|
|
14
|
-
return (
|
|
15
|
-
source === null ||
|
|
16
|
-
source === undefined ||
|
|
17
|
-
(skipEmptyString === true && (source === '' || `${ source }`.replace(/\s/g, '') === ''))
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const notEmptyString = (source: any, skipEmptyString = true): boolean => {
|
|
22
|
-
return emptyString(source, skipEmptyString) === false;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const safeString = (source?: string): string => {
|
|
26
|
-
if (source) {
|
|
27
|
-
return `${ source }`.replace(/'/g, '');
|
|
28
|
-
}
|
|
29
|
-
return '';
|
|
30
|
-
};
|
|
31
|
-
export const trimObject = <T>(data: any): T => {
|
|
32
|
-
if (data) {
|
|
33
|
-
for (const k in data) {
|
|
34
|
-
if (typeof data[k] === 'string') {
|
|
35
|
-
data[k] = data[k].trim();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const randomNumber = (len: number): string => {
|
|
43
|
-
return `${ parseInt(`${ (Math.random() * 9 + 1) * Math.pow(10, (len - 1)) }`, 10) }`;
|
|
44
|
-
};
|
|
45
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
46
|
-
const charLen = chars.length;
|
|
47
|
-
export const randomString = (len: number): string => {
|
|
48
|
-
return Array.from(new Array(len)).map(() => chars.charAt(Math.floor(Math.random() * charLen))).join('');
|
|
49
|
-
};
|
|
50
|
-
const chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
51
|
-
const charLen2 = chars2.length;
|
|
52
|
-
export const randomString2 = (len: number): string => {
|
|
53
|
-
return Array.from(new Array(len)).map(() => chars2.charAt(Math.floor(Math.random() * charLen2))).join('');
|
|
54
|
-
};
|
|
55
|
-
const chars3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
56
|
-
const charLen3 = chars3.length;
|
|
57
|
-
export const randomString3 = (len: number): string => {
|
|
58
|
-
return Array.from(new Array(len)).map(() => chars3.charAt(Math.floor(Math.random() * charLen3))).join('');
|
|
59
|
-
};
|
|
60
|
-
export const buildWxStr = (data: {[key: string]: string}, maxLabelLength: number, ...titles: string[]) => {
|
|
61
|
-
let str = titles.join('\r\n');
|
|
62
|
-
str += '\r\n\r\n';
|
|
63
|
-
const items = new Array<string>();
|
|
64
|
-
// const maxLength = maxLabelLength * 2;
|
|
65
|
-
for (const [key, value] of Object.entries(data)) {
|
|
66
|
-
if (notEmptyString(value)) {
|
|
67
|
-
const len = maxLabelLength - key.length;
|
|
68
|
-
items.push(`${ key }:${ ''.padEnd(len * 3 + (len > 0 ? 1 : 0), ' ') }${ value }`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
str += items.join('\r\n');
|
|
72
|
-
return str;
|
|
73
|
-
};
|
|
74
|
-
const chinese = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g;
|
|
75
|
-
const table = {
|
|
76
|
-
'!': '!',
|
|
77
|
-
'¥': '$',
|
|
78
|
-
'…': '.',
|
|
79
|
-
'(': '(',
|
|
80
|
-
')': ')',
|
|
81
|
-
'《': '<',
|
|
82
|
-
'》': '>',
|
|
83
|
-
'?': '?',
|
|
84
|
-
':': ':',
|
|
85
|
-
'“': `'`,
|
|
86
|
-
'”': `'`,
|
|
87
|
-
'’': `'`,
|
|
88
|
-
'‘': `'`,
|
|
89
|
-
',': ',',
|
|
90
|
-
'。': '.',
|
|
91
|
-
'、': '/',
|
|
92
|
-
';': ';',
|
|
93
|
-
'〈': '<',
|
|
94
|
-
'〉': '>',
|
|
95
|
-
'【': '[',
|
|
96
|
-
'】': ']',
|
|
97
|
-
'『': '[',
|
|
98
|
-
'』': ']',
|
|
99
|
-
'「': '[',
|
|
100
|
-
'」': ']',
|
|
101
|
-
'﹃': '[',
|
|
102
|
-
'﹄': ']',
|
|
103
|
-
'〔': '(',
|
|
104
|
-
'〕': ')',
|
|
105
|
-
'—': '-',
|
|
106
|
-
'~': '~',
|
|
107
|
-
'﹏': '~'
|
|
108
|
-
};
|
|
109
|
-
export const replaceChineseCode = (str: string) => {
|
|
110
|
-
return str.replace(chinese, (a: string) => table[a] || '');
|
|
111
|
-
};
|
package/src/test-postgresql.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Boot } from './boot.js';
|
|
3
|
-
import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
|
|
4
|
-
class AmaFuck2 {
|
|
5
|
-
@Field({ type: SqlType.int, length: 200, id: true, uuid: true })
|
|
6
|
-
userid?: number;
|
|
7
|
-
@Field({ type: SqlType.varchar, length: 200, def: '333' })
|
|
8
|
-
username?: string;
|
|
9
|
-
@Field({ type: SqlType.varchar, length: 200 })
|
|
10
|
-
pwd?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@DB({
|
|
14
|
-
tableName: 'nfc_user', clz: AmaFuck2, dbType: DBType.Postgresql
|
|
15
|
-
})
|
|
16
|
-
class AmaService2 extends SqlService<AmaFuck2>{
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// interface Menu {
|
|
21
|
-
// resourceid: string;
|
|
22
|
-
// resourcepid: string;
|
|
23
|
-
// resourcename: string;
|
|
24
|
-
// children: Menu[];
|
|
25
|
-
// }
|
|
26
|
-
|
|
27
|
-
export async function go2() {
|
|
28
|
-
await Boot({
|
|
29
|
-
Postgresql: {
|
|
30
|
-
database: 'nfc',
|
|
31
|
-
user: 'postgres',
|
|
32
|
-
password: 'abcd1234',
|
|
33
|
-
port: 5432,
|
|
34
|
-
host: '127.0.0.1'
|
|
35
|
-
},
|
|
36
|
-
log: 'info',
|
|
37
|
-
columnMode: ColumnMode.HUMP,
|
|
38
|
-
sqlDir: 'E:/pro/baja-lite/xml',
|
|
39
|
-
sqlMap: {
|
|
40
|
-
['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const service = new AmaService2();
|
|
44
|
-
await service.transaction<number>({
|
|
45
|
-
fn: async conn => {
|
|
46
|
-
const rt5 = await service.select<{username:string}>({
|
|
47
|
-
sqlId: 'test.test',
|
|
48
|
-
params: { username: '1111' },
|
|
49
|
-
selectResult: SelectResult.RS_CS,
|
|
50
|
-
conn
|
|
51
|
-
})
|
|
52
|
-
console.log(55, rt5.length);
|
|
53
|
-
await service.insert({
|
|
54
|
-
data:{
|
|
55
|
-
userid:22,
|
|
56
|
-
username:'222',
|
|
57
|
-
pwd: '333'
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// const data = await service.select<Menu>({
|
|
65
|
-
// sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
|
|
66
|
-
// params: {
|
|
67
|
-
// site: '1234',
|
|
68
|
-
// matchInfo: { reportType: 'yyyy', id: '11' }
|
|
69
|
-
// },
|
|
70
|
-
// // mapper: [
|
|
71
|
-
// // ['site', ['info', 'bSist'], 989],
|
|
72
|
-
// // ['site', ['info2', 'bSist'], 33],
|
|
73
|
-
// // ['site', ['Bsite'], 0]
|
|
74
|
-
// // ]
|
|
75
|
-
// });
|
|
76
|
-
// console.log(data);
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
go2();
|
package/src/test.ts
DELETED
package/src/wx/base.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
import * as rp from 'request-promise';
|
|
3
|
-
import { Throw } from '../error.js';
|
|
4
|
-
import pino from 'pino';
|
|
5
|
-
const logger =
|
|
6
|
-
process.env['NODE_ENV'] !== 'production' ? pino({
|
|
7
|
-
name: 'wx',
|
|
8
|
-
transport: {
|
|
9
|
-
target: 'pino-pretty'
|
|
10
|
-
}
|
|
11
|
-
}) : pino({ name: 'wx' });
|
|
12
|
-
export abstract class BaseWx {
|
|
13
|
-
protected authErrorCodes = [40001, 40014, 41001, 42001];
|
|
14
|
-
protected name: string = '';
|
|
15
|
-
protected tokenUrl: string = '';
|
|
16
|
-
private tokenData = '';
|
|
17
|
-
protected mock = false;
|
|
18
|
-
protected async getToken(force?: boolean): Promise<string> {
|
|
19
|
-
let token = '';
|
|
20
|
-
const now = +new Date();
|
|
21
|
-
let need = force === true;
|
|
22
|
-
if (this.tokenData) {
|
|
23
|
-
const datas = this.tokenData.split('^_^');
|
|
24
|
-
token = datas[0]!;
|
|
25
|
-
const lastTime = datas[1]!;
|
|
26
|
-
const spliceTime = datas[2]!;
|
|
27
|
-
if (now - parseInt(lastTime, 10) - parseInt(spliceTime, 10) > 0) {
|
|
28
|
-
need = true;
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
need = true;
|
|
32
|
-
}
|
|
33
|
-
if (need === true) {
|
|
34
|
-
const data = await this.fetch(() => this.tokenUrl, 'get', {}, false);
|
|
35
|
-
token = data.access_token;
|
|
36
|
-
this.tokenData = `${token}^_^${now}^_^${data.expires_in * 1000}`;
|
|
37
|
-
}
|
|
38
|
-
return token;
|
|
39
|
-
}
|
|
40
|
-
protected async fetch(uri: (token: string) => string, method: 'get' | 'post', data: { [key: string]: any }, needToken = true, buffer = false) {
|
|
41
|
-
if (this.mock === true) {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
let token = needToken ? await this.getToken() : '';
|
|
45
|
-
if (!needToken || token) {
|
|
46
|
-
const start = +new Date();
|
|
47
|
-
let url = uri(token);
|
|
48
|
-
const param = method === 'get' ? {
|
|
49
|
-
method,
|
|
50
|
-
json: buffer ? false : true,
|
|
51
|
-
qs: data,
|
|
52
|
-
encoding: buffer ? null : undefined
|
|
53
|
-
} : {
|
|
54
|
-
json: data,
|
|
55
|
-
method,
|
|
56
|
-
encoding: buffer ? null : undefined
|
|
57
|
-
};
|
|
58
|
-
let response = await rp.default({
|
|
59
|
-
uri: url,
|
|
60
|
-
...param
|
|
61
|
-
});
|
|
62
|
-
if (this.authErrorCodes.includes(response.errcode)) {
|
|
63
|
-
token = await this.getToken(true);
|
|
64
|
-
url = uri(token);
|
|
65
|
-
response = await rp.default({
|
|
66
|
-
uri: url,
|
|
67
|
-
...param
|
|
68
|
-
});
|
|
69
|
-
Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
|
|
70
|
-
}
|
|
71
|
-
Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
|
|
72
|
-
logger.info(`fetch data ${+new Date() - start} ms`);
|
|
73
|
-
return response;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/wx/mini.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { BaseWx } from './base';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
|
-
import { WxMiniConfig, WxLiveInfo, WxLiveReplay } from './types.js';
|
|
4
|
-
import { Throw } from '../error.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
|
-
}
|
package/src/wx/organ.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import {BaseWx} from './base';
|
|
2
|
-
import {WxOrganConfig, WxDepartment, WxOrganUser, WxOrganUserSimply, WxOrganText, WxOrganImage, WxOrganVoice, WxOrganVideo, WxOrganFile, WxOrganTextCard, WxOrganNews, WxOrganMpNews, WxOrganMarkDown, WxOrganTaskCard, WxOrganMini} 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
|
-
}
|
package/test.json
DELETED
|
File without changes
|