cgserver 7.2.684 → 7.2.689

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.
@@ -75,5 +75,40 @@ class MongoBaseService {
75
75
  let ret = MongoManager_1.GMongoMgr.aggregate(this._table, pipeline, options);
76
76
  return ret;
77
77
  }
78
+ /**
79
+ * 仅仅支持一级
80
+ * @param array 数据名称 比如 items
81
+ * @param where 数组内赛选条件 比如 "items.id":1
82
+ * @param pre_match 数组上一级赛选条件 比如 "user_id":1
83
+ */
84
+ async getsInArray(array, where, pre_match) {
85
+ let agg = this.aggregate();
86
+ if (pre_match) {
87
+ agg = agg.match(pre_match);
88
+ }
89
+ agg = agg.unwind("$" + array);
90
+ if (where) {
91
+ agg = agg.match(where);
92
+ }
93
+ let all = await agg.toArray();
94
+ let items = [];
95
+ for (let i = 0; i < all.length; ++i) {
96
+ items.push(all[i][array]);
97
+ }
98
+ return items;
99
+ }
100
+ /**
101
+ * 仅仅支持一级
102
+ * @param array 数据名称 比如 items
103
+ * @param where 数组内赛选条件 比如 "items.id":1
104
+ * @param pre_match 数组上一级赛选条件 比如 "user_id":1
105
+ */
106
+ async getInArray(array, where, pre_match) {
107
+ let items = await this.getsInArray(array, where, pre_match);
108
+ if (items.length <= 0) {
109
+ return null;
110
+ }
111
+ return items[0];
112
+ }
78
113
  }
79
114
  exports.MongoBaseService = MongoBaseService;
@@ -4,33 +4,49 @@ exports.GHttpTool = void 0;
4
4
  const request = require("request");
5
5
  const qs = require("querystring");
6
6
  const Log_1 = require("./Log");
7
- const cgserver_1 = require("cgserver");
7
+ const Core_1 = require("../Core/Core");
8
8
  exports.GHttpTool = null;
