cgserver 6.9.475 → 7.1.568
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/README.md +3 -0
- package/dist/lib/Config/{ServerConfig.js → IServerConfig.js} +3 -4
- package/dist/lib/Database/MSSqlManager.js +5 -5
- package/dist/lib/Database/MysqlBaseService.js +2 -2
- package/dist/lib/Database/MysqlManager.js +9 -9
- package/dist/lib/Service/MongoCacheService.js +17 -2
- package/dist/lib/SocketServer/IClientWebSocket.js +20 -52
- package/dist/lib/SocketServer/IRpcClientWebSocket.js +1 -1
- package/dist/lib/SocketServer/IRpcServerWebSocket.js +1 -1
- package/dist/lib/SocketServer/IServerWebSocket.js +51 -21
- package/dist/lib/SocketServer/ISocketServer.js +43 -35
- package/dist/lib/SocketServer/IWebSocket.js +2 -2
- package/dist/lib/ThirdParty/AlipayTool.js +13 -13
- package/dist/lib/ThirdParty/Alisms.js +4 -4
- package/dist/lib/ThirdParty/AppleTool.js +3 -3
- package/dist/lib/ThirdParty/CgMq.js +2 -2
- package/dist/lib/ThirdParty/EmailTool.js +7 -7
- package/dist/lib/ThirdParty/OpenSocial.js +5 -5
- package/dist/lib/ThirdParty/QQTool.js +7 -7
- package/dist/lib/ThirdParty/QiniuTool.js +4 -4
- package/dist/lib/ThirdParty/WechatTool.js +4 -4
- package/dist/lib/WebServer/Decorator/SyncCall.js +21 -0
- package/dist/lib/WebServer/Decorator/SyncCallServer.js +41 -0
- package/dist/lib/WebServer/Engine/Engine.js +6 -0
- package/dist/lib/WebServer/IWebServer.js +3 -3
- package/dist/lib/index.js +9 -9
- package/dist/types/Config/IServerConfig.d.ts +9 -0
- package/dist/types/Service/MongoCacheService.d.ts +1 -0
- package/dist/types/SocketServer/IClientWebSocket.d.ts +9 -21
- package/dist/types/SocketServer/IRpcClientWebSocket.d.ts +1 -1
- package/dist/types/SocketServer/IRpcServerWebSocket.d.ts +1 -1
- package/dist/types/SocketServer/IServerWebSocket.d.ts +20 -9
- package/dist/types/SocketServer/ISocketServer.d.ts +22 -15
- package/dist/types/ThirdParty/CgMq.d.ts +2 -2
- package/dist/types/WebServer/Decorator/SyncCall.d.ts +7 -0
- package/dist/types/WebServer/Decorator/SyncCallServer.d.ts +7 -0
- package/dist/types/index.d.ts +3 -3
- package/package.json +3 -3
- package/dist/types/Config/ServerConfig.d.ts +0 -10
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.IServerConfig = exports.GServerCfg = void 0;
|
|
4
4
|
const FrameworkConfig_1 = require("./FrameworkConfig");
|
|
5
5
|
exports.GServerCfg = null;
|
|
6
|
-
class
|
|
6
|
+
class IServerConfig extends FrameworkConfig_1.FrameworkConfig {
|
|
7
7
|
port = -1;
|
|
8
8
|
_server_name = "";
|
|
9
|
-
webserver = null;
|
|
10
9
|
get serverName() {
|
|
11
10
|
return this._server_name;
|
|
12
11
|
}
|
|
@@ -24,4 +23,4 @@ class ServerConfig extends FrameworkConfig_1.FrameworkConfig {
|
|
|
24
23
|
return ret;
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
|
-
exports.
|
|
26
|
+
exports.IServerConfig = IServerConfig;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GMSSqlMgr = exports.MssqlReturn = void 0;
|
|
4
4
|
const mssql = require("mssql");
|
|
5
|
-
const
|
|
5
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
6
6
|
const DBCache_1 = require("./Decorator/DBCache");
|
|
7
7
|
class MssqlReturn {
|
|
8
8
|
error = null;
|
|
@@ -24,12 +24,12 @@ class MSSqlManager {
|
|
|
24
24
|
}
|
|
25
25
|
async init() {
|
|
26
26
|
if (this._pool
|
|
27
|
-
|| !
|
|
28
|
-
|| !
|
|
27
|
+
|| !IServerConfig_1.GServerCfg.db.mssql
|
|
28
|
+
|| !IServerConfig_1.GServerCfg.db.mssql.open) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
this._pool = await mssql.connect(
|
|
32
|
-
console.log("mssql config=" + JSON.stringify(
|
|
31
|
+
this._pool = await mssql.connect(IServerConfig_1.GServerCfg.db.mssql);
|
|
32
|
+
console.log("mssql config=" + JSON.stringify(IServerConfig_1.GServerCfg.db.mssql));
|
|
33
33
|
//这个的初始化位置不能变,必须位于cbs前,pool后
|
|
34
34
|
await DBCache_1.GDBCache.init();
|
|
35
35
|
for (let i = 0; i < this._init_cbs.length; ++i) {
|
|
@@ -5,7 +5,7 @@ const Property_1 = require("./Decorator/Property");
|
|
|
5
5
|
const MysqlManager_1 = require("./MysqlManager");
|
|
6
6
|
const Log_1 = require("../Logic/Log");
|
|
7
7
|
const DBCache_1 = require("./Decorator/DBCache");
|
|
8
|
-
const
|
|
8
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
9
9
|
class BaseModel {
|
|
10
10
|
}
|
|
11
11
|
exports.BaseModel = BaseModel;
|
|
@@ -42,7 +42,7 @@ class MysqlBaseService {
|
|
|
42
42
|
throw new Error("数据表的类必须要具有Table装饰器");
|
|
43
43
|
}
|
|
44
44
|
this._table = "`" + table.table + "`";
|
|
45
|
-
if (!
|
|
45
|
+
if (!IServerConfig_1.GServerCfg.db.mysql.auto) {
|
|
46
46
|
//未开启自动创建数据表
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -47,22 +47,22 @@ class MysqlManager {
|
|
|
47
47
|
async init() {
|
|
48
48
|
return new Promise(async (resolve) => {
|
|
49
49
|
if (this._pool
|
|
50
|
-
|| !
|
|
51
|
-
|| !
|
|
50
|
+
|| !IServerConfig_1.GServerCfg.db.mysql
|
|
51
|
+
|| !IServerConfig_1.GServerCfg.db.mysql.open) {
|
|
52
52
|
resolve(null);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
this._pool = mysql.createPool({
|
|
56
56
|
connectionLimit: 100,
|
|
57
|
-
host:
|
|
58
|
-
port:
|
|
59
|
-
user:
|
|
60
|
-
password:
|
|
61
|
-
database:
|
|
57
|
+
host: IServerConfig_1.GServerCfg.db.mysql.host,
|
|
58
|
+
port: IServerConfig_1.GServerCfg.db.mysql.port,
|
|
59
|
+
user: IServerConfig_1.GServerCfg.db.mysql.user,
|
|
60
|
+
password: IServerConfig_1.GServerCfg.db.mysql.password,
|
|
61
|
+
database: IServerConfig_1.GServerCfg.db.mysql.database,
|
|
62
62
|
supportBigNumbers: true,
|
|
63
63
|
charset: "utf8mb4"
|
|
64
64
|
});
|
|
65
|
-
console.log("mysql config=" + JSON.stringify(
|
|
65
|
+
console.log("mysql config=" + JSON.stringify(IServerConfig_1.GServerCfg.db.mysql));
|
|
66
66
|
//这个的初始化位置不能变,必须位于cbs前,pool后
|
|
67
67
|
await DBCache_1.GDBCache.init();
|
|
68
68
|
resolve(null);
|
|
@@ -177,4 +177,4 @@ class MysqlManager {
|
|
|
177
177
|
exports.GMysqlMgr = new MysqlManager();
|
|
178
178
|
//该import必须放在GMysqlMgr实例化之后,否则version基类找不到GMysqlMgr
|
|
179
179
|
const DBCache_1 = require("./Decorator/DBCache");
|
|
180
|
-
const
|
|
180
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GMongoCacheSer = exports.MongoCacheModel = void 0;
|
|
4
|
+
const cgserver_1 = require("../cgserver");
|
|
4
5
|
const MongoBaseService_1 = require("../Database/MongoBaseService");
|
|
5
6
|
const MongoManager_1 = require("../Database/MongoManager");
|
|
6
7
|
//暂时就用这个了,反正没啥用户
|
|
@@ -14,14 +15,28 @@ exports.GMongoCacheSer = null;
|
|
|
14
15
|
class MongoCacheService extends MongoBaseService_1.MongoBaseService {
|
|
15
16
|
constructor() {
|
|
16
17
|
super("cache", MongoCacheModel);
|
|
17
|
-
|
|
18
|
+
cgserver_1.GCgServer.addListener("start", () => {
|
|
19
|
+
this.createIndex({ key: 1 });
|
|
20
|
+
this.createIndex({ "expireAt": 1 }, { expireAfterSeconds: 0 });
|
|
21
|
+
});
|
|
18
22
|
}
|
|
19
23
|
async getData(key) {
|
|
20
|
-
let cm = await
|
|
24
|
+
let cm = await this.get(null, { key: key });
|
|
21
25
|
if (!cm) {
|
|
22
26
|
return null;
|
|
23
27
|
}
|
|
24
28
|
return cm.data;
|
|
25
29
|
}
|
|
30
|
+
async addData(key, data, expireAt = Date.now() + 365 * 24 * 60 * 60 * 1000) {
|
|
31
|
+
let mcm = new MongoCacheModel();
|
|
32
|
+
mcm.key = key;
|
|
33
|
+
mcm.data = data;
|
|
34
|
+
mcm.expireAt = expireAt;
|
|
35
|
+
let rs = await this.updateOne(mcm, { key: mcm.key }, true);
|
|
36
|
+
if (rs.rs.upsertedCount <= 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return mcm;
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
exports.GMongoCacheSer = new MongoCacheService();
|
|
@@ -2,74 +2,42 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IClientWebSocket = void 0;
|
|
4
4
|
const IWebSocket_1 = require("./IWebSocket");
|
|
5
|
-
const ws = require("websocket");
|
|
6
5
|
const Log_1 = require("../Logic/Log");
|
|
7
6
|
const IProtoFilter_1 = require("./ProtoFilter/IProtoFilter");
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* 默认自动重连
|
|
8
|
+
* 服务器接收到的客户端的连接
|
|
9
|
+
* 客户端的session对象
|
|
12
10
|
*/
|
|
13
11
|
class IClientWebSocket extends IWebSocket_1.IWebSocket {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
get host() {
|
|
19
|
-
return this._host;
|
|
12
|
+
_server = null;
|
|
13
|
+
get server() {
|
|
14
|
+
return this._server;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 连接的服务器端口
|
|
24
|
-
*/
|
|
25
|
-
get port() {
|
|
26
|
-
return this._port;
|
|
27
|
-
}
|
|
28
|
-
_need_close = false;
|
|
29
|
-
constructor(protoType = IProtoFilter_1.EProtoType.Json, protoPath = "") {
|
|
16
|
+
constructor(server, protoType = IProtoFilter_1.EProtoType.Json, protoPath = "") {
|
|
30
17
|
super(protoType, protoPath);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this._host = domain || this._host;
|
|
34
|
-
this._port = port || this._port;
|
|
35
|
-
this._connect();
|
|
36
|
-
}
|
|
37
|
-
_connect() {
|
|
38
|
-
let url = "ws://" + this._host + ":" + this._port + "/";
|
|
39
|
-
Log_1.GLog.info("Trying to connect to server : " + url);
|
|
40
|
-
let _ws = new ws.client();
|
|
41
|
-
_ws.on("connect", super.onConnect.bind(this));
|
|
42
|
-
_ws.on("connectFailed", this.onClose.bind(this));
|
|
43
|
-
_ws.connect(url, null, null, { cookie: "client=" + this._tipKey });
|
|
44
|
-
}
|
|
45
|
-
onOpen(e) {
|
|
46
|
-
super.onOpen(e);
|
|
47
|
-
Log_1.GLog.info("success to connect to " + this._host + ":" + this._port);
|
|
18
|
+
this._server = server;
|
|
19
|
+
this._tipKey = this._server.name;
|
|
48
20
|
}
|
|
49
21
|
onClose(reasonCode, description) {
|
|
50
22
|
super.onClose(reasonCode, description);
|
|
51
|
-
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
if (!this._need_close) {
|
|
54
|
-
this.connect(this._host, this._port);
|
|
55
|
-
}
|
|
56
|
-
}, 1000);
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
23
|
+
this._server.removeServerWebSocketBySocketId(this._socket_id);
|
|
62
24
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
25
|
+
broadCast(data) {
|
|
26
|
+
if (!data) {
|
|
27
|
+
Log_1.GLog.info("Send Message warning:null data!");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
Log_1.GLog.info("broadCast:----------------------------------");
|
|
31
|
+
Log_1.GLog.info(data);
|
|
32
|
+
let msg = this._protoFilter.encode(data);
|
|
33
|
+
this._server.broadCast(msg);
|
|
66
34
|
}
|
|
67
35
|
_onDecode(message, ...params) {
|
|
68
|
-
let msg = super._onDecode(message, "
|
|
36
|
+
let msg = super._onDecode(message, "msgReq");
|
|
69
37
|
return msg;
|
|
70
38
|
}
|
|
71
39
|
_onEncode(data, ...params) {
|
|
72
|
-
let msg = super._onEncode(data, "
|
|
40
|
+
let msg = super._onEncode(data, "msgRes");
|
|
73
41
|
return msg;
|
|
74
42
|
}
|
|
75
43
|
}
|
|
@@ -2,43 +2,73 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IServerWebSocket = void 0;
|
|
4
4
|
const IWebSocket_1 = require("./IWebSocket");
|
|
5
|
+
const ws = require("websocket");
|
|
5
6
|
const Log_1 = require("../Logic/Log");
|
|
6
7
|
const IProtoFilter_1 = require("./ProtoFilter/IProtoFilter");
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* 连接到服务器的websocket
|
|
10
|
+
* 默认自动重连
|
|
10
11
|
*/
|
|
11
12
|
class IServerWebSocket extends IWebSocket_1.IWebSocket {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
_host = "";
|
|
14
|
+
/**
|
|
15
|
+
* 连接的服务器地址
|
|
16
|
+
*/
|
|
17
|
+
get host() {
|
|
18
|
+
return this._host;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
_port = -1;
|
|
21
|
+
/**
|
|
22
|
+
* 连接的服务器端口
|
|
23
|
+
*/
|
|
24
|
+
get port() {
|
|
25
|
+
return this._port;
|
|
26
|
+
}
|
|
27
|
+
_need_close = false;
|
|
28
|
+
constructor(protoType = IProtoFilter_1.EProtoType.Json, protoPath = "") {
|
|
17
29
|
super(protoType, protoPath);
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
}
|
|
31
|
+
connect(domain, port) {
|
|
32
|
+
this._host = domain || this._host;
|
|
33
|
+
this._port = port || this._port;
|
|
34
|
+
this._connect();
|
|
35
|
+
}
|
|
36
|
+
_connect() {
|
|
37
|
+
let url = "ws://" + this._host + ":" + this._port + "/";
|
|
38
|
+
Log_1.GLog.info("Trying to connect to server : " + url);
|
|
39
|
+
let _ws = new ws.client();
|
|
40
|
+
_ws.on("connect", super.onConnect.bind(this));
|
|
41
|
+
_ws.on("connectFailed", this.onClose.bind(this));
|
|
42
|
+
_ws.connect(url, null, null, { cookie: "client=" + this._tipKey });
|
|
43
|
+
}
|
|
44
|
+
onOpen(e) {
|
|
45
|
+
super.onOpen(e);
|
|
46
|
+
Log_1.GLog.info("success to connect to " + this._host + ":" + this._port);
|
|
20
47
|
}
|
|
21
48
|
onClose(reasonCode, description) {
|
|
22
49
|
super.onClose(reasonCode, description);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return;
|
|
50
|
+
if (!this._need_close) {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
if (!this._need_close) {
|
|
53
|
+
this.connect(this._host, this._port);
|
|
54
|
+
}
|
|
55
|
+
}, 1000);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return false;
|
|
30
60
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
61
|
+
}
|
|
62
|
+
close() {
|
|
63
|
+
this._need_close = true;
|
|
64
|
+
super.close();
|
|
35
65
|
}
|
|
36
66
|
_onDecode(message, ...params) {
|
|
37
|
-
let msg = super._onDecode(message, "
|
|
67
|
+
let msg = super._onDecode(message, "msgRes");
|
|
38
68
|
return msg;
|
|
39
69
|
}
|
|
40
70
|
_onEncode(data, ...params) {
|
|
41
|
-
let msg = super._onEncode(data, "
|
|
71
|
+
let msg = super._onEncode(data, "msgReq");
|
|
42
72
|
return msg;
|
|
43
73
|
}
|
|
44
74
|
}
|
|
@@ -11,41 +11,31 @@ const https = require("https");
|
|
|
11
11
|
const MongoManager_1 = require("../Database/MongoManager");
|
|
12
12
|
const MSSqlManager_1 = require("../Database/MSSqlManager");
|
|
13
13
|
const EventTool_1 = require("../Logic/EventTool");
|
|
14
|
-
const
|
|
14
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
15
15
|
const cgserver_1 = require("../cgserver");
|
|
16
16
|
class ISocketServer {
|
|
17
|
+
_cfg = null;
|
|
18
|
+
//方便提示
|
|
19
|
+
get cfg() {
|
|
20
|
+
return this._cfg;
|
|
21
|
+
}
|
|
17
22
|
//服务器已被关闭
|
|
18
23
|
_is_closed = false;
|
|
19
24
|
get isClosed() {
|
|
20
25
|
return this._is_closed;
|
|
21
26
|
}
|
|
22
|
-
_code = -1; //服务器唯一编码
|
|
23
|
-
get code() {
|
|
24
|
-
return this._code;
|
|
25
|
-
}
|
|
26
|
-
set code(value) {
|
|
27
|
-
this._code = value;
|
|
28
|
-
}
|
|
29
|
-
_name = "";
|
|
30
27
|
get name() {
|
|
31
|
-
return this.
|
|
32
|
-
}
|
|
33
|
-
get fullServerName() {
|
|
34
|
-
return this._name + "@" + this._code;
|
|
28
|
+
return this._cfg.serverName;
|
|
35
29
|
}
|
|
36
30
|
//监听websocket
|
|
37
|
-
|
|
38
|
-
get
|
|
39
|
-
return this.
|
|
31
|
+
_listening_websocket = null;
|
|
32
|
+
get listeningWebSocket() {
|
|
33
|
+
return this._listening_websocket;
|
|
40
34
|
}
|
|
41
35
|
//来自于用户的链接
|
|
42
36
|
_ws_clients = {};
|
|
43
|
-
_listen_port = 0;
|
|
44
37
|
get listenPort() {
|
|
45
|
-
return this.
|
|
46
|
-
}
|
|
47
|
-
set listenPort(value) {
|
|
48
|
-
this._listen_port = value;
|
|
38
|
+
return this._cfg.port;
|
|
49
39
|
}
|
|
50
40
|
/**
|
|
51
41
|
* websocket can accepted protocol
|
|
@@ -62,8 +52,8 @@ class ISocketServer {
|
|
|
62
52
|
}
|
|
63
53
|
this._name_vs_class[name] = cls;
|
|
64
54
|
}
|
|
65
|
-
constructor(
|
|
66
|
-
this.
|
|
55
|
+
constructor(cfg) {
|
|
56
|
+
this._cfg = cfg;
|
|
67
57
|
}
|
|
68
58
|
removeServerWebSocketBySocketId(socketId) {
|
|
69
59
|
this._ws_clients[socketId] = null;
|
|
@@ -73,22 +63,20 @@ class ISocketServer {
|
|
|
73
63
|
cgserver_1.GCgServer.addSocketServer(this);
|
|
74
64
|
await MSSqlManager_1.GMSSqlMgr.init();
|
|
75
65
|
await MysqlManager_1.GMysqlMgr.init();
|
|
76
|
-
await RedisManager_1.GRedisMgr.init(
|
|
77
|
-
await MongoManager_1.GMongoMgr.init(
|
|
78
|
-
let code = await RedisManager_1.GRedisMgr.incr("server_code");
|
|
79
|
-
this._code = code;
|
|
66
|
+
await RedisManager_1.GRedisMgr.init(IServerConfig_1.GServerCfg.db?.redis);
|
|
67
|
+
await MongoManager_1.GMongoMgr.init(IServerConfig_1.GServerCfg.db?.mongo);
|
|
80
68
|
this.initWebSocket();
|
|
81
69
|
}
|
|
82
70
|
stop() {
|
|
83
71
|
this._is_closed = true;
|
|
84
|
-
this.
|
|
72
|
+
this._listening_websocket.closeAllConnections();
|
|
85
73
|
}
|
|
86
74
|
/*
|
|
87
75
|
把所有的客户端链接保存起来
|
|
88
76
|
方便统计,广播等
|
|
89
77
|
*/
|
|
90
|
-
addClient(
|
|
91
|
-
this._ws_clients[
|
|
78
|
+
addClient(ws_client) {
|
|
79
|
+
this._ws_clients[ws_client.socketId] = ws_client;
|
|
92
80
|
}
|
|
93
81
|
isOriginAllowed(origin) {
|
|
94
82
|
return true;
|
|
@@ -115,8 +103,8 @@ class ISocketServer {
|
|
|
115
103
|
response.end();
|
|
116
104
|
});
|
|
117
105
|
}
|
|
118
|
-
server.listen(this.
|
|
119
|
-
this.
|
|
106
|
+
server.listen(this._cfg.port, this.onListenning.bind(this));
|
|
107
|
+
this._listening_websocket = new ws.server({
|
|
120
108
|
httpServer: server,
|
|
121
109
|
// You should not use autoAcceptConnections for production
|
|
122
110
|
// applications, as it defeats all standard cross-origin protection
|
|
@@ -125,14 +113,14 @@ class ISocketServer {
|
|
|
125
113
|
// to accept it.
|
|
126
114
|
autoAcceptConnections: false
|
|
127
115
|
});
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
116
|
+
this._listening_websocket.on('request', this.onRequest.bind(this));
|
|
117
|
+
this._listening_websocket.on('close', this.onClose.bind(this));
|
|
130
118
|
}
|
|
131
119
|
onClose(connection, reason, desc) {
|
|
132
120
|
}
|
|
133
121
|
onListenning() {
|
|
134
122
|
EventTool_1.GEventTool.emit("socket_server_init_done");
|
|
135
|
-
let info = (new Date()) + " Server " + this.
|
|
123
|
+
let info = (new Date()) + " Server " + this.name + " is listening on port " + this._cfg.port;
|
|
136
124
|
Log_1.GLog.info(info);
|
|
137
125
|
console.log(info);
|
|
138
126
|
}
|
|
@@ -190,5 +178,25 @@ class ISocketServer {
|
|
|
190
178
|
}
|
|
191
179
|
return server_name;
|
|
192
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* 广播消息
|
|
183
|
+
* @param msg
|
|
184
|
+
*/
|
|
185
|
+
broadCast(msg) {
|
|
186
|
+
for (var key in this._ws_clients) {
|
|
187
|
+
let ws = this._ws_clients[key];
|
|
188
|
+
ws.send(msg);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 获取任意客户端连接
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
195
|
+
getAnyWebSocket() {
|
|
196
|
+
for (var key in this._ws_clients) {
|
|
197
|
+
return this._ws_clients[key];
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
193
201
|
}
|
|
194
202
|
exports.ISocketServer = ISocketServer;
|
|
@@ -6,7 +6,7 @@ const ProtoFactory_1 = require("./ProtoFilter/ProtoFactory");
|
|
|
6
6
|
const IProtoFilter_1 = require("./ProtoFilter/IProtoFilter");
|
|
7
7
|
const Core_1 = require("../Core/Core");
|
|
8
8
|
const _ = require("underscore");
|
|
9
|
-
const
|
|
9
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
10
10
|
const SyncQueueTool_1 = require("../Logic/SyncQueueTool");
|
|
11
11
|
class BaseMsg {
|
|
12
12
|
cmd;
|
|
@@ -62,7 +62,7 @@ class IWebSocket {
|
|
|
62
62
|
return false;
|
|
63
63
|
}
|
|
64
64
|
constructor(protoType = IProtoFilter_1.EProtoType.Json, protoPath = "") {
|
|
65
|
-
this._debug_msg =
|
|
65
|
+
this._debug_msg = IServerConfig_1.GServerCfg.debug_msg;
|
|
66
66
|
this._socket_id = parseInt(_.uniqueId());
|
|
67
67
|
this._protoType = protoType;
|
|
68
68
|
this._protoPath = protoPath;
|
|
@@ -7,7 +7,7 @@ const AliPayUtil_1 = require("alipay_sdk2/AliPayUtil");
|
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const form_1 = require("alipay-sdk/lib/form");
|
|
9
9
|
const Log_1 = require("../Logic/Log");
|
|
10
|
-
const
|
|
10
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
11
11
|
class AlipayResult {
|
|
12
12
|
alipay_trade_app_pay_response = {
|
|
13
13
|
code: "10000",
|
|
@@ -71,26 +71,26 @@ class AlipayTool {
|
|
|
71
71
|
notify_url: ""
|
|
72
72
|
};
|
|
73
73
|
init() {
|
|
74
|
-
if (!
|
|
75
|
-
|| !
|
|
74
|
+
if (!IServerConfig_1.GServerCfg.third_cfg.alipay
|
|
75
|
+
|| !IServerConfig_1.GServerCfg.third_cfg.alipay.open) {
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
let suffix = "";
|
|
79
|
-
if (
|
|
79
|
+
if (IServerConfig_1.GServerCfg.third_cfg.alipay.dev) {
|
|
80
80
|
suffix = "_dev";
|
|
81
81
|
}
|
|
82
82
|
this._cfg = {
|
|
83
|
-
app_id:
|
|
84
|
-
app_key:
|
|
85
|
-
gateway:
|
|
83
|
+
app_id: IServerConfig_1.GServerCfg.third_cfg.alipay["app_id" + suffix],
|
|
84
|
+
app_key: IServerConfig_1.GServerCfg.third_cfg.alipay["app_key" + suffix],
|
|
85
|
+
gateway: IServerConfig_1.GServerCfg.third_cfg.alipay["gateway" + suffix],
|
|
86
86
|
//RSA1 RSA2
|
|
87
|
-
signType:
|
|
87
|
+
signType: IServerConfig_1.GServerCfg.third_cfg.alipay["signType" + suffix],
|
|
88
88
|
/** 指定private key类型, 默认: PKCS1, PKCS8: PRIVATE KEY, PKCS1: RSA PRIVATE KEY */
|
|
89
|
-
keyType:
|
|
90
|
-
alipay_root_cert_sn:
|
|
91
|
-
alipay_cert_sn:
|
|
92
|
-
app_cert_sn:
|
|
93
|
-
notify_url:
|
|
89
|
+
keyType: IServerConfig_1.GServerCfg.third_cfg.alipay["signType" + suffix],
|
|
90
|
+
alipay_root_cert_sn: IServerConfig_1.GServerCfg.third_cfg.alipay["alipay_root_cert_sn" + suffix],
|
|
91
|
+
alipay_cert_sn: IServerConfig_1.GServerCfg.third_cfg.alipay["alipay_cert_sn" + suffix],
|
|
92
|
+
app_cert_sn: IServerConfig_1.GServerCfg.third_cfg.alipay["app_cert_sn" + suffix],
|
|
93
|
+
notify_url: IServerConfig_1.GServerCfg.third_cfg.alipay["notify_url" + suffix]
|
|
94
94
|
};
|
|
95
95
|
if (this._cfg.alipay_cert_sn) {
|
|
96
96
|
this._aliPay = new AliPayUtil_1.AliPayUtil(this._cfg.alipay_cert_sn, this._cfg.app_key);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GSmsTool = void 0;
|
|
4
|
-
const
|
|
4
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
5
5
|
const Log_1 = require("./../Logic/Log");
|
|
6
6
|
let SMSClient = require("@alicloud/sms-sdk");
|
|
7
7
|
exports.GSmsTool = null;
|
|
@@ -13,7 +13,7 @@ class SMSTool {
|
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
15
|
this._is_init = true;
|
|
16
|
-
this._sms_client = new SMSClient({ accessKeyId:
|
|
16
|
+
this._sms_client = new SMSClient({ accessKeyId: IServerConfig_1.GServerCfg.third_cfg.aliSms.accessKeyId, secretAccessKey: IServerConfig_1.GServerCfg.third_cfg.aliSms.secretAccessKey });
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* 发送短信验证码
|
|
@@ -25,8 +25,8 @@ class SMSTool {
|
|
|
25
25
|
return new Promise((resolve, reject) => {
|
|
26
26
|
this._sms_client.sendSMS({
|
|
27
27
|
PhoneNumbers: phone,
|
|
28
|
-
SignName:
|
|
29
|
-
TemplateCode:
|
|
28
|
+
SignName: IServerConfig_1.GServerCfg.third_cfg.aliSms.signName,
|
|
29
|
+
TemplateCode: IServerConfig_1.GServerCfg.third_cfg.aliSms.templateCode,
|
|
30
30
|
TemplateParam: JSON.stringify({ code: code })
|
|
31
31
|
}).then((res) => {
|
|
32
32
|
if (res.Code == "OK") {
|
|
@@ -6,7 +6,7 @@ const HttpTool_1 = require("./../Logic/HttpTool");
|
|
|
6
6
|
const ec_key_1 = require("ec-key");
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
8
8
|
const fs = require("fs");
|
|
9
|
-
const
|
|
9
|
+
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
10
10
|
//developer.apple.com/documentation/appstorereceipts/responsebody
|
|
11
11
|
class ReceiptInfo {
|
|
12
12
|
cancellation_date = "";
|
|
@@ -187,7 +187,7 @@ class AppleTool {
|
|
|
187
187
|
}
|
|
188
188
|
signature(nickname, create_time, appBundleID, productIdentifier, offerIdentifier) {
|
|
189
189
|
let keyIdentifier = "";
|
|
190
|
-
for (var k in
|
|
190
|
+
for (var k in IServerConfig_1.GServerCfg.third_cfg.apple.keyIds) {
|
|
191
191
|
keyIdentifier = k;
|
|
192
192
|
break;
|
|
193
193
|
}
|
|
@@ -200,7 +200,7 @@ class AppleTool {
|
|
|
200
200
|
nonce.toLowerCase() + '\u2063' +
|
|
201
201
|
create_time;
|
|
202
202
|
// Get the PEM-formatted private key string associated with the Key ID.
|
|
203
|
-
const path =
|
|
203
|
+
const path = IServerConfig_1.GServerCfg.third_cfg.apple.keyIds[keyIdentifier];
|
|
204
204
|
const keyString = fs.readFileSync(path).toString();
|
|
205
205
|
// Create an Elliptic Curve Digital Signature Algorithm (ECDSA) object using the private key.
|
|
206
206
|
const key = new ec_key_1.default(keyString, 'pem');
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CgMq = exports.CgMqConfig = exports.CgMqRetMsg = void 0;
|
|
4
4
|
const Core_1 = require("../Core/Core");
|
|
5
5
|
const Log_1 = require("../Logic/Log");
|
|
6
|
-
const
|
|
6
|
+
const IRpcServerWebSocket_1 = require("../SocketServer/IRpcServerWebSocket");
|
|
7
7
|
const IRpc_1 = require("../SocketServer/IRpc");
|
|
8
8
|
//接受到的消息无需basemsg部分
|
|
9
9
|
class CgMqMsg extends IRpc_1.RpcBaseMsg {
|
|
@@ -27,7 +27,7 @@ class CgMqRetMsg extends CgMqMsg {
|
|
|
27
27
|
count = 0;
|
|
28
28
|
}
|
|
29
29
|
exports.CgMqRetMsg = CgMqRetMsg;
|
|
30
|
-
class CgMqServerWebsocket extends
|
|
30
|
+
class CgMqServerWebsocket extends IRpcServerWebSocket_1.IRpcServerWebSocket {
|
|
31
31
|
_cgmq = null;
|
|
32
32
|
/**
|
|
33
33
|
* 自己的身份
|