9
9
  class HttpTool {
10
- httpRequest(url, noParse) {
10
+ get(options_url) {
11
+ let options = null;
12
+ if (Core_1.core.isString(options_url)) {
13
+ options = { url: options_url };
14
+ }
15
+ else {
16
+ options = options_url;
17
+ }
11
18
  return new Promise((resolve, reject) => {
12
- request.get(url, {
13
- strictSSL: false,
14
- rejectUnauthorized: false
15
- }, (error, response, body) => {
16
- if (!noParse) {
19
+ request.get(options, (error, response, body) => {
20
+ let bd = body;
21
+ if (error) {
22
+ Log_1.GLog.error("get:" + options.url);
23
+ Log_1.GLog.error(error);
24
+ }
25
+ try {
26
+ if (Core_1.core.isString(body)) {
27
+ body = JSON.parse(body);
28
+ }
29
+ }
30
+ catch (e) {
17
31
  try {
18
- if (body) {
19
- body = JSON.parse(body);
20
- }
32
+ body = qs.parse(body);
21
33
  }
22
34
  catch (e) {
23
- try {
24
- body = qs.parse(body);
25
- }
26
- catch (e) { }
35
+ body = bd;
27
36
  }
28
37
  }
29
38
  resolve({ error, response, body });
30
39
  });
31
40
  });
32
41
  }
33
- httpPost(options) {
42
+ post(options_url) {
43
+ let options = null;
44
+ if (Core_1.core.isString(options_url)) {
45
+ options = { url: options_url };
46
+ }
47
+ else {
48
+ options = options_url;
49
+ }
34
50
  return new Promise((resolve, reject) => {
35
51
  request.post(options, (error, response, body) => {
36
52
  let bd = body;
@@ -39,7 +55,7 @@ class HttpTool {
39
55
  Log_1.GLog.error(error);
40
56
  }
41
57
  try {
42
- if (cgserver_1.core.isString(body)) {
58
+ if (Core_1.core.isString(body)) {
43
59
  body = JSON.parse(body);
44
60
  }
45
61
  }
@@ -174,12 +174,12 @@ class AppleTool {
174
174
  let reqb = new RequestBody();
175
175
  reqb['receipt-data'] = receipt;
176
176
  //先验证生产环境
177
- var resb = (await HttpTool_1.GHttpTool.httpPost({ url, form: JSON.stringify(reqb) })).body;
177
+ var resb = (await HttpTool_1.GHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
178
178
  Log_1.GLog.info("production end onVerify_Res============================status=" + (resb ? resb.status : "null"));
179
179
  //状态21007表示是沙盒环境
180
180
  if (resb && resb.status == 21007) {
181
181
  url = this._sandboxVerifyUrl;
182
- resb = (await HttpTool_1.GHttpTool.httpPost({ url, form: JSON.stringify(reqb) })).body;
182
+ resb = (await HttpTool_1.GHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
183
183
  Log_1.GLog.info("sandbox end onVerify_Res============================status=" + (resb ? resb.status : "null"));
184
184
  }
185
185
  Log_1.GLog.info(resb);
@@ -16,7 +16,7 @@ class OpenSocial {
16
16
  unionid: unionid,
17
17
  openid: openid
18
18
  };
19
- let rs = await HttpTool_1.GHttpTool.httpPost({ url: IServerConfig_1.GServerCfg.third_cfg.open_social.user_url, json: msg });
19
+ let rs = await HttpTool_1.GHttpTool.post({ url: IServerConfig_1.GServerCfg.third_cfg.open_social.user_url, json: msg });
20
20
  return rs.body;
21
21
  }
22
22
  async updatePwd(unionid, openid, new_pwd) {
@@ -25,7 +25,7 @@ class OpenSocial {
25
25
  openid: openid,
26
26
  password: new_pwd
27
27
  };
28
- let jsonData = await HttpTool_1.GHttpTool.httpPost({ url: IServerConfig_1.GServerCfg.third_cfg.open_social.update_pwd_url, json: msg });
28
+ let jsonData = await HttpTool_1.GHttpTool.post({ url: IServerConfig_1.GServerCfg.third_cfg.open_social.update_pwd_url, json: msg });
29
29
  return jsonData.body || jsonData.error;
30
30
  }
31
31
  }
@@ -75,7 +75,7 @@ class QQTool {
75
75
  //必须 成功授权后的回调地址,必须是注册appid时填写的主域名下的地址,建议设置为网站首页或网站的用户中心
76
76
  let redirect_uri = URLEncode.encode(IServerConfig_1.GServerCfg.third_cfg.qq.redirect_uri);
77
77
  let url = "https://graph.qq.com/oauth2.0/token?code=" + auth_code + "&grant_type=" + grant_type + "&client_id=" + client_id + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri;
78
- let rs = await HttpTool_1.GHttpTool.httpRequest(url);
78
+ let rs = await HttpTool_1.GHttpTool.get(url);
79
79
  if (rs.body && rs.body.access_token) {
80
80
  return rs.body.access_token;
81
81
  }
@@ -86,7 +86,7 @@ class QQTool {
86
86
  }
87
87
  async getOpenId(access_token) {
88
88
  let url = "https://graph.qq.com/oauth2.0/me?access_token=" + access_token;
89
- let rs = await HttpTool_1.GHttpTool.httpRequest(url);
89
+ let rs = await HttpTool_1.GHttpTool.get(url);
90
90
  let body = rs.response ? rs.response.body : null;
91
91
  if (body) {
92
92
  body = body.replace("callback( ", "");
@@ -104,7 +104,7 @@ class QQTool {
104
104
  }
105
105
  async getUserInfo(access_token, openid) {
106
106
  let url = "https://graph.qq.com/user/get_user_info?access_token=" + access_token + "&oauth_consumer_key=" + IServerConfig_1.GServerCfg.third_cfg.qq.app_id + "&openid=" + openid;
107
- let rs = await HttpTool_1.GHttpTool.httpRequest(url);
107
+ let rs = await HttpTool_1.GHttpTool.get(url);
108
108
  if (rs.body) {
109
109
  return rs.body;
110
110
  }
@@ -41,7 +41,7 @@ class WechatTool {
41
41
  return null;
42
42
  }
43
43
  let url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + IServerConfig_1.GServerCfg.third_cfg.wechat.app_id + "&secret=" + IServerConfig_1.GServerCfg.third_cfg.wechat.app_key + "&code=" + auth_code + "&grant_type=authorization_code";
44
- let rs = await HttpTool_1.GHttpTool.httpRequest(url);
44
+ let rs = await HttpTool_1.GHttpTool.get(url);
45
45
  /*
46
46
  {
47
47
  "access_token":"ACCESS_TOKEN",
@@ -63,7 +63,7 @@ class WechatTool {
63
63
  }
64
64
  async getUserInfo(access_token, openid) {
65
65
  let url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid;
66
- let rs = await HttpTool_1.GHttpTool.httpRequest(url);
66
+ let rs = await HttpTool_1.GHttpTool.get(url);
67
67
  if (rs.body) {
68
68
  return rs.body;
69
69
  }
@@ -64,4 +64,18 @@ export declare class MongoBaseService<T> {
64
64
  rs: string;
65
65
  }>;
66
66
  aggregate(pipeline?: Document[], options?: mongo.AggregateOptions): mongo.AggregationCursor<mongo.Document>;
67
+ /**
68
+ * 仅仅支持一级
69
+ * @param array 数据名称 比如 items
70
+ * @param where 数组内赛选条件 比如 "items.id":1
71
+ * @param pre_match 数组上一级赛选条件 比如 "user_id":1
72
+ */
73
+ getsInArray<T>(array: string, where?: any, pre_match?: any): Promise<T[]>;
74
+ /**
75
+ * 仅仅支持一级
76
+ * @param array 数据名称 比如 items
77
+ * @param where 数组内赛选条件 比如 "items.id":1
78
+ * @param pre_match 数组上一级赛选条件 比如 "user_id":1
79
+ */
80
+ getInArray<T>(array: string, where?: any, pre_match?: any): Promise<T>;
67
81
  }
@@ -1,12 +1,12 @@
1
1
  import * as request from "request";
2
2
  export declare let GHttpTool: HttpTool;
3
3
  declare class HttpTool {
4
- httpRequest(url: string, noParse?: boolean): Promise<{
4
+ get(options_url: request.OptionsWithUrl | string): Promise<{
5
5
  error: any;
6
6
  response: any;
7
7
  body: any;
8
8
  }>;
9
- httpPost(options: request.OptionsWithUrl): Promise<{
9
+ post(options_url: request.OptionsWithUrl | string): Promise<{
10
10
  error: any;
11
11
  response: any;
12
12
  body: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "7.2.684",
3
+ "version": "7.2.689",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",
@@ -48,7 +48,6 @@
48
48
  "@types/websocket": "^1.0.4",
49
49
  "alipay_sdk2": "^1.1.6",
50
50
  "alipay-sdk": "^3.1.7",
51
- "cgserver": "^6.9.468",
52
51
  "colors": "^1.4.0",
53
52
  "cookie-parser": "^1.4.5",
54
53
  "cors": "^2.8.5